//<?php
//header('Content-Type: javascript');

/*****

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, mode = 0, cOpacity = 0.0;

function so_init() {
	if(!d.getElementById || !d.createElement)return;

	// DON'T FORGET TO GRAB THIS FILE AND PLACE IT ON YOUR SERVER IN THE SAME DIRECTORY AS THE JAVASCRIPT!
	// http://slayeroffice.com/code/imageCrossFade/xfade2.css
	css = d.createElement("link");
	css.setAttribute("href","xfade2.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);
	
	timeDelay = 0; // Time between pictures	
	
	imgs = d.getElementById("imageContainer").getElementsByTagName("img");
	imgContainer = d.getElementById("imageContainer");
	//imgContainer.style.width = "10px";
	
	btopmid = d.getElementById("topmid");
	bbotmid = d.getElementById("botmid"); // width - 20
	bleft2 = d.getElementById("left2"); // height - 20
	bright2 = d.getElementById("right2"); // height - 20
	bpicture_row_container = d.getElementById("picture_row_container");
	
	btopleft = d.getElementById("topleft");
	btopright = d.getElementById("topright");
	bbotright = d.getElementById("botright");
	bbotleft = d.getElementById("botleft");
	bleft1 = d.getElementById("left1");
	bright1 = d.getElementById("right1");		

	for(i=1;i<imgs.length;i++) 
	{
		imgs[i].style.display = "none";
		imgs[i].xOpacity = 0;
		setOpacity2(imgs[i]);
	}
	imgs[0].style.display = "inline";
	imgs[0].xOpacity = 0;
	setOpacity2(imgs[0]);
	
	btopmid.xOpacity = 0;	
	setOpacity2(btopmid);
	
	bbotmid.xOpacity = 0;	
	setOpacity2(bbotmid);
	
	bleft2.xOpacity = 0;	
	setOpacity2(bleft2);

	bright2.xOpacity = 0;	
	setOpacity2(bright2);
	
	btopleft.xOpacity = 0;	
	setOpacity2(btopleft);
	
	btopright.xOpacity = 0;	
	setOpacity2(btopright);
	
	bbotleft.xOpacity = 0;	
	setOpacity2(bbotleft);
	
	bbotright.xOpacity = 0;	
	setOpacity2(bbotright);
	
	bleft1.xOpacity = 0;	
	setOpacity2(bleft1);

	bright1.xOpacity = 0;	
	setOpacity2(bright1);

	//setTimeout(so_xfade,timeDelay);
	setTimeout(so_slideShow,timeDelay);
	
	function setOpacity2(obj) {
		//if(obj.xOpacity>1) {
		//	obj.xOpacity = 1;
		//	return;
		//}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		
		//bleft2.style.MozOpacity = obj.xOpacity;
	}
}

function so_slideShow() {
	timeDelay = 4000;
	//cOpacity = imgs[current].xOpacity;	
	if(mode == 0)
	{
		cOpacity+=.10;
	}
	if(mode == 1)
	{
		cOpacity-=.10;
	}
	imgs[current].xOpacity = cOpacity;
	//imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]);
	
	if(cOpacity >= 1.0 && mode == 0) {
		//imgs[current].style.display = "none";
		cOpacity = 1.0;
		//imgs[current].style.display = "none";
		//current = current + 1;
		//imgs[current].style.display = "inline";
		//imgs[2].xOpacity = 0.0;
		mode = 1;
		setTimeout(so_slideShow,timeDelay);		
	}
	else if(cOpacity <= 0 && mode == 1) {
		//imgs[current].style.display = "none";
		//alert("pass1");		
		
		cOpacity = 0.0;
		imgs[current].style.display = "none";
		current = current + 1;
		if(current > imgs.length-1)
		{
			current = 0;
		}
		imgs[current].xOpacity = 0.0;
		imgs[current].style.display = "inline";
		
		setOpacity(imgs[current]);
		//imgContainer.style.width = 
		//alert('Container: '+imgContainer.style.width+'\nImg: '+imgs[current].width);
		// Borders
		//alert("pass2");
		btopmid.style.width = imgs[current].width+'px';
		bbotmid.style.width = (imgs[current].width-20)+'px';
		bleft2.style.height = (imgs[current].height-20)+'px';
		bright2.style.height = (imgs[current].height-20)+'px';
		bpicture_row_container.style.width = imgs[current].width+'px';
		imgContainer.style.width = imgs[current].width+'px';
		imgContainer.style.height = imgs[current].height+'px';		
		bpicture_row_container.style.width = (imgs[current].width+40)+'px';
		bpicture_row_container.style.height = (imgs[current].height+50)+'px';
		bpicture_row_container.style.marginLeft = ((-(imgs[current].width+40))/2)+'px';
		bpicture_row_container.style.marginTop = ((-(imgs[current].height+50))/2)+'px';
		
		//alert('margin:'+bpicture_row_container.style.marginLeft+'px');	
		//alert("pass3");
		// ---
		
		//imgs[2].xOpacity = 0.0;
		mode = 0;
		setTimeout(so_slideShow,500);
	} else {
		setTimeout(so_slideShow,40);
	}
	
	function setOpacity(obj) {
		//if(obj.xOpacity>1) {
		//	obj.xOpacity = 1;
		//	return;
		//}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		
		bright1.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";		
		bright2.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";		
		bleft1.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		bleft2.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		btopleft.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		btopmid.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		btopright.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		bbotleft.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		bbotright.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		bbotmid.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		
		bright1.style.opacity = obj.xOpacity;		
		bright2.style.opacity = obj.xOpacity;		
		bleft1.style.opacity = obj.xOpacity;
		bleft2.style.opacity = obj.xOpacity;
		btopleft.style.opacity = obj.xOpacity;
		btopmid.style.opacity = obj.xOpacity;
		btopright.style.opacity = obj.xOpacity;
		bbotleft.style.opacity = obj.xOpacity;
		bbotright.style.opacity = obj.xOpacity;
		bbotmid.style.opacity = obj.xOpacity;
		
		bright1.style.MozOpacity = obj.xOpacity;		
		bright2.style.MozOpacity = obj.xOpacity;		
		bleft1.style.MozOpacity = obj.xOpacity;
		bleft2.style.MozOpacity = obj.xOpacity;
		btopleft.style.MozOpacity = obj.xOpacity;
		btopmid.style.MozOpacity = obj.xOpacity;
		btopright.style.MozOpacity = obj.xOpacity;
		bbotleft.style.MozOpacity = obj.xOpacity;
		bbotright.style.MozOpacity = obj.xOpacity;
		bbotmid.style.MozOpacity = obj.xOpacity;
	}
	
}


// ?>