
function DropMenu1(id) {

    /* Type of the menu: "horizontal" or "vertical" */
    this.type = "horizontal";
    
    this.order="abc";
    this.firstout="false";
    this.secondover="false";
    this.secondout="false";
    this.thirdover = "false";
    this.thirdout="false";
    this.fourthover="false";
    this.fourthout="false";
    this.fifthover="false";
    this.fifthout="false";



    /* Delay (in miliseconds >= 0): show-hide menu */
    this.delay = {
        "show": 0,
        "hide": 30
    }
    /* Change the default position of sub-menu by Y pixels from top and X pixels from left
     * Negative values are allowed */
    this.position = {
        "top": 0,
        "left": 0
    }
    /* Z-index property for .section */
    this.zIndex = {
        "visible": 1,
        "hidden": -1
    };

    // Browser detection
    this.browser = {
        "ie": Boolean(document.body.currentStyle),
        "ie5": (navigator.appVersion.indexOf("MSIE 5.5") != -1 || navigator.appVersion.indexOf("MSIE 5.0") != -1),
        "ie6": (navigator.appVersion.indexOf("MSIE 6.5") != -1 || navigator.appVersion.indexOf("MSIE 6.0") != -1)
    };
    if (!this.browser.ie) { this.browser.ie5 = false; }

    /* Initialize the menu */
    this.init = function() {
        if (!document.getElementById(this.id)) { return alert("DropMenu1.init() failed. Element '"+ this.id +"' does not exist."); }
        if (this.type != "horizontal" && this.type != "vertical") { return alert("DropMenu1.init() failed. Unknown menu type: '"+this.type+"'"); }
        if (this.browser.ie && this.browser.ie5) { fixWrap(); }
        fixSections();
        parse(document.getElementById(this.id).childNodes, this.tree, this.id);
    }

    /* Search for .section elements and set width for them */
    function fixSections() {
        var arr = document.getElementById(self.id).getElementsByTagName("div");
        
        var sections = new Array();
        var widths = new Array();

		

        for (var i = 0; i < arr.length; i++) {
            if (arr[i].className == "section") {
                sections.push(arr[i]);
            }
        }
        for (var i = 0; i < sections.length; i++) {
            widths.push(getMaxWidth(sections[i].childNodes));
        }
        for (var i = 0; i < sections.length; i++) {
            sections[i].style.width = (widths[i]) + "px";
        }
        if (self.browser.ie) {
            for (var i = 0; i < sections.length; i++) {
                setMaxWidth(sections[i].childNodes, widths[i]);
            }
        }
    }

    function fixWrap() {
        var elements = document.getElementById(self.id).getElementsByTagName("a");
        for (var i = 0; i < elements.length; i++) {
            if (/subitem/.test(elements[i].className)) {
                elements[i].innerHTML = '<div nowrap="nowrap">'+elements[i].innerHTML+'</div>';
            }
        }
    }

    /* Search for an element with highest width among given nodes, return that width */
    function getMaxWidth(nodes) {
        var maxWidth = 0;
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType != 1) { continue; }
            if (nodes[i].offsetWidth > maxWidth) { maxWidth = nodes[i].offsetWidth; }
        }
        return maxWidth;
    }

    /* Set width for item2 elements */
    function setMaxWidth(nodes, maxWidth) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType == 1 && /subitem/.test(nodes[i].className) && nodes[i].currentStyle) {
                if (self.browser.ie5) {
                    nodes[i].style.width = (maxWidth) + "px";
                } else {
                    nodes[i].style.width = (maxWidth - parseInt(nodes[i].currentStyle.paddingLeft) - parseInt(nodes[i].currentStyle.paddingRight)) + "px";
                }
            }
        }
    }

    /* Parse nodes, create events, position elements */
    function parse(nodes, tree, id) {
        for (var i = 0; i < nodes.length; i++) {
            if (1 != nodes[i].nodeType) {
                continue;
            }           
            switch (true) {
                // .item1
                case /\bitem1\b/.test(nodes[i].className):
                    nodes[i].id = id + "-" + tree.length;
                   
                    tree.push(new Array());                                     
                    nodes[i].onmouseover = item1over;
                    nodes[i].onmouseout = item1out;
                    break;
               case /\bitem2\b/.test(nodes[i].className):
                    nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());  
                    nodes[i].onmouseover = item2over;
                    nodes[i].onmouseout = item1out;
                    break; 
               case /\bitem3\b/.test(nodes[i].className):
                    nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());  
                    nodes[i].onmouseover = item3over;
                    nodes[i].onmouseout = item1out;
                    break;
                case /\bitem4\b/.test(nodes[i].className):
                    nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());  
                    nodes[i].onmouseover = item4over;
                    nodes[i].onmouseout = item1out;
                    break;
               case /\bitem5\b/.test(nodes[i].className):
                    nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());  
                    nodes[i].onmouseover = item5over;
                    nodes[i].onmouseout = item1out;
                    break;
               case /\bitem6\b/.test(nodes[i].className):
                    nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());  
                    nodes[i].onmouseover = item6over;
                    nodes[i].onmouseout = item1out;
                    break;                            
                // .item2
                case /\bsubitem\b/.test(nodes[i].className):
                    nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());  
                    break;
                // .section
                case /\bsection\b/.test(nodes[i].className):
                    // id, events
                   
                    nodes[i].id = id + "-" + (tree.length - 1) + "-section";
                    nodes[i].onmouseover = sectionOver;
                    nodes[i].onmouseout = sectionOut;
                    // position
                    var box1 = document.getElementById(id + "-" + (tree.length - 1));
                    var box2 = document.getElementById(nodes[i].id);
                    
                    if ("horizontal" == self.type) {
                        box2.style.top = box1.offsetTop + box1.offsetHeight + self.position.top + "px";
                        if (self.browser.ie5) {
                            box2.style.left = self.position.left + "px";
                        } else {
                                                      
                          box2.style.left = box1.offsetLeft + self.position.left + "px";
                         	
                        }
                    } else if ("vertical" == self.type) {
                        box2.style.top = box1.offsetTop + self.position.top + "px";
                        if (self.browser.ie5) {
                            box2.style.left = box1.offsetWidth + self.position.left + "px";
                        } else {
                            box2.style.left = box1.offsetLeft + box1.offsetWidth + self.position.left + "px";
                        }
                    }
                    // sections, sectionsShowCnt, sectionsHideCnt
                    self.sections.push(nodes[i].id);
                    self.sectionsShowCnt.push(0);
                    self.sectionsHideCnt.push(0);
                    break;
            }
            if (nodes[i].childNodes) {
                if (/\bsection\b/.test(nodes[i].className)) {
                    parse(nodes[i].childNodes, tree[tree.length - 1], id + "-" + (tree.length - 1));
                } else {
                    parse(nodes[i].childNodes, tree, id);
                }
            }
        }
    }

    /* event, item1:onmouseover */
    function item1over() {
    	 //arraycheck();
        var id_section = this.id + "-section";
        
        if (getIfContainsArray(self.sections,id_section)) {
            self.sectionsHideCnt[getIndexOfarray(self.sections,id_section)]++;
            var cnt = self.sectionsShowCnt[getIndexOfarray(self.sections,id_section)];
            setTimeout(function(a, b)
            { 
            	return function()
            	{
            		 self.showSection(a, b); 
             		 if (self.browser.ie6)
             		 {        		
       					item1hideonmouseover();
       				 }
       			} 
       		} 
       		(id_section, cnt), self.delay.show);
        } else {
            if (self.visible) {
                var cnt = self.sectionsHideCnt[getIndexOfarray(self.sections,self.visible)];
                setTimeout(function(a, b) { return function() { self.hideSection(a, b); } } (self.visible, cnt), self.delay.show);
            }
        }
         	
    }
    
     /* event, item1:onmouseover */
    function item2over() {
    	
        var id_section = this.id + "-section";
        
       
       if (getIfContainsArray(self.sections,id_section)) {
            self.sectionsHideCnt[getIndexOfarray(self.sections,id_section)]++;
            var cnt = self.sectionsShowCnt[getIndexOfarray(self.sections,id_section)];
            setTimeout(function(a, b) 
            { 
            	return function() 
            	{ 
            		self.showSection(a, b); 
            		this.secondover = "true";
            		document.getElementById("dropdown_id1").style.visibility = "visible";
            		if (self.browser.ie6)
            		{
         				item2hideonmouseover();
         			}
            	} 
            } (id_section, cnt), self.delay.show);
        } else {
            if (self.visible) {
                 var cnt = self.sectionsHideCnt[getIndexOfarray(self.sections,self.visible)];
                setTimeout(function(a, b) { return function() { self.hideSection(a, b); } } (self.visible, cnt), self.delay.show);
            }
        }
         
       
    }
    
     /* event, item1:onmouseover */
    function item3over() {
    	
        var id_section = this.id + "-section";
        
       
        if (getIfContainsArray(self.sections,id_section)) {
            self.sectionsHideCnt[getIndexOfarray(self.sections,id_section)]++;
            var cnt = self.sectionsShowCnt[getIndexOfarray(self.sections,id_section)];
            setTimeout(function(a, b) 
            { 
            	return function() 
            	{ 
            		self.showSection(a, b); 
            		this.thirdover="true";
            		document.getElementById("dropdown_id2").style.visibility = "visible";
            		if (self.browser.ie6) {
	         			item3hideonmouseover();
       				 }       
            	} 
            } (id_section, cnt), self.delay.show);
        } else {
            if (self.visible) {
                 var cnt = self.sectionsHideCnt[getIndexOfarray(self.sections,self.visible)];
                setTimeout(function(a, b) { return function() { self.hideSection(a, b); } } (self.visible, cnt), self.delay.show);
            }
        }
        
    }
    
     /* event, item1:onmouseover */
    function item4over() {
    	
        var id_section = this.id + "-section";
       
    
        if (getIfContainsArray(self.sections,id_section)) {
            self.sectionsHideCnt[getIndexOfarray(self.sections,id_section)]++;
            var cnt = self.sectionsShowCnt[getIndexOfarray(self.sections,id_section)];
            setTimeout(function(a, b) 
            { 
            	return function() 
            	{ 
            		self.showSection(a, b);
            			this.fourthover = "true";
            		if (self.browser.ie6) {
	       				item4hideonmouseover();
	   				} 
            	} 
            } (id_section, cnt), self.delay.show);
        } else {
            if (self.visible) {
                var cnt = self.sectionsHideCnt[getIndexOfarray(self.sections,self.visible)];
                setTimeout(function(a, b) { return function() { self.hideSection(a, b); } } (self.visible, cnt), self.delay.show);
            }
        }
             
       
    }
    
     /* event, item1:onmouseover */
    function item5over() {
    	
        var id_section = this.id + "-section";

       if (getIfContainsArray(self.sections,id_section)) {
            self.sectionsHideCnt[getIndexOfarray(self.sections,id_section)]++;
            var cnt = self.sectionsShowCnt[getIndexOfarray(self.sections,id_section)];
            setTimeout(function(a, b) 
            { 
            	return function() 
            	{ 
            		self.showSection(a, b); 
            		document.getElementById("dropdown_id1").style.visibility = "visible";
            		this.fifthover="true";
            		if (self.browser.ie6) {
	       				item5hideonmouseover();
					} 
            	} 
            } (id_section, cnt), self.delay.show);
        } else {
            if (self.visible) {
                 var cnt = self.sectionsHideCnt[getIndexOfarray(self.sections,self.visible)];
                setTimeout(function(a, b) { return function() { self.hideSection(a, b); } } (self.visible, cnt), self.delay.show);
            }
        }
           
       
    }
    
     /* event, item1:onmouseover */
    function item6over() {
    	
        var id_section = this.id + "-section";
       
        if (getIfContainsArray(self.sections,id_section)) {
            self.sectionsHideCnt[getIndexOfarray(self.sections,id_section)]++;
            var cnt = self.sectionsShowCnt[getIndexOfarray(self.sections,id_section)];
            setTimeout(function(a, b) { return function() { 
            self.showSection(a, b); 
            document.getElementById("dropdown_id1").style.visibility = "visible";
            document.getElementById("dropdown_id2").style.visibility = "visible";
            } } (id_section, cnt), self.delay.show);
        } else {
            if (self.visible) {
                var cnt = self.sectionsHideCnt[getIndexOfarray(self.sections,self.visible)];
                setTimeout(function(a, b) { return function() { self.hideSection(a, b); } } (self.visible, cnt), self.delay.show);
            }
        }
       
    }
	/* Items to be hidden on mouseover of first menu */
	function item1hideonmouseover(){
			if(document.getElementById("WC_UserRegistrationAddForm_FormInput_personTitle_In_Register_1_1")!= null){       		
       			document.getElementById("WC_UserRegistrationAddForm_FormInput_personTitle_In_Register_1_1").style.visibility="hidden";
       		}
       		if(document.getElementById("addressId")!= null){       		
       			document.getElementById("addressId").style.visibility="hidden";
       		}
	}
	
	/* Items to be hidden on mouseover of second menu */
	function item2hideonmouseover(){
			if(document.getElementById("WC_UserRegistrationAddForm_FormInput_personTitle_In_Register_1_1")!= null){       		
       			document.getElementById("WC_UserRegistrationAddForm_FormInput_personTitle_In_Register_1_1").style.visibility="hidden";
       		}
			if(document.getElementById("pageSize_id2") != null){
         		document.getElementById("pageSize_id2").style.visibility="hidden";
         	}         	
         	if(document.getElementById("singleShipmentAddress") != null){
	         	document.getElementById("singleShipmentAddress").style.visibility="hidden"; 
         	}
         	if(document.getElementById("WC__ShoppingCartAddressEntryForm_FormInput_country_1") != null){
	         	document.getElementById("WC__ShoppingCartAddressEntryForm_FormInput_country_1").style.visibility="hidden"; 
         	}
         	
	}
	
	/* Items to be hidden on mouseover of third menu */
	function item3hideonmouseover(){
		document.getElementById("dropdown_id1").style.visibility="hidden";
		    
	}
	
		
	/* Items to be hidden on mouseover of fourth menu */
	function item4hideonmouseover(){
		 	document.getElementById("dropdown_id2").style.visibility="hidden";
	        document.getElementById("dropdown_id1").style.visibility="hidden";
	        if(document.getElementById("searchType") != null){
			    document.getElementById("searchType").style.visibility="hidden";
			    document.getElementById("filterType").style.visibility="hidden";
			    document.getElementById("catGroupId").style.visibility="hidden";	    
		        document.getElementById("searchTermScope_id1").style.visibility="hidden";  
		        
	        }   
	        if(document.getElementById("orderBy1_id1") != null){ 	       
		        document.getElementById("orderBy1_id1").style.visibility="hidden";
		    }
		}
	
	/* Items to be hidden on mouseover of fifth menu */
	function item5hideonmouseover(){	
	
 		document.getElementById("dropdown_id2").style.visibility="hidden";
 		if(document.getElementById("searchType") != null){     
		    document.getElementById("searchType").style.visibility="hidden";
		    document.getElementById("filterType").style.visibility="hidden";
		}
		if(document.getElementById("orderBy1_id1") != null){    
		    document.getElementById("orderBy1_id1").style.visibility="hidden";	
		}    
	}
	
	
    /* event, item1:onmouseout */
    function item1out() {
        var id_section = this.id + "-section";
       if(document.getElementById(this.id).className == "item2"){
        	this.secondout = "true";
        }
        if(document.getElementById(this.id).className == "item3"){
        	this.thirdout = "true";
        	document.getElementById("dropdown_id1").style.visibility = "visible";
        }
        if(document.getElementById(this.id).className == "item4"){
        	document.getElementById("dropdown_id1").style.visibility = "visible";
        	document.getElementById("dropdown_id2").style.visibility = "visible";
        }
        if(document.getElementById(this.id).className == "item5"){
        	document.getElementById("dropdown_id2").style.visibility = "visible";
        }
        
               
        if (getIfContainsArray(self.sections,id_section)) {
            self.sectionsShowCnt[getIndexOfarray(self.sections,id_section)]++;
            if (id_section == self.visible) {
                var cnt = self.sectionsHideCnt[getIndexOfarray(self.sections,id_section)];
                setTimeout(function(a, b) 
                { 
                	return function() 
                	{ 
                		self.hideSection(a, b); 
                		
                	} 
                }(id_section, cnt), self.delay.hide);
            }
        }
        
    }
    
   
    
   
    
    /* Display all the hidden dropdowns */
    function unhidealldropdowns(){
    		//if((document.getElementById(this.id) != null )&& (document.getElementById(this.id).className != "item4")) {
    		document.getElementById("dropdown_id1").style.visibility="visible";  
    	 	document.getElementById("dropdown_id2").style.visibility="visible";
    	 	//}
       		if(document.getElementById("searchType") != null){
			    document.getElementById("searchType").style.visibility="visible";
			    document.getElementById("filterType").style.visibility="visible";
			    document.getElementById("catGroupId").style.visibility="visible";	    
		        document.getElementById("searchTermScope_id1").style.visibility="visible";  
	        
        	}   
        	if(document.getElementById("orderBy1_id1") != null){ 	       
	        	document.getElementById("orderBy1_id1").style.visibility="visible";
	    	}
	        
	        if( document.getElementById("pageSize_id2") != null) {
		        document.getElementById("pageSize_id2").style.visibility="visible";
		        document.getElementById("orderBy1_id1").style.visibility="visible";
	        }
	        if( document.getElementById("WC_UserRegistrationAddForm_FormInput_personTitle_In_Register_1_1") != null) {
	        	document.getElementById("WC_UserRegistrationAddForm_FormInput_personTitle_In_Register_1_1").style.visibility="visible";
	        }
	        
         	if( document.getElementById("addressId") != null) {
	         	document.getElementById("addressId").style.visibility="visible";	         	      	
	        }
	       		        
	        if(document.getElementById("singleShipmentAddress") != null){
	        
	         	document.getElementById("singleShipmentAddress").style.visibility="visible";   
         	}
         	
         	if(document.getElementById("WC__ShoppingCartAddressEntryForm_FormInput_country_1") != null){
	         	document.getElementById("WC__ShoppingCartAddressEntryForm_FormInput_country_1").style.visibility="visible"; 
         	}         	
    
    }

    /* event, section:onmouseover */
    function sectionOver() {
        self.sectionsHideCnt[getIndexOfarray(self.sections,this.id)]++;
       var el = new Element(this.id);
        el = document.getElementById(el.getParent().id);
       if (self.browser.ie6) {
	       	if(el.className == "item2"){
	       		 item2hideonmouseover();
	       	}
	         if(el.className == "item3"){
	       		 item3hideonmouseover();
	       	} 
	       	if(el.className == "item4"){
	       		 item4hideonmouseover();
	       	} 
	       	if(el.className == "item5"){
	       		 item5hideonmouseover();
	       	} 
	       	if(el.className == "item1-active"){
	       		 item1hideonmouseover();
	       	} 
	       	
	    }   	
               
    }

    /* event, section:onmouseout */
    function sectionOut() {
        self.sectionsShowCnt[getIndexOfarray(self.sections,this.id)]++;
        var cnt = self.sectionsHideCnt[getIndexOfarray(self.sections,this.id)];
        setTimeout(function(a, b) { return function() { 
        self.hideSection(a, b); 
        
        } }(this.id, cnt), self.delay.hide);
        
        
    }

    /* Show section (1 argument passed)
     * Try to show section (2 arguments passed) - check cnt with sectionShowCnt */
    this.showSection = function(id, cnt) {
 
     	var el = new Element(id);
      	var parent = document.getElementById(el.getParent().id);
     
    	
    	
        if (typeof cnt != "undefined") {
            if (cnt != this.sectionsShowCnt[getIndexOfarray(this.sections,id)]) { return; }
        }
        this.sectionsShowCnt[getIndexOfarray(this.sections,id)]++;      
       
      	if (this.visible) {
            if (id == this.visible) { return; }
            this.hideSection(this.visible);
        }
        //document.getElementById(id).style.display = "block";
      
       
        document.getElementById(id).style.visibility = "visible";
        document.getElementById(id).style.zIndex = this.zIndex.visible;
        this.visible = id;
        
        
    }

    /* Hide section (1 argument passed)
     * Try to hide section (2 arguments passed) - check cnt with sectionHideCnt */
    this.hideSection = function(id, cnt) {
   
        if (typeof cnt != "undefined") {        
            if (cnt != this.sectionsHideCnt[getIndexOfarray(this.sections,id)]) { return; }
        }
       
       
        document.getElementById(id).style.zIndex = this.zIndex.hidden;
        document.getElementById(id).style.visibility = "hidden";
        if (self.browser.ie6) {
	 		 unhidealldropdowns();
        }
        //document.getElementById(id).style.display = "none";
        if (id == this.visible) { this.visible = ""; }
        else {
	        
            //throw "DropMenu1.hideSection('"+id+"', "+cnt+") failed, cannot hide element that is not visible";
            return;
        }
        this.sectionsHideCnt[getIndexOfarray(this.sections,id)]++;
        
        
    }

    /* Necessary when showing section that doesn't exist - hide currently visible section. See: item1over() */
    	this.hideSelf = function(cnt) {
        if (this.visible && cnt == this.sectionsHideCnt[getIndexOfarray(this.sections,this.visible)]) {
        
            this.hideSection(this.visible);
            
        }
    }

    /* Element (.section, .item2 etc) */
    function Element(id) {
        /* Get parent element */
        this.getParent = function() {
            var s = this.id.substr(this.menu.id.length);
            var a = s.split("-");
            a.pop();
            return new Element(this.menu.id + a.join("-"));
        }
        this.menu = self;
        this.id = id;
    }

    var self = this;
    this.id = id; /* menu id */
    this.tree = []; /* tree structure of menu */
    this.sections = []; /* all sections, required for timeout */
    this.sectionsShowCnt = [];
    this.sectionsHideCnt = [];
    this.visible = ""; /* visible section, ex. menu-0-section */
    
    function getIndexOfarray(selarray,item) {
    
    for(var i=0;i<selarray.length;i++)
    {
    
    	if ((typeof selarray[i] == typeof item) && (selarray[i] == item)) {
	              return i;
	    }
    
    }
    return -1;
    }
    
    
    function getIfContainsArray(selarray,item)
    {
    	for(var i=0;i<selarray.length;i++)
    {
    
    	 if (selarray[i] === item) {
	             return true;
	          }
	        }
	       return false;
    }
    

}


