var oldImage = "7player";

function setOpacity(domId, val) {
	obj = document.getElementById(domId);
	obj.style.MozOpacity = val;
	obj.style.opacity = val/10;
	obj.style.filter = 'alpha(opacity=' + val*10 + ')';
};

function fadeOut(domId, time){
	obj = document.getElementById(domId); //Get the Element
	var alpha = 10; //Set the initial value of alpha to 10 (Opaque)
	function f(){ //Internal function
		alpha--; //Decrememnt the alpha value
		setOpacity(domId, alpha); //Set the opacity of our element to the specified alpha
		if(alpha > -1){ //If alpha is still bigger than -1 then..
			setTimeout(f, 100); //..then call the function again after 100 milliseconds
		}else{ //otherwise..
			obj.style.display = 'none'; //..otherwise now that we cant see the element anyways, hide it
		}
	}
	setTimeout(f, 100); //This is where we call the f() function for the first time
};

function fadeIn(domId, time){
	obj = document.getElementById(domId); //Get the element
	obj.style.display = ''; //Un-hide the object before its animation
	var alpha = 0; //Set the initial value of alpha to 0 (invisible)
	function a(){ //Internal function
		alpha+=.25; //Increment alpha
		setOpacity(domId, alpha); //Set the opacity of our element to the specified alpha
		if(alpha < 11)setTimeout(a, time);
		/*Till alpha is 10, keep calling the
		a() function after 100 milliseconds */
	}
	setTimeout(a, time); //This is where we call the a() function for the first time
};

function fadeElement(domId, time) {
	//fadeOut(oldImage, 100.0);
	obj = document.getElementById(oldImage);
	obj.style.display = 'none';
	setOpacity(oldImage, -1);
	oldImage = domId;

	
	obj = document.getElementById(domId); 
	if(obj.style.display == "none") {
		fadeIn(domId, time);
	} else {
		fadeOut(domId, time);
	}
}
