﻿window.addEventListener ? window.addEventListener("load", banner_init, false): window.attachEvent("onload", banner_init);

var d=document, imgs1=new Array(), imgs2=new Array(), imgs3=new Array(), imgs4=new Array(), zInterval=null, current1=0, current2=0, current3=0, current4=0, pause=false;
var duration1=6000, duration2=10000, duration3=8000, duration4=12000;

function banner_init() 
{
	if (!d.getElementById || !d.createElement)
	    return;
	    
	imgs1 = d.getElementById("imageContainer1").getElementsByTagName("img");
	for(i=1; i <imgs1.length; i++) imgs1[i].xOpacity = 0;
	imgs1[0].style.display = "block";
	imgs1[0].xOpacity = .99;
	
    imgs2 = d.getElementById("imageContainer2").getElementsByTagName("img");
	for(i=1; i <imgs2.length; i++) imgs2[i].xOpacity = 0;
	imgs2[0].style.display = "block";
	imgs2[0].xOpacity = .99;
	
	imgs3 = d.getElementById("imageContainer3").getElementsByTagName("img");
	for(i=1; i <imgs3.length; i++) imgs3[i].xOpacity = 0;
	imgs3[0].style.display = "block";
	imgs3[0].xOpacity = .99;
	
	imgs4 = d.getElementById("imageContainer4").getElementsByTagName("img");
	for(i=1; i <imgs4.length; i++) imgs4[i].xOpacity = 0;
	imgs4[0].style.display = "block";
	imgs4[0].xOpacity = .99;
	
	setTimeout(banner1_fade, duration1);
	setTimeout(banner2_fade, duration2);
	setTimeout(banner3_fade, duration3);
	setTimeout(banner4_fade, duration4);
}

function banner1_fade() 
{
	cOpacity = imgs1[current1].xOpacity;
	nIndex = imgs1[current1+1] ? current1+1 : 0;
	nOpacity = imgs1[nIndex].xOpacity;
	cOpacity-=.05; 
	nOpacity+=.05;
	imgs1[nIndex].style.display = "block";
	imgs1[current1].xOpacity = cOpacity;
	imgs1[nIndex].xOpacity = nOpacity;
	setOpacity(imgs1[current1]); 
	setOpacity(imgs1[nIndex]);

	if (cOpacity<=0) 
	{
		imgs1[current1].style.display = "none";
		current1 = nIndex;
		setTimeout(banner1_fade, duration1);
	} 
	else 
		setTimeout(banner1_fade, 50);
}

function banner2_fade() 
{
	cOpacity = imgs2[current2].xOpacity;
	nIndex = imgs2[current2+1] ? current2+1 : 0;
	nOpacity = imgs2[nIndex].xOpacity;
	cOpacity-=.05; 
	nOpacity+=.05;
	imgs2[nIndex].style.display = "block";
	imgs2[current2].xOpacity = cOpacity;
	imgs2[nIndex].xOpacity = nOpacity;
	setOpacity(imgs2[current2]); 
	setOpacity(imgs2[nIndex]);

	if (cOpacity<=0) 
	{
		imgs2[current2].style.display = "none";
		current2 = nIndex;
		setTimeout(banner2_fade, duration2);
	} 
	else 
		setTimeout(banner2_fade, 50);
}

function banner3_fade() 
{
	cOpacity = imgs3[current3].xOpacity;
	nIndex = imgs3[current3+1] ? current3+1 : 0;
	nOpacity = imgs3[nIndex].xOpacity;
	cOpacity-=.05; 
	nOpacity+=.05;
	imgs3[nIndex].style.display = "block";
	imgs3[current3].xOpacity = cOpacity;
	imgs3[nIndex].xOpacity = nOpacity;
	setOpacity(imgs3[current3]); 
	setOpacity(imgs3[nIndex]);

	if (cOpacity<=0) 
	{
		imgs3[current3].style.display = "none";
		current3 = nIndex;
		setTimeout(banner3_fade, duration3);
	} 
	else 
		setTimeout(banner3_fade, 50);
}

function banner4_fade() 
{
	cOpacity = imgs4[current4].xOpacity;
	nIndex = imgs4[current4+1] ? current4+1 : 0;
	nOpacity = imgs4[nIndex].xOpacity;
	cOpacity-=.05; 
	nOpacity+=.05;
	imgs4[nIndex].style.display = "block";
	imgs4[current4].xOpacity = cOpacity;
	imgs4[nIndex].xOpacity = nOpacity;
	setOpacity(imgs4[current4]); 
	setOpacity(imgs4[nIndex]);

	if (cOpacity<=0) 
	{
		imgs4[current4].style.display = "none";
		current4 = nIndex;
		setTimeout(banner4_fade, duration4);
	} 
	else 
		setTimeout(banner4_fade, 50);
}
	
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) + ")";
}