﻿window.addEventListener ? window.addEventListener("load", banner_init, false): window.attachEvent("onload", banner_init);

var d=document, imgs1=new Array(), imgs2=new Array(), zInterval=null, current1=0, current2=0, pause=false;
var duration1=12000, duration2=15000

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;
	
	setTimeout(banner1_fade, duration1);
	setTimeout(banner2_fade, duration2);
}

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 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) + ")";
}
