// Cross browser opacity transition courtesy of http://www.brainerror.net/scripts_js_blendtrans.php
// Hacked by Robin ;-)
var opacity = {
	
	set: function (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("opacity.change(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		} 
		else if(opacStart < opacEnd) 
		{
			for(i = opacStart; i <= opacEnd; i++)
			{
				setTimeout("opacity.change(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		}
	},
	
	change: function (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 + ")";
	},
	
	shift: function(id, millisec) 
	{
		//if an element is invisible, make it visible, else make it ivisible
		
		var currentOpacity = document.getElementById(id).style.opacity;
		
		if((currentOpacity == 0) || (currentOpacity != ''))
			opacity.set(id, 0, 100, millisec);
		else
			opacity.set(id, 100, 0, millisec);
	},
	
	current: function(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.set(id, currentOpac, opacEnd, millisec)
	}
};

/*function blendImage(divid, imageid, imagefile, millisec)
	{
		
		//alert(divid +"\n\r"+ imageid +"\n\r"+ imagefile +"\n\r"+ millisec);
		window.setTimeout("blendImage2('" + divid + "','" + imageid + "','" + imagefile + "','" + millisec + "')", 1);	
		
	}*/


function blendImage(divid, imageid, imagefile, millisec, tranflag) //divid, imageid, imagefile, millisec
{
	var speed = Math.round(millisec / 100);
	var timer = 0;
						  
			document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
				
			opacity.change(0, imageid);
				
			document.getElementById(imageid).src = imagefile;
			
			//if(transflag = 1){
				for(i = 0; i <= 100; i++) 
				{
					setTimeout("opacity.change(" + i + ",'" + imageid + "')",(timer * speed));
					timer++;
				}
			//}
}