var remember = true; //Remember menu states, and restore them on next visit.
var contractall_default= false; //Should all submenus be contracted by default? (true or false)

var menu, titles, submenus, arrows, bypixels;
var heights = new Array();

var n = navigator.userAgent;
if(/Opera/.test(n)) bypixels = 2;
else if(/Firefox/.test(n)) bypixels = 3;
else if(/MSIE/.test(n)) bypixels = 2;

 
var speed=25;  
/////DD added expandall() and contractall() functions/////

function slash_expandall(){
if (typeof menu!="undefined"){
	for(i=0; i<Math.max(titles.length, submenus.length); i++){
		titles[i].className="CurrentItem";
		arrows[i].src = imgpath+"/dropdown.gif";
		submenus[i].style.display="";
		submenus[i].style.height = heights[i]+"px";
	}
}
}



function slash_contractall()
{
	if (typeof menu!="undefined")
	{
		if(expandall == false)
		{
			for(i=0; i<Math.max(titles.length, submenus.length); i++)
			{
				currents[i].className="NoSelect";
				arrows[i].src = imgpath+"/dropdown.gif";
				submenus[i].style.display="none";
				submenus[i].style.height = 0+"px";
				submenusli[i].style.display = "none";
			}
		}
	}
}


/////End DD added functions///////////////////////////////


function init(showmenuid,showmenuidlist){
	
    menu = getElementsByClassName("NavManagerMenu", "div", document)[0];
    titles = getElementsByClassName("CurrentItem", "li", menu);
    arrows = getElementsByClassName("arrow", "img", menu);
    submenus = getElementsByClassName("Submenu1", "div", menu);
    submenusli = getElementsByClassName("Submenu", "li", menu);
    currents = getElementsByClassName("current", "div", menu);
   
    
   for(i=0; i<Math.max(titles.length, submenus.length); i++) {
        //currents[i].onclick = gomenu;
        //arrows[i].onmousedown = gomenu;
        //titles[i].onclick = gomenu;
        heights[i] = submenus[i].offsetHeight;
        submenus[i].style.height = submenus[i].offsetHeight+"px";
        
        submenus[i].style.display = "none";
        currents[i].style.display = "none";
        titles[i].style.display = "none";
        currents[i].className="NoSelect";
        submenusli[i].style.display = "none";
       /*alert(i); */
	
//	    if(expandall == false)
//	    {
//			//if(i>0)
//			{
//				//titles[i].className="li";
//				//currents[i].className = "NavManagerMenu li";
//				
//				arrows[i].src = imgpath+"/dropdown.gif";
//				submenus[i].style.display="none";
//				//submenus[i].style.height = 0;
//				//currents[i].style.height=200+'px';
//				//alert('123');
//			}
//			else
//			{
//			    //titles[i].className="CurrentItem";
//				//currents[i].className = "current";
//				arrows[i].src = imgpath+"/dropup.gif";
//				submenus[i].style.display="block";
//				//submenus[i].style.height = 0;
//			}
//	    }
	}

	 
	if((showmenuid!=null)&&(showmenuid!=""))
	{
	        i = 0;
	        var menuidarray = showmenuidlist.split(',')
	        for(i = 0; i< menuidarray.length ;i++)
	        {
	           titles[menuidarray[i]-1].style.display = "block";
	           if(menuidarray[i]!=showmenuid)
	           {
	                submenus[menuidarray[i]-1].style.display = "none";
                    currents[menuidarray[i]-1].style.display = "block";
                    arrows[menuidarray[i]-1].src = imgpath+"/dropdown.gif";
                    submenusli[menuidarray[i]-1].style.display = "none";
               }
               else
               {
                    
                    submenus[menuidarray[i]-1].style.display = "block";
                    currents[menuidarray[i]-1].style.display = "block";
                    arrows[menuidarray[i]-1].src = imgpath+"/dropup.gif";
                    currents[menuidarray[i]-1].className = "current";
                    submenusli[menuidarray[i]-1].style.display = "block";
               }
          }
	}
	
	
    //if(remember)
	//			restore()
	//	else if (contractall_default) //DD added code
	//			slash_contractall() //DD added code

window_load();
document.getElementById('loadnavmenu').style.display="none";


}

function restore() {
    if(getcookie("menu") != null) {
        var hidden = getcookie("menu").split(",");
        for(var i in hidden) {
           
            titles[hidden[i]].className = "CurrentItem";
            submenus[hidden[i]].style.height = "0px";
            submenus[hidden[i]].style.display = "none";
            arrows[hidden[i]].src =imgpath+"/dropup.gif";
         }
    }
}

function gomenu(e) 
{
   
    if (!e)
        var e = window.event;
    var ce = (e.target) ? e.target : e.srcElement;
 
    var sm ;
  
    for(var i in currents) {
        if((arrows[i] == ce)||(currents[i] == ce.parentNode)||(currents[i] == ce.parentNode.parentNode)) 
            sm = i;
    }
   
    if(sm >=0)
    {
       if(parseInt(submenus[sm].style.height) > parseInt(heights[sm])) 
       {
          hidemenu(sm);
       }
       else
       {
          if(submenus[sm].style.display=="block")
          {
             hidemenu(sm);
          }
          else
          {
             //titles[sm].className = "CurrentItem";
             slash_contractall();
             currents[sm].className = "current";
             showmenu(sm);
          }
       }
   }
}

function hidemenu(sm) {
  
    var nr = submenus[sm].getElementsByTagName("a").length*bypixels+speed;
    submenus[sm].style.height = (parseInt(submenus[sm].style.height)-nr)+"px";
    
    var to = setTimeout("hidemenu("+sm+")", 5);
    //alert(nr);
    if(parseInt(submenus[sm].style.height) <= nr) {
        clearTimeout(to);
        submenus[sm].style.display = "none";
        submenus[sm].style.height = 0+"px";
        arrows[sm].src = imgpath+"/dropdown.gif";
        submenusli[sm].style.display = "none";
        currents[sm].className = "NoSelect";
    }
    
  
    
  
 
}

function showmenu(sm) {
   

    var nr = submenus[sm].getElementsByTagName("a").length*bypixels+speed;
    submenus[sm].style.display = "block";
    submenus[sm].style.height = (parseInt(submenus[sm].style.height)+nr)+"px";
    var to = setTimeout("showmenu("+sm+")", 5);
    if(parseInt(submenus[sm].style.height) > (parseInt(heights[sm])-nr)) {
        clearTimeout(to);
        submenus[sm].style.height = heights[sm]+"px";
        arrows[sm].src = imgpath+"/dropup.gif";
        submenusli[sm].style.display = "block";
        //titles[sm].className = "CurrentItem";
    }
        
        
}

function store() {
    var hidden = new Array();
    for(var i in titles) {
        if(titles[i].className == "CurrentItem")
            hidden.push(i);
    }
    putcookie("menu", hidden.join(","), 5);
}

function getElementsByClassName(strClassName, strTagName, oElm){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function getElements(strTagName, oElm){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    return arrElements;
}

function putcookie(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate);
}

function getcookie(c_name) {
    if(document.cookie.length > 0) {
        var c_start = document.cookie.indexOf(c_name + "=");
        if(c_start != -1) {
            c_start = c_start + c_name.length + 1;
            var c_end = document.cookie.indexOf(";",c_start);
            if(c_end == -1)
                c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return null;
}

