/*****

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

Please leave this notice intact. 

*****/


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

var d = document
var imgs = new Array();
var zInterval = null;
var current = 0;

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

	imgs = d.getElementById("img_container").getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) {
     imgs[i].xOpacity = 0;
  }

	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	
	setTimeout(so_xfade,5000);
}

function so_xfade() {
	var curOpacity = imgs[ current ].xOpacity;    // current opacity
	var nextIndex  = imgs[ current + 1 ] ? current + 1 : 0;  // next index

	nextOpacity = imgs[ nextIndex ].xOpacity;
	
	curOpacity  -= .05;
	nextOpacity += .05;
	
	imgs[ nextIndex ].style.display = "block";
	imgs[ current   ].xOpacity = curOpacity;
	imgs[ nextIndex ].xOpacity = nextOpacity;

	setOpacity( imgs[ current ] ); 
	setOpacity( imgs[ nextIndex ] );
	
	if( curOpacity <= 0 ) {
    // Hide current when fade out is complete and pause
		imgs[ current ].style.display = "none";
		current = nextIndex;
		setTimeout( so_xfade, 5000 );
	}
  else {
		setTimeout( so_xfade, 50 );
	}
	
	function setOpacity( obj ) {
		if( obj.xOpacity > .99 ) {
			obj.xOpacity = .99;
			return;
		}

		obj.style.opacity      = obj.xOpacity;
		obj.style.MozOpacity   = obj.xOpacity;
    obj.style.KhtmlOpacity = obj.xOpacity;
		obj.style.filter       = "alpha(opacity=" + ( obj.xOpacity * 100 ) + ")";
	}
}

