// Functions Created by Dominion Digital (c) 2007
// info@dominiondigital.com

window.onload = init;

function init() {
	traverseTree(document.getElementById("mainMenuContainer"));

  // set the font size of the "contentContainer" on page load
	var theFont = getCookie("font");
	contentDIV = document.getElementById("contentContainer");

	if (theFont) 
	{
		setFontSize(theFont); 
	} 
	else 
	{
		changeFontSize();
	}

}

function traverseTree(whatTree){	
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])
	}
	
	if (version==6) {	
		if (whatTree.hasChildNodes()) {
			for(var i=0;i<whatTree.childNodes.length;i++) {
				var node_str = whatTree.childNodes[i]
				if (node_str.nodeName=="UL") {
					for(var j=0;j<node_str.childNodes.length;j++) {
						var subnode_str = node_str.childNodes[j]
						if (subnode_str.nodeName=="LI") {
							setItAndForgetIt(subnode_str);
							traverseTree(subnode_str);
						}
					}
				}
			}		
		} 
	} 
}

function setItAndForgetIt(whichNode) {
	whichNode.onmouseover=function() {
	  this.className+=" over";
	}
	whichNode.onmouseout=function() {
	  this.className=this.className.replace("over", "");
	}
}

function toggleDiv(whichID) {
	var divObject = document.getElementById(whichID)
	if (divObject.style.display == "block") {
		  divObject.style.display = "none";
	} else {
		  divObject.style.display = "block";
	}
}	

function hideDiv(whichID) {
  document.getElementById(whichID).style.display = "none";
}	
function showDiv(whichID) {
  document.getElementById(whichID).style.display = "block";
}	

/* Floating Div Script */
var verticalpos="fromtop"

function floatDiv(whichDiv) {

	startX=0,
	startY=0;
	var browser=(navigator.appName.indexOf("Netscape")!=-1);
	var d=document;
	
	function getStartPosition(id){
		var ourElement=d.getElementById(id);
		ourElement.startPosition=function(x,y) {
				this.style.right=x+'px';
				this.style.top=y+'px';
			}
		ourElement.x = startX;
		ourElement.y=startY;
		return ourElement;
	}
	window.refixPosition=function() {
		var yPosition=browser?pageYOffset:d.body.parentNode.scrollTop;
		floatingObject.y+=(yPosition+startY- floatingObject.y)/8;
		floatingObject.startPosition(floatingObject.x,floatingObject.y);
		setTimeout('refixPosition()',10);
		}
	floatingObject=getStartPosition(whichDiv);
	refixPosition();
}



function getWindowHeight() {
	var windowHeight=0;
		if (typeof(window.innerHeight)=='number') {
			windowHeight=window.innerHeight;
		} else {
		if (document.documentElement&&document.documentElement.clientHeight) {
			windowHeight=document.documentElement.clientHeight;
			} else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
				}
			}
		}	
	return windowHeight;
}

function setBoxHeight() {
	if (document.getElementById) {
		var windowHeight=getWindowHeight();
		if (windowHeight>0) {
			var boxElement=document.getElementById('schedule');
			if (windowHeight>=511) {
				boxElement.style.height=windowHeight-466+'px';
			} else {
				boxElement.style.height=150+'px';
			}
		}
	}
}

function rosterToggleClass(whichID) {
	var divObject = document.getElementById(whichID);
	if (divObject.className == "detailsCollapsed") {
		divObject.className = "detailsOpen";
	} else {
		divObject.className = "detailsCollapsed";
	}
}



/***** Font resizer *****/
function changeFontSize(whichDirection) 
{
  if (contentDIV != null)
  {
	  //This works by swapping the current class for the content area for a different preset one in rex_content.css
	  var min=0;
	  var max=5;
	  var classParts = contentDIV.className.split("_");
  	
	  currentClass = parseInt(classParts[1]);

	  if (!currentClass) 
	  {
		  newClass = 2;
	  }
  	
	  if (whichDirection=="up") 
	  {
		  if(currentClass!=max) 
		  {
			  newClass = currentClass + 1;
		  } 
		  else 
		  {
			  newClass = currentClass;
		  }
	  } 
	  else if (whichDirection=="down") 
	  {
		  if(currentClass!=min) 
		  {
			  newClass = currentClass - 1;
		  } 
		  else 
		  {
			  newClass = currentClass;
		  }
	  } 
	  else 
	  {
		  newClass = 2;
	  }
  			
	  setFontSize(newClass); 
  }
}

function setFontSize(whatSize) 
{
	if (contentDIV) 
	{
		contentDIV.className = "fontSize_" + whatSize; 
	  setCookie("font",whatSize);
	}
}


function setCookie(name,inpVal) 
{
	inpVal=escape(inpVal); // just in case of special characters
	var nodays = 15;
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	document.cookie = name + "=" + inpVal + "; path=/; expires="+UTCstring;
	return true;
}

function getCookie(name) 
{ // use: getCookie("name");
	var allCookies = document.cookie;
  var index = allCookies.indexOf(name + "=");
  
  if (index == -1) 
    return false;
  
  index = allCookies.indexOf("=", index) + 1; // first character
  var endstr = allCookies.indexOf(";", index);
  
  if (endstr == -1) 
    endstr = allCookies.length; // last character
    
  return unescape(allCookies.substring(index, endstr));
}