window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var d=document, imgs = new Array(), bullets = new Array(), zInterval = 5000, current=0, next=1, pause=false, timer1;

function so_init() {
	if (!d.getElementById || !d.createElement) return;

	imgs = d.getElementById("imageContainer").getElementsByTagName("img");
	bullets = d.getElementById("bulletsContainer").getElementsByTagName("a");
	for(i=0;i<imgs.length;i++) {
		imgs[i].xOpacity = 0;
		imgs[i].id = i;
		imgs[i].onclick = function() {
			location.href=bullets[this.id].href;
		};
	}
	showImg(0);
	
	for (i=0; i<bullets.length; i++) {
		bullets[i].id = i;
		bullets[i].onmouseover = function() {
			showImg(this.id);
			clearTimeout(timer1);
                        current=this.id
			timer1 = setTimeout("nextImg("+this.id+ ")",zInterval);
		};
	}
	timer1 = setTimeout(nextImg,zInterval);
}
function getNext(c) {
	return imgs[parseInt(c,10)+1]?(parseInt(c,10)+1):0;
}
function animate(obj) {
	obj.xOpacity = obj.xOpacity + (obj.tOpacity - obj.xOpacity)*0.3;
	if (Math.abs(obj.xOpacity-obj.tOpacity)<0.01) {
		obj.xOpacity = obj.tOpacity;
	} else {
		setTimeout("animate(imgs["+obj.id+"]);",50);
	}
	if (obj.xOpacity > 0) {
		obj.style.display = "block";
	} else {
		obj.style.display = "none";
	}
	setOpacity(obj);
}

function showForm(obj,val) {
	obj = d.getElementById(obj);
	if (val > 0) {
		obj.style.display = "block";
	} else {
		obj.style.display = "none";
	}
}

function showImg(c) {
	current = c;
	for (i = 0; i < imgs.length; i++) {
		imgs[i].tOpacity = (i == c)?.99:0;
		bullets[i].className = (i == c)?"active":"non-active";
		setTimeout("animate(imgs["+i+"]);",50);
	}
}
function nextImg(ca) {
/*	if (ca>-1) {
		current = getNext(ca);
	} else { */
		current = getNext(current);
//	}
	showImg(current);
	timer1 = setTimeout(nextImg,zInterval);
}
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) + ")";
}
