// global variable for menu Animation
var myitem;

// set up month rollover scripts
function initNav() {
	// drop down
	if (document.getElementById && document.getElementById("mainMenu")) {
		navRoot = document.getElementById("mainMenu");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.className == "collapsed") {
				node.onmouseover = function() {
					this.className = 'expanded';
					if(this.childNodes[1].childNodes.length>0){
						if(currentMenu != this.childNodes[1].childNodes[0].id){
							if(currentMenu != ""){
								document.getElementById(currentMenu+"Menu").className= 'collapsed';
								document.getElementById(currentMenu).style.clip = "rect(0px 500px 0px 0px)";
							}
							if(currentMenu != "")document.getElementById(currentMenu).style.clip = "rect(0px 500px 0px 0px)";
							currentMenu = this.childNodes[1].childNodes[0].id;
							clearTimeout(currentAnim);
							myitem = document.getElementById(this.childNodes[1].childNodes[0].id);
							myitem.style.clip = "rect(0px 500px 0px 0px)";
							menuAnim(myitem);
						}
					}else{
						currentMenu = "";
					}
					
				}
				node.onmouseout = function() {
					this.className = 'collapsed';
				}
				
				var navitems = node.childNodes;
				for (k=0; k<navitems.length; k++) {
					if (navitems[k].className == "navItem") {
						if(navitems[k].id==section)navitems[k].className = "navItemOn";
					}
					if (navitems[k].className == "altNavItem") {
						if(navitems[k].id==section)navitems[k].className = "altNavItemOn";
					}
				}
				
			}

		}

		mytest=navRoot.getElementsByTagName("li");
		for (j=0; j<mytest.length; j++) {
			if (mytest.item(j).className == "menuItem") {
				dropElem = mytest.item(j);
				dropElem.onmouseover = function() {this.className = 'menuItemOver';}
				dropElem.onmouseout = function() {this.className = 'menuItem';}
			}
		}

	}
	
}

// Animation Functions
currentMenu = "";
currentAnim = "";

function menuAnim(elm){
	val = elm.style.clip.split("rect(")[1].split(")")[0].split("px")[2]
	if(clipValues(elm,'b')>=400){}
	else {	
		clipBy(elm,0,0,10,0);
		currentAnim = setTimeout('menuAnim(myitem)',1)
	}
}

function clipValues(elm, which) {
	var clipv = elm.style.clip.split("rect(")[1].split(")")[0].split("px")
	if (which=="t") return  Number(clipv[0].replace(/, /g,""))
    if (which=="r") return  Number(clipv[1].replace(/, /g,""))
    if (which=="b") return  Number(clipv[2].replace(/, /g,""))
    if (which=="l") return  Number(clipv[3].replace(/, /g,""))
}

function clipBy(elm,t,r,b,l) {
    clipTo(elm,clipValues(elm,'t')+t,clipValues(elm,'r')+r,clipValues(elm,'b')+b,clipValues(elm,'l')+l)
}

function clipTo(elm,t,r,b,l) {
	if (t==null) t = 0
    if (r==null) r = 500
    if (b==null) b = 500
    if (l==null) l = 0
	elm.style.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"
}

//Linking Function
function openLink(url, newWin){
	if (newWin){window.open(url);}
	else{top.location.href=url;}
}
//Search Submit Function
function validateSearchText() {
	if( document.hdr_search.query_text1.value == "" || document.hdr_search.query_text1.value == "Search" ) { alert('Please enter search keyword'); return false; } 
	else return true;
}