//need these global variables
//initializes the old image, only needed for first slide?
var oldone = 0;
//tells the mootools accordion delay to keep going, until we change to 1
var stoptimer = 0;
var eventtest = 0;
var accordionvar;

	window.addEvent('domready', function(){
		accordionvar = new Accordion('h3.atStart', 'div.atStart', {
									  
			opacity: false,
			onActive: function(toggler, element){
				toggler.setStyle('color', '#D34229');
				//toggler.setStyle('background', '#D34229');
				//alert(toggler.getStyle('background-image')).split('/').pop);
				//var imgarray = imgurl.split('/');
				//var last = imgarray.pop;
				//newlast = on+last;
				//alert(newlast);
				
				//change image
				
				/*var togglechar = toggler.getAttribute('id').charAt(0);
					showimage(togglechar,0);*/
					
				//change background image whether active or not
				//if(stoptimer == 0) { //slideshow is on autopilot now
				
					var i=0;
					for(i=0; i<3; i++) {
						/*if(i==toggler.getAttribute('id').charAt(0)) {
							document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_current.jpg)";	
						}
						else {
							document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_mid.jpg)";	
						}*/
						
						if(i==0) {
							if(i==toggler.getAttribute('id').charAt(0)) {
								document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_current_top.jpg)";																					
							}
							else {
								document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_top.jpg)";	
							}
						}
						if(i==1) {
							if(i==toggler.getAttribute('id').charAt(0)) {
								document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_current_mid.jpg)";																					
							}
							else {
								document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_mid.jpg)";	
							}
						}
						if(i==2) {
							if(i==toggler.getAttribute('id').charAt(0)) {
								document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_current_bottom.jpg)";																					
							}
							else {
								document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_bottom.jpg)";	
							}
							document.getElementById('2element').style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_element_bottom.jpg)";	
							document.getElementById('2element').style.backgroundRepeat = "no-repeat";

						}
					}
				//}
					
				
			},
			
			/*
			onComplete: function(){
				if(stoptimer == 0) {
					this.display.delay(5000, this, (this.previous + 1) % this.togglers.length);
				}
			},
			*/
			onBackground: function(toggler, element){
				toggler.setStyle('color', '#222');
				//toggler.setStyle('background', '#ddd');
			},
			
		}, $('accordion'));
		
	});

//interval = setInterval ("showimage(autoscroll, 1)", 5000);

function showimage(newone, clicked){
		
		//alert("hello");
		//if clicked on by a human
		//if(clicked==1) {
		
			//clearEvent(eventtest);
			//global variable to tell the mootools accordion delay to stop
			stoptimer = 1;
			
			//change background image
			var i = 0;
			var element_bottom = '2element';
			//alert(autoscroll);
			for(i = 0; i<3; i++) {
				//alert(i+' and '+newone);
				//alert(i==newone);
				if(i==0) {
					if(i==newone) {
						document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_current_top.jpg)";	
						accordionvar.display(0);
					}
					else {
						document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_top.jpg)";	
					}
				}
				if(i==1) {
					if(i==newone) {
						document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_current_mid.jpg)";		
						accordionvar.display(1);
					}
					else {
						document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_mid.jpg)";	
					}
				}
				if(i==2) {
					if(i==newone) {
						document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_current_bottom.jpg)";		
						accordionvar.display(2);
					}
					else {
						document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_bottom.jpg)";	
					}
					document.getElementById('2element').style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_element_bottom.jpg)";
					document.getElementById('2element').style.backgroundRepeat = "no-repeat";
				}
				
				//document.getElementById(i).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_mid.jpg)";
			
			}

			autoscroll = (autoscroll+1)%3;

			if(clicked == 1) {
				clearInterval(interval);
			}
			
			//alert(clicked);
			
			//document.getElementById(newone).style.backgroundImage = "url(/templates/irvine_main/images/style1/frontpage_accordion_current.gif)";	
			//document.getElementById(newone).style.color = "green";	
																																													
		//}

		tDiv = "div"+oldone;
		vDiv = "div"+newone;
	
	if(tDiv != vDiv) {
	
		if($(tDiv).fx){$(tDiv).fx.stop();}
		if($(vDiv).fx){$(vDiv).fx.stop();}
		$(tDiv).fx = $(tDiv).effect('opacity', {duration: 700}).start(0);
		$(vDiv).fx = $(vDiv).effect('opacity', {duration: 700}).start(1);	
		
		oldone = newone;
	
	}
}
