// rollover script

window.onload=function(){ 
	var divs=document.getElementsByTagName('div'); 
	var divs_ln=divs.length; 
	for(var i=0;i<divs_ln;i++){ 
		if(divs[i].className.indexOf('_overs')!=-1){ 
			divs[i].onmouseover=swapOne; 
			divs[i].onmouseout=swapTwo; 
		} 
	} 
} 
function swapOne(){ 
	var divs=this.getElementsByTagName('div'); 
	divs[0].style.visibility="hidden"; 
	divs[1].style.visibility="visible";
} 
function swapTwo(){ 
	var divs=this.getElementsByTagName('div'); 
	divs[0].style.visibility="visible"; 
	divs[1].style.visibility="hidden"; 
} 



function updateIndex(indexNum){
	killTimer();
	slideIndex = indexNum;
	fadeDuration = skipTimer;
	triggerSlide();
}

function triggerSlide(){
	//alert('advance!');
	thisImage = $j("#largeImg");
	imgPath =imgPaths[slideIndex];
	linkURL =linkURLs[slideIndex];
	thisDescription =thisDescriptions[slideIndex];
	
	flipImage(imgPath, thisImage, linkURL, thisDescription);
	
	if(slideIndex<(imgPaths.length-1)){
		slideIndex++;
	}else{
		slideIndex=0;
	}
  
}

function flipImage(imgPath, thisImage, linkURL, thisDescription){
	
	imgPathsCount = imgPaths.length;
	//alert(imgPathsCount);
	var i=0;
	for (i=0; i<=(imgPathsCount-1);i++){
		setColor("selector-"+i,"normal");
	}
	setColor("selector-"+slideIndex,"hilight");
	
	
	imgPathOld = thisImage[0].src;
	if(imgPathOld != imgPath){
		$j("#largeImg").stop();
		$j("#largeImg").animate({opacity: 0.0, queue: false}, 0);
		$j("#largeImg").attr({src: imgPath, alt: imgPath});
		$j("#largeImg").attr("title", thisDescription);
		$j("#largeImg").css('visibility', 'visible');
		//$j("#largeImg").attr("href", linkURL);
		//$j("#largeImg").attr("rel", "lightbox");
		
		$j("#largeImgBG").stop();
		$j("#largeImgBG").attr({src: imgPathOld, alt: imgPath});
		
		$j("#largeImgLink").attr("href", linkURL);
		$j("#largeImgLink").attr("title", thisDescription);
		
		//$j("#learn_more_button").animate({opacity: 0.0, queue: true}, 0);
		//$j("#learn_more_button").animate({opacity: 0.0, queue: true}, 0);	

		imgPathOld = imgPath;
	}else{
		//alert(imgPathOld + "  " +imgPath);
		$j("#largeImg").stop();
		$j("#largeImg").animate({opacity: 1.0, queue: true}, "slow");
	}
}



function startTimer(){
  delayTrigger = setInterval ( "triggerSlide()",pauseDelay);
}

function killTimer(){
  clearInterval(delayTrigger);
}

function setColor(elementID, colorType){
  //document.getElementById("colourButton").style.color = "#000000";
  if(colorType=="normal"){
	document.getElementById(elementID).style.color = linkColor;
  	document.getElementById(elementID).style.backgroundImage='url(/images/rotator/rotator_button_bg.gif)';  
  }else{
	//document.getElementById(elementID).style.borderBottomColor="#FFFFFF";
	document.getElementById(elementID).style.color = hilightColor;
  	document.getElementById(elementID).style.backgroundImage='url(/images/rotator/rotator_button_bg_current.gif)';  
  }
}
