// Functions Created by Dominion Digital (c) 2007
// info@dominiondigital.com

window.onload = init;

function init() {
	traverseTree(document.getElementById("mainmenuContainer"));
	
	var theFont = getCookie("font");
	contentDIV = document.getElementById("column2");

	if (theFont) {
		setFontSize(theFont); 
	} else {
		changeFontSize();
	}
	
}

function traverseTree(whatTree){
	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";
}	

function changeFontSize(whichDirection) {
	//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 contentDIV = document.getElementById("column2");
	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); 
	setCookie("font",newClass);
}

function setFontSize(whatSize) {
//	var contentDIV = document.getElementById("column2");
	if (contentDIV) {
		contentDIV.className = "fontSize_" + 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));
}

function emailPage() {
	emailForm = document.createElement("form");
	emailForm.method = "post";
	emailForm.action = "/email_page.asp";
	document.appendChild(emailForm)
	inputPageTitle = document.createElement("input");
	inputPageTitle.name = "pageTitle";
	inputPageTitle.type = "text";
	inputPageTitle.value = document.title;
	emailForm.appendChild(inputPageTitle)

	emailForm.submit();
}