// JavaScript Document
// JavaScript Document
/* 
	a few concepts were taken form: http://brainerror.net/scripts/javascript/blendtrans/
*/
var timerID = new Array();
var which  = 0;
var rotate_time = 4000;

function start(div_id, img_id, path, image_prefix, image_total) {
	which += 1;
	if(which > image_total )
	{
		which = 1;
	}
	blendimage(div_id, img_id, path, image_prefix, rotate_time, image_total, which);
	timerID = setTimeout("start('"+div_id+"', '"+img_id+"', '"+path+"', '"+image_prefix+"', '"+image_total+"')", rotate_time);
}
/**
######################################################################
**/
function blendimage(divid, imageid, path, image_prefix, rotate_time, image_total, count) {
	var speed = Math.round(rotate_time / 300);
	var timer = 0;
	var timer_id = null;
	
	//fade in image
	for(i = 100; i >= 0; i--) {
		timer_id = setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
		if(i == 0)
		{
			clearTimeout(timer_id);
			//switch background to the top image
			imagefile = path+image_prefix+count+'.jpg';
			document.getElementById(imageid).src = imagefile;
			//set opac to 100 for image
			changeOpac(100, imageid);
			//set new background
			count++;
			if(count > image_total){
				count = 1;
			}
			bg_image = path+image_prefix+count+'.jpg';
			document.getElementById(divid).style.background = " url('"+bg_image + "') no-repeat";
		}
	}
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}
/**************************************/
