var delay = 5000;
var transition = 40;
var imageContainer = 'mod_banner_container';
var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;
var timer = null;
var intransition = false;

function so_init() {
	if(!d.getElementById || !d.createElement)return;
	imgs = d.getElementById(imageContainer).getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	timer = setTimeout(so_fadetonext,delay);
}

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 so_next()
{
	if (!intransition)
	{
		so_fadetonext();
	}
}

function so_back()
{
	if (!intransition)
	{
		so_fadetoback();
	}
}

function so_fadetonext()
{

	// Cancel the current timer
	clearTimeout(timer);
	timer=null;
	
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;
	cOpacity-=.1; 
	nOpacity+=.1;
	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;
		intransition = false;
		timer = setTimeout(so_fadetonext,delay);
	} else {
		intransition = true;
		setTimeout(so_fadetonext,transition);
	}
}

function so_fadetoback()
{

	// Cancel the current timer
	clearTimeout(timer);
	timer=null;
	
	cOpacity = imgs[current].xOpacity;
	if (current - 1 < 0)
	{
		nIndex = imgs.length - 1;
	}
	else
	{
		nIndex = current - 1;
	}
	nOpacity = imgs[nIndex].xOpacity;
	cOpacity-=.1; 
	nOpacity+=.1;
	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;
		intransition = false;
		timer = setTimeout(so_fadetoback,delay);
	} else {
		intransition = true;		
		timer = setTimeout(so_fadetoback,transition);
	}
}

// Load everything up
function init_ahr() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;
	so_init();
};

// DOM2
if ( typeof window.addEventListener != "undefined" ) { window.addEventListener( "load", init_ahr, false ); }
// IE 
else if ( typeof window.attachEvent != "undefined" ) { window.attachEvent( "onload", init_ahr ); }
else {
	if ( window.onload != null ) {
		var oldOnload = window.onload;
		window.onload = function ( e ) {
			oldOnload( e );
			init_ahr();
		};
	}
	else 
		window.onload = init_ahr;
}


