//Opacity function
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 + ")";}

//Ajax Functions
function setActive(x){
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null){alert ("Browser does not support HTTP Request");return;}
	var url="return.php?active="+x;
	xmlhttp.onreadystatechange=retrieveActive;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);}
function retrieveActive(){
	if (xmlhttp.readyState==4){
	document.getElementById("activeOption").innerHTML=xmlhttp.responseText;}}
function GetXmlHttpObject(){
	if (window.XMLHttpRequest){/* code for IE7+, Firefox, Chrome, Opera, Safari */
	return new XMLHttpRequest();}
	if (window.ActiveXObject){/*code for IE6, IE5*/
	return new ActiveXObject("Microsoft.XMLHTTP");}
	return null;}

//Content Variables
var activeOn = "NO";
var activeIs = "HOME";

//Show a loading circle
function showLoad(){
	var roundLoad = '<img src="BG/roundLoad.gif" id="roundLoad" />';
	document.getElementById('activeOption').innerHTML='';}

//Empty the Content Holder
function clearActive(){document.getElementById('activeOption').innerHTML='';}

//Return to Home Screen
function resetActive(){
	if(activeIs!="HOME"){
		opacity('activeOption',100,0,400);
		opacity('TBG',0,100,400);
		setTimeout("opacity('LBG',0,100,400)",150);
		setTimeout("opacity('VBG',0,100,400)",250);
		setTimeout("clearActive()",400);
		activeOn = "NO"; activeIs = "HOME";}}

//Fade from Home
function fadeFromHome(){
	showLoad();
	opacity('VBG',100,0,400);
	setTimeout("opacity('LBG',100,0,400)",100);
	setTimeout("opacity('TBG',100,0,400)",250);
	setTimeout("opacity('activeOption',0,100,400)",250);}

//Fade from Active Content
function fadeFromContent(){
	opacity('activeOption',100,0,400);
	setTimeout("showLoad()",399);
	setTimeout("opacity('activeOption',0,100,350)",500);}

//Initiate a Content Change
function activeContent(content, onStatus, isStatus){
	if(content==activeIs){;}
	else if(content!=activeIs && activeOn=="NO"){
		fadeFromHome();
		setActive(content);
		activeOn = onStatus;activeIs = isStatus;}
	else if(content!=activeIs && activeOn=="YES"){
		fadeFromContent();
		setTimeout('setActive(\"'+content+'\")',450);
		activeOn = onStatus;activeIs = isStatus;}}
	
