function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}
//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 + ")";
	if(opacity==0)showdiv(id,0);
	else {showdiv(id,1);}
	if(opacity==100 && id=="e"+current)fully=1;
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}
var current=0,is_halt=0,timer=0;
var interval=new Array();
var num=2,fully=0;
function showdiv(id,state) 
{
	document.getElementById(id).style.visibility = (state==1)?"visible":"hidden";
}
function change()
{
	if(fully==1)
	{
		fully=0;
		anim(1,1);
	}
}
function init(n)
{
	num=n;
	changeOpac(100,"e0");
	interval[0]=8000;
	for(i=1;i<num;i++)
	{
		changeOpac(0,"e"+i);
		interval[i]=8000;
	}
}
function setinterval(i,val)
{
	interval[i]=val*1000;
}
var tok=0;
function timer_set(v){if(tok==v){timer=1;anim(0,1);}}
function timer_start()
{
	setTimeout('timer_set('+(++tok)+')',interval[current]);
}
function anim(v,dir)
{
	if((!is_halt && timer)||v)
	{
		shiftOpacity("e"+current,500);
		current=(num+current+dir)%num;
		shiftOpacity("e"+current,500);
		timer_start();
		timer=0;
	}
}

function halt(v)
{
	is_halt=v;
	if(!is_halt)
		anim(0,1);
}
function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}