var img_index, doc=document, tran_step, tran_delay, tran_fade_interruption, img_arr = new Array(), div_index;
var div_arr = new Array();

function set_variables() {
	div_index = 0;
	img_index = 0;
	tran_step = 0.01;
	tran_delay = 10000;
	tran_fade_interruption = 20; // tran_duration / 50 ; 
	
	quote_delay = 6500;
	quote_fade_interruption=15;
}

if (window.addEventListener ) {
	window.addEventListener("load",fun_onload,false)
} else {
	window.attachEvent("onload",fun_onload);
}



function fun_transition() {
	img_opacity = img_arr[img_index].xOpacity;
	var exist_next = img_arr[img_index+1];
	if (exist_next) {
		new_img_index = img_index+1;
	} else {
		new_img_index= 0;
	}

	new_img_opacity = img_arr[new_img_index].xOpacity;
	
	img_opacity = img_opacity - tran_step; 
	new_img_opacity = new_img_opacity + tran_step;
	
	img_arr[new_img_index].style.display = "block";
	img_arr[img_index].xOpacity = img_opacity;
	img_arr[new_img_index].xOpacity = new_img_opacity;
	
	modifyTransparency(img_arr[img_index]); 
	modifyTransparency(img_arr[new_img_index]);
	
	if(img_opacity >= tran_step) {
		setTimeout(fun_transition,tran_fade_interruption);
	} else {
		img_arr[img_index].style.display = "none";
		img_index = new_img_index;
		setTimeout(fun_transition,tran_delay);
	}
	
	function modifyTransparency(obj) {
		if(obj.xOpacity + tran_step > 1) {
			obj.xOpacity = 1; // not crossing the limit
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}



function div_transition() {
	div_opacity = div_arr[div_index].xOpacity;
	var exist_next = div_arr[div_index+1];
	if (exist_next) {
		new_div_index = div_index+1;
	} else {
		new_div_index= 0;
	}

	new_div_opacity = div_arr[new_div_index].xOpacity;
	
	div_opacity = div_opacity - tran_step; 
	new_div_opacity = new_div_opacity + tran_step;
	div_arr[new_div_index].style.display = "block";
	div_arr[div_index].xOpacity = div_opacity;
	div_arr[new_div_index].xOpacity = new_div_opacity;
	
	modifyTransparency(div_arr[div_index]); 
	modifyTransparency(div_arr[new_div_index]);
	
	if(div_opacity >= tran_step) {
		setTimeout(div_transition,quote_fade_interruption);
	} else {
		div_arr[div_index].style.display = "none";
		div_index = new_div_index;
		setTimeout(div_transition,quote_delay);
	}
	
	function modifyTransparency(obj) {
		if(obj.xOpacity + tran_step > 1) {
			obj.xOpacity = 1; // not crossing the limit
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}




function fun_onload() {
	set_variables();

	if(!doc.getElementById || !doc.createElement) return;

	stylesheet = doc.createElement("link");
	stylesheet.setAttribute("type","text/css");
	stylesheet.setAttribute("href","transition.css");
	stylesheet.setAttribute("rel","stylesheet");
	doc.getElementsByTagName("head")[0].appendChild(stylesheet);
	
	/**images**/
	img_arr = doc.getElementById("transition-box").getElementsByTagName("img");
	for(i=1;i<img_arr.length;i++) img_arr[i].xOpacity = 0;
	img_arr[0].style.display = "block";
	img_arr[0].xOpacity = 1;
	
	/**quotes**/
/*	div_arr = doc.getElementById("quotes").getElementsByTagName("div");
	for(i=1;i<div_arr.length;i++) div_arr[i].xOpacity = 0;
	div_arr[0].style.display = "block";
	div_arr[0].xOpacity = 1;*/
	
	setTimeout(fun_transition,tran_delay);
//	setTimeout(div_transition,quote_delay);
}


