/*var fadeInTimer = null;
	if (typeof fadeInTimer!="undefined")
		clearTimeout(fadeInTimer)*/
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

/*
The fadeIn function uses a Timeout to call itself every 100ms with an object Id and an opacity.
The opacity is specified as a percentage and increased 10% at a time.
The loop stops once the opacity reaches 100%:
*/
function fadeIn(objId,opacity,inc) {
	if (fadingIn) {
		clearTimeout(fadingIn)
		fadingIn=false;
	}
	
	var obj = getObj(objId);

	if (opacity <= 100) {
    	setOpacity(obj, opacity);
      	opacity += inc;
      	window.setTimeout("fadeIn('"+objId+"',"+opacity+","+inc+",false)", 10);
		fadingIn = true;
    } else
		fadingIn=false;
}
function fadeInWithDelay(objId,opacity,inc,delay) {
	if (typeof fadingInWithDelay!="undefined"
		&& fadingInWithDelay!=null) {
		clearTimeout(fadingInWithDelay)
		fadingInWithDelay=null;
	}
	
	var obj = getObj(objId);

	if (opacity <= 100) {
    	setOpacity(obj, opacity);
      	opacity += inc;
	  	if (delay) {
	    	fadingInWithDelay = window.setTimeout("fadeInWithDelay('"+objId+"',"+opacity+","+inc+",false)", 1000);
	  	} else {
	      	fadingInWithDelay = window.setTimeout("fadeInWithDelay('"+objId+"',"+opacity+","+inc+",false)", 40);
	  	}
    }
}
/* Fade out an DOM object */
function fadeOut(objId,opacity,inc,delay) {
	var obj = getObj(objId);

	if (opacity >= 0) {
    	setOpacity(obj, opacity);
      	opacity -= inc;
	  	if (delay) {
	    	window.setTimeout("fadeOut('"+objId+"',"+opacity+","+inc+",false)", 1000);
	  	} else {
	      	window.setTimeout("fadeOut('"+objId+"',"+opacity+","+inc+",false)", 40);
	  	}
    }
}

/*
Overwrites the browser "click" policy forcing a fade out before new page is loaded.
USED to fade out content before exiting page and loading a new one.
*/
function exitURL(e) {
   if (!document.getElementById) return true; // DOM only
   
   if (!e) { 
      var e = window.event; // IE
      var elmClick = e.srcElement;
   } else { 
      var elmClick = e.target; // FF
   }
   while (String(elmClick.nodeName) != "A") {
      elmClick=elmClick.parentNode; // up the tree 
      if (String(elmClick.nodeName) == "HTML") return true;
   }
   url = String(elmClick);
	// url.indexOf("http") // going somewhere? -1 == NO
	// url.indexOf(location.hostname) // where server?
	// return false == can't leave
	// alert(url+" ? "+url.indexOf("http")+" ? "+url.indexOf(location.hostname));
	if (typeof unloading=="undefined") {
		unloading = true;
		fadeOut('MediaPanel',100,4,0);
		setTimeout("exitURL(event)", 10000);
	}
	
	return true; // pass back to originating object
}