/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact. 

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html


*****/


window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;
var t1,t2;

function so_init() {
	if(!d.getElementById || !d.createElement)return;
	
	imgs = d.getElementById("displayImage").getElementsByTagName("img");
	
	if(imgs.length>0){
	    for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
		
		imgs[0].style.display = "block";
		imgs[0].xOpacity = .99;
		
		title = document.getElementById("imgTitle"); 
		detail = document.getElementById("imgDetail"); 
		
		if (title != null) 
			title.innerHTML = '<span>' + arrImageInfo[0]["title"] + '</span>';
			
		if (detail != null) 
			detail.innerHTML = arrImageInfo[0]["detail"];
			
		if(typeof sIFR == "function"){
			sIFR.replaceElement(named({sSelector:"#imgTitle span", sFlashSrc:"/flashes/CenturyGothic.swf", sColor:"#8B0E04", sLinkColor:"#8B0E04", sBgColor:"#8B0E04", sHoverColor:"#8B0E04", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"", sWmode: "transparent"}));
		}
			
	    t1 = setTimeout(so_xfade,1000);
	}
}
function initOpacity()
{
    for(i=0;i<imgs.length;i++) 
	{
	    imgs[i].xOpacity = 0;
	    imgs[i].style.opacity = 0;
		imgs[i].style.MozOpacity = 0;
		imgs[i].style.filter = "alpha(opacity=0)";
	}
}
function so_xfade() {
	if(pause)return;

	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;
		
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		t2 = setTimeout(so_xfade,3000);

		title = document.getElementById("imgTitle"); 
		detail = document.getElementById("imgDetail"); 
		
		if (title != null) {
			title.innerHTML = '<span>' + arrImageInfo[nIndex]["title"] + '</span>';
		}
			
		if(typeof sIFR == "function"){
			sIFR.replaceElement(named({sSelector:"#imgTitle span", sFlashSrc:"/flashes/CenturyGothic.swf", sColor:"#8B0E04", sLinkColor:"#8B0E04", sBgColor:"#8B0E04", sHoverColor:"#8B0E04", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"", sWmode: "transparent"}));
		}
		
		if (detail != null) 
			detail.innerHTML = arrImageInfo[nIndex]["detail"];
	} else {
		t2 = setTimeout(so_xfade,125);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}
function playImage(){
	if(pause){
		pause = false;
		if(imgs.length>0){
		    so_xfade();
		}
	}
	return false;
}
function stopDisplay(){
	pause = true;
	return false;
}
function clickImage(indexImg){
    pause = true;
    initOpacity();
    current = indexImg;
    
    imgs[current].style.display = "block";
	imgs[current].xOpacity = 100;	
	imgs[current].style.opacity = 100;
	imgs[current].style.MozOpacity = 100;
	imgs[current].style.filter = "alpha(opacity=100)";
	
	title = document.getElementById("imgTitle"); 
	detail = document.getElementById("imgDetail"); 
	
	if (title != null) 
		title.innerHTML = '<span>' + arrImageInfo[indexImg]["title"] + '</span>';
		
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({sSelector:"#imgTitle span", sFlashSrc:"/flashes/CenturyGothic.swf", sColor:"#8B0E04", sLinkColor:"#8B0E04", sBgColor:"#8B0E04", sHoverColor:"#8B0E04", nPaddingTop:0, nPaddingRight:0, nPaddingBottom:0, nPaddingLeft:0, sFlashVars:"", sWmode: "transparent"}));
	}
	
	if (detail != null) 
		detail.innerHTML = arrImageInfo[nIndex]["detail"];
	
    return false;
}
