// global variable for menu Animation
var myitem;

// set up month rollover scripts
function initNav(menu) {
	// drop down
	if (document.getElementById && document.getElementById(menu)) {
		navRoot = document.getElementById(menu);
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.className == "mmhide_collapsed") {
				node.onmouseover = function() {
					this.className = 'mmhide_expanded';
					if(this.childNodes[1].childNodes.length>0){
						if(currentMenu != this.childNodes[1].childNodes[0].id){
							if(currentMenu != ""){
								document.getElementById(currentMenu+"Menu").className= 'mmhide_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 = 'mmhide_collapsed';
				}
				
				var mmhide_navItems = node.childNodes;
				for (k=0; k<mmhide_navItems.length; k++) {
					if (mmhide_navItems[k].className == "mmhide_navItem") {
						if(mmhide_navItems[k].id==section)mmhide_navItems[k].className = "mmhide_navItemOn";
					}
					if (mmhide_navItems[k].className == "mmhide_altmmhide_navItem") {
						if(mmhide_navItems[k].id==section)mmhide_navItems[k].className = "mmhide_altmmhide_navItemOn";
					}
				}
				
			}

		}

		mytest=navRoot.getElementsByTagName("li");
		for (j=0; j<mytest.length; j++) {
			if (mytest.item(j).className == "mmhide_menuItem") {
				dropElem = mytest.item(j);
				dropElem.onmouseover = function() {this.className = 'mmhide_menuItemOver';}
				dropElem.onmouseout = function() {this.className = 'mmhide_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;
}