// poprawić przełczanie dla stylów active
// poprawić pozycjonowanie poziome
// zrobić dodawanie kodu z funckji zdarzeń i modyfikacja funkcji, która to robi.
horizontalMenu=1; // czy menu jest horyzontalne
menuClickVersion=0; // czy menu działa w systemie klikania, a nie najeżdzania myszk
stopScriptPositioning=0; // czy skrypt ustawia pozycję czy style to robi.
nowrap=1; // czy teksty maj być niełamliwe (gdy długo?ć podmenu'ów jest nieustalona lepiej pozostawić na 1 lub, gdy menu jest pozycjonowane przez skrypt)

// poniższe dwa warunki s proste - domy?lnie zalecane jest nieusuwanie ich
if (horizontalMenu) {stopScriptPositioning=0}
if (stopScriptPositioning) {menuClickVersion=1}

/*
 * DO NOT REMOVE THIS NOTICE
 *
 * PROJECT:   mygosuMenu
 * VERSION:   1.1.6
 * COPYRIGHT: (c) 2003,2004 Cezary Tomczak
 * LINK:      http://gosu.pl/dhtml/mygosumenu.html
 * LICENSE:   BSD (revised)
 */

/*
  Todo, bugs to fix:
  - delay.show = 400 , delay.hide = 400
    go Product Three -> Live Demo -> Test Drive -> Test Three , go fast to Product Four.
    Result: 2 elements highlighted in the same section
  - delay.show = 0 , delay.hide = 400
    go Product Three -> Live Demo , section out , section over, seciont out.
    Result: Live Demo is not highlighted
  - active className changing, unnecessary blink
  - opera: hideSection() exceptions are throwed
*/
if (navigator.appName.indexOf("Explorer")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {explorer=1;} else {explorer=0;}

document.collectionToAdd=new Array();
document.actCollectionNr=0;
itr=new Array();
itr2=new Array();
function addSubMenu(beforeNodesM, actSubMenu, firstItem, specIter) {
			nodesM=beforeNodesM.childNodes
			for (itr[specIter]=0;itr[specIter]<nodesM.length;itr[specIter]++) {
					if ((nodesM[itr[specIter]].nodeName.indexOf("text")+'')==-1) {
										 spanAsLi=document.createElement('a')
										 linkM=nodesM[itr[specIter]].getElementsByTagName('a')[0];							
          					 sectionM=nodesM[itr[specIter]].getElementsByTagName('ul')[0];
										 for (i2=0;i2<nodesM[itr[specIter]].attributes.length;i2++) {
												if (nodesM[itr[specIter]].attributes[i2].value!="null"&&nodesM[itr[specIter]].attributes[i2].value!="") {
													 	 spanAsLi.setAttribute(nodesM[itr[specIter]].attributes[i2].name, (nodesM[itr[specIter]].attributes[i2].value)); 
												}
            				 } // uwaga techniczna - przepisywanie atrybutów różnych znaczników (IE szczególnie)
										 
										 if (spanAsLi.getAttribute('disabled')) {spanAsLi.removeAttribute('disabled')}
      							 spanAsLi.style.display="block"
										 
										 
	    							 if (firstItem) {thisItem=1;} else {thisItem=2;}
										 
										 spanAsLi.className="item" + thisItem+" "+(nodesM[itr[specIter]].attributes['class']?nodesM[itr[specIter]].attributes['class'].value:'');
										 
										 spanAsLi.setAttribute('href',linkM.getAttribute('href'))
										 if (spanAsLi.getAttribute("href")=="#"||spanAsLi.className.indexOf("unLink")!=-1) {spanAsLi.setAttribute('href','javascript:void(0)')}
										 
										 
										 
										 if (horizontalMenu&&firstItem) {
										 spanAsLi.setAttribute('style',spanAsLi.getAttribute('style')+';float:left;')
										 if (explorer&&spanAsLi.runtimeStyle) {spanAsLi.runtimeStyle.cssText=spanAsLi.getAttribute('style')+";float:left"}
										 }
										 
										 if (linkM) {
      										 obL=document.createElement('span')
      										 for (i2=0;i2<linkM.attributes.length;i2++) {
															if (!linkM.attributes[i2].value!="null"&&linkM.attributes[i2].value!="") {obL.setAttribute(linkM.attributes[i2].name, (linkM.attributes[i2].value))}
													 }
      										 
													 if (obL.getAttribute('disabled')!="true") {obL.removeAttribute('disabled')}
													 obL.removeAttribute('href')
													 
													 obL.innerHTML=linkM.innerHTML 												 
      										 spanAsLi.appendChild(obL)
      										 actSubMenu.appendChild(spanAsLi)		 
													 obL.style.display="block"
													 
										 }			

      							 if (sectionM) {
												obD=document.createElement('div')
												for (i2=0;i2<sectionM.attributes.length;i2++) {
      											if (sectionM.attributes[i2].value!="null"&&sectionM.attributes[i2].value!="") obD.setAttribute(sectionM.attributes[i2].name, (sectionM.attributes[i2].value))
            						} //przepisanie atrybutów z ul do div
              			    
      									if (!stopScriptPositioning) {
												obD.style.position="absolute";
												} else {obD.style.display="none"}
												
												obD.style.visibility="hidden";
												obD.style.zIndex=-1;
												//if (explorer) obD.style.zoom=1 //usuwa to błd wy?wietlania w IE6

												obD.className="section"+" "+(sectionM.attributes['class']?sectionM.attributes['class'].value:''); 
      									actSubMenu.appendChild(obD) 
												
												if (sectionM.childNodes) {
													document.collectionToAdd[document.actCollectionNr]=new Array();
  												document.collectionToAdd[document.actCollectionNr][0]=sectionM
  												document.collectionToAdd[document.actCollectionNr++][1]=obD
  												document.incrNodesMa++;
      									}  
												if (obD.getAttribute('disabled')!="true") {obD.removeAttribute('disabled')}
										 } 
      							 
      	  }				 
			}

for (itr2[specIter]=0;itr2[specIter]<document.collectionToAdd.length;itr2[specIter]++) {
		
		if (!document.collectionToAdd[itr2[specIter]][2]||document.collectionToAdd[itr2[specIter]][2]!="done") {
    		document.collectionToAdd[itr2[specIter]][2]="done"
    		addSubMenu(document.collectionToAdd[itr2[specIter]][0],document.collectionToAdd[itr2[specIter]][1], 0, ++specIter)		
		} 
}

//addSubMenu(sectionM, obD)
return actSubMenu.innerHTML
}
document.zminnerr=''

intervalVar1=0;

adase=0

function getTrueProperty(element, property) {
return explorer?element.currentStyle[property]:(document.defaultView?document.defaultView.getComputedStyle(element, null).getPropertyValue(property):"");
}

function liOrDivToMenu() {
	if (document&&document.getElementById('cssMenu')&&document.getElementById('cssMenu').nextSibling) {clearInterval(intervalV1);} else {return}
//	if (!document||!document.getElementById('cssMenu')&&!document.getElementById('cssMenu').nextSibling) {return} else {clearInterval(intervalV1);}
	objMenu=document.getElementById('cssMenu');
  cont=document.createElement('div');
	if (explorer) zoomIE=""; else {zoomIE=""} 
	cont.innerHTML="<table width='auto' cellspacing='0' cellpadding='0' id='menu1' style='width: auto;' class='ddmx cssMenu'><tbody><tr><td><div id='specialDivHorizontal' style='"+zoomIE+"'></div></td></tr></tbody></table>"
	tx=".childNodes[0]"
	eval('mTD=cont'+tx+tx+tx+tx+tx); 
	
	if (objMenu.childNodes) {
  	 addSubMenu(objMenu,mTD, 1,0);
	}

	objMenu.style.display="none"
  linksTD=objMenu.getElementsByTagName('a')
		
	objMenu.parentNode.insertBefore(cont,objMenu)
	var ddmx = new DropDownMenuX('menu1');
  if (horizontalMenu) {ddmx.type = "horizontal";} else {ddmx.type = "vertical";}
  ddmx.delay.show = 0;
  ddmx.delay.hide = 400;
  ddmx.position.levelX.left = 0;
	ddmx.init();
	
	if (explorer&&!stopScriptPositioning) {
    	menuO4k=document.getElementById(ddmx.id).getElementsByTagName('a')
    	menu04array=new Array();
    	for (i=0;i<menuO4k.length;i++) {
        	if (menuO4k[i].className.indexOf('item2')!=-1) {
        		 menu04array[i]=menuO4k[i].offsetWidth
        	}
    	}
    
    	for (i=0;i<menuO4k.length;i++) {
        	if (menuO4k[i].className.indexOf('item2')!=-1) {
          	menuO4k[i].style.width="2000px";
      			menuO4k[i].style.width=menu04array[i]-(menuO4k[i].offsetWidth-2000)+'px';
        	}
    	}
    


    	menuO4k=document.getElementById(ddmx.id).getElementsByTagName('div')
    	for (i=0;i<menuO4k.length;i++) {
        	if (menuO4k[i].className.indexOf('section')!=-1) {
          	menuO4k[i].style.display="block";
          	menuO4k[i].style.display="none";
        	}
    	}
	
	
	}
	
}

// +----------------------------------------------------------------+
// | Array functions that are missing in IE 5.0                     |
// | Author: Cezary Tomczak [www.gosu.pl]                           |
// | Free for any use as long as all copyright messages are intact. |
// +----------------------------------------------------------------+

// Removes the last element from an array and returns that element.
if (!Array.prototype.pop) {
    Array.prototype.pop = function() {
        var last;
        if (this.length) {
            last = this[this.length - 1];
            this.length -= 1;
        }
        return last;
    };
}

// Adds one or more elements to the end of an array and returns the new length of the array.
if (!Array.prototype.push) {
    Array.prototype.push = function() {
        for (var i = 0; i < arguments.length; ++i) {
            this[this.length] = arguments[i];
        }
        return this.length;
    };
}

// Removes the first element from an array and returns that element.
if (!Array.prototype.shift) {
    Array.prototype.shift = function() {
        var first;
        if (this.length) {
            first = this[0];
            for (var i = 0; i < this.length - 1; ++i) {
                this[i] = this[i + 1];
            }
            this.length -= 1;
        }
        return first;
    };
}

// Adds one or more elements to the front of an array and returns the new length of the array.
if (!Array.prototype.unshift) {
    Array.prototype.unshift = function() {
        if (arguments.length) {
            var i, len = arguments.length;
            for (i = this.length + len - 1; i >= len; --i) {
                this[i] = this[i - len];
            }
            for (i = 0; i < len; ++i) {
                this[i] = arguments[i];
            }
        }
        return this.length;
    };
}

// Adds and/or removes elements from an array.
if (!Array.prototype.splice) {
    Array.prototype.splice = function(index, howMany) {
        var elements = [], removed = [], i;
        for (i = 2; i < arguments.length; ++i) {
            elements.push(arguments[i]);
        }
        for (i = index; (i < index + howMany) && (i < this.length); ++i) {
            removed.push(this[i]);
        }
        for (i = index + howMany; i < this.length; ++i) {
            this[i - howMany] = this[i];
        }
        this.length -= removed.length;
        for (i = this.length + elements.length - 1; i >= index + elements.length; --i) {
            this[i] = this[i - elements.length];
        }
        for (i = 0; i < elements.length; ++i) {
            this[index + i] = elements[i];
        }
        return removed;
    };
}

function DropDownMenuX(id) {

    /* Type of the menu: "horizontal" or "vertical" */
    if (horizontalMenu) {this.type = "horizontal";} else {this.type = "vertical";}

    /* Delay (in miliseconds >= 0): show-hide menu
     * Hide must be > 0 */
    if (menuClickVersion) {
    		this.delay = {
            "show": 0,
            "hide": 0
        }
		} else {
    		this.delay = {
            "show": 0,
            "hide": 400
        }
		}

    /* Change the default position of sub-menu by Y pixels from top and X pixels from left
     * Negative values are allowed */
    this.position = {
        "level1": { "top": 0, "left": 0},
        "levelX": { "top": 0, "left": 0}
    }

    /* fix ie selectbox bug ? */
    this.fixIeSelectBoxBug = true;

    /* Z-index property for .section */
    this.zIndex = {
        "visible": 500,
        "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.0") != -1||navigator.appVersion.indexOf("MSIE 7") != -1),
    		"ie7": (navigator.appVersion.indexOf("MSIE 7") != -1)
		};
    
    if (!this.browser.ie) {
        this.browser.ie5 = false;
        this.browser.ie6 = false;
    }

    /* Initialize the menu */
    this.init = function() {
        if (!document.getElementById(this.id)) { return alert("DropDownMenuX.init() failed. Element '"+ this.id +"' does not exist."); }
        if (this.type != "horizontal" && this.type != "vertical") { return alert("DropDownMenuX.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 (/item2/.test(elements[i].className)) {
                elements[i].innerHTML = '<div>'+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 || /section/.test(nodes[i].className)) { 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 && /item2/.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";
                }
            }
        }
    }

		function blurItem() {
			this.blur()			 
		}
		
		document.theHighestItem1=0;
    /* 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());
										if (menuClickVersion) {
											nodes[i].onclick = itemOver
										}	else {
  										nodes[i].onmouseover = itemOver;
                      nodes[i].onmouseout = itemOut;
										}									
											nodes[i].onfocus = blurItem
										if (nowrap) {
											 nodes[i].style.whiteSpace="nowrap"
										}
										nodes[i].style.display="block"
										nodes[i].style.position="relative"
										
										
										break;
                // .item2
                case /\bitem2\b/.test(nodes[i].className):
										nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());
										
										if (menuClickVersion) {
											nodes[i].onclick = itemOver

											if (nodes[i].parentNode.previousSibling&&nodes[i].parentNode.previousSibling.nodeName=="A") {
													nodes[i].parentNode.previousSibling.setAttribute('href', 'javascript: void(0)')
											} else if (nodes[i].parentNode.previousSibling.previousSibling&&nodes[i].parentNode.previousSibling.previousSibling.nodeName=="A") {
													nodes[i].parentNode.previousSibling.previousSibling.setAttribute('href', 'javascript: void(0)')
											} 
											

										}	else {
  										nodes[i].onmouseover = itemOver;
                      nodes[i].onmouseout = itemOut;
										}									
											nodes[i].onfocus = blurItem

										if (nowrap) {
											nodes[i].style.whiteSpace="nowrap"
										}

										nodes[i].style.display="block"
										nodes[i].style.position="relative"
										nodes[i].style.zIndex=500;
										
										break;
                // .section
                case /\bsection\b/.test(nodes[i].className):
                    // id, events
                    nodes[i].id = id + "-" + (tree.length - 1) + "-section";
										if (menuClickVersion) {
											nodes[i].onclick = sectionOver
										}	else {
  										nodes[i].onmouseover = sectionOver;
                      nodes[i].onmouseout = sectionOut;
										}
										nodes[i].onfocus = blurItem
									
                    // position
										var box1 = document.getElementById(id + "-" + (tree.length - 1));
										var box2 = document.getElementById(nodes[i].id);
          				  var el = new Element(box1.id);

										
										//if (explorer) {box2.style.zoom="1";alert(box2.style.pixelWidth)}
    								if (!stopScriptPositioning) {
												if (1 == el.level) {
    											  if ("horizontal" == self.type) {
                                box2.style.top = box1.offsetTop + box1.offsetHeight + self.position.level1.top + "px";
                                if (self.browser.ie5) {
                                    box2.style.left = self.position.level1.left + "px";
                                } else {
                                    box2.style.left = box1.offsetLeft + self.position.level1.left + "px";
                                }
														} else if ("vertical" == self.type) {
                                box2.style.top = box1.offsetTop + self.position.level1.top+ "px";
                                if (self.browser.ie5) {
                                    box2.style.left = box1.offsetWidth + self.position.level1.left + "px";
                                } else {
                                    box2.style.left = box1.offsetLeft + box1.offsetWidth + self.position.level1.left + "px";
                                }
                            }
                        
    										} else {
    												if (navigator.appVersion.indexOf("MSIE 7") != -1) {
    													 box1.style.width="auto"
    												}
    
    												box2.style.top = box1.offsetTop + self.position.levelX.top+ "px";
                            box2.style.left = box1.offsetLeft+ box1.offsetWidth + self.position.levelX.left + "px";
    										}
                   }	
										// sections, sectionsShowCnt, sectionsHideCnt
                    self.sections.push(nodes[i].id);
                    self.sectionsShowCnt.push(0);
                    self.sectionsHideCnt.push(0);
                    if (!stopScriptPositioning&&self.fixIeSelectBoxBug && self.browser.ie6) {
                        nodes[i].innerHTML = nodes[i].innerHTML + '<iframe id="'+nodes[i].id+'-iframe" src="javascript:false;" scrolling="no" frameborder="0" style="position: absolute; top: 0px; left: 0px; display: none; filter:alpha(opacity=0);"></iframe>';
                    }
                    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, item:onmouseover */
    function itemOver() {
  		if (menuClickVersion) {
    			if (!this.parentNode) return
    					if (this.nextSibling&&this.nextSibling.nodeName=="DIV") {
    					   itemObjV=this.nextSibling
    				} else {
      					 if (this.nextSibling&&this.nextSibling.nextSibling&&this.nextSibling.nodeName!="A"&&this.nextSibling.nextSibling.nodeName=="DIV") {
      					 		itemObjV=this.nextSibling.nextSibling;
      					 } else {
      					 	 	itemObjV=null
      					 }
    				} 
    
    				if (itemObjV&&getTrueProperty(itemObjV, "visibility")=="visible") {
    					 itemObjV.style.visibility="hidden";
    					 itemObjV.style.display="none"
							 if (menuClickVersion) {
  							  if (/item\d-active/.test(this.className)) {
      								this.className = this.className.replace(/(item\d)-active/, "$1");
      								if (this.className.indexOf('specialseparator624')!=-1) this.className=this.className.substring(0,(this.className.indexOf('specialseparator624')-1))
  								}
							 }
							 
    					 sections=itemObjV.getElementsByTagName('div')
    					 for (itm=0;itm<sections.length;itm++) {
    							if (sections[itm].className.indexOf('section')!=-1) {sections[itm].style.visibility="hidden"}
    					 }
    					 return
    				} else {
    					 itemOver(null, this)
    					 if (menuClickVersion) {
  							 if (!/item\d-active/.test(this.className)) {
  				    	 		this.className = this.className.replace(/(item\d)/, "$1-active")+activeClasses(this);
  							    this.blockOnce=1
								 } else this.blockOnce=0;
								 
							 }
							 if (itemObjV) {
    					 sections=itemObjV.getElementsByTagName('div')
    					 itemObjV.style.visibility="visible"
    					 itemObjV.style.display="block"
    					 for (itm=0;itm<sections.length;itm++) {
    					 		if (sections[itm].className.indexOf('section')!=-1) {sections[itm].style.visibility="hidden"}
    					 }
    					 }
    				}
  			}	
				//debug("itemOver("+this.id+") , visible = " + self.visible);
        self.itemShowCnt++;
        var id_section = this.id + "-section";
        if (self.visible.length&&!this.blockOnce) {
            
						var el = new Element(self.visible.getLast());
            el = document.getElementById(el.getParent().id);
            if (/item\d-active/.test(el.className)) {
								el.className = el.className.replace(/(item\d)-active/, "$1");
								if (el.className.indexOf('specialseparator624')!=-1) el.className=el.className.substring(0,(el.className.indexOf('specialseparator624')-1))
						}
        }
        if (self.sections.contains(id_section)) {
            clearTimers();
            self.sectionsHideCnt[self.sections.indexOf(id_section)]++;
            var cnt = self.sectionsShowCnt[self.sections.indexOf(id_section)];
            var timerId = setTimeout(function(a, b) { return function() { self.showSection(a, b); } } (id_section, cnt), self.delay.show);
            self.timers.push(timerId);
        } else {
            if (self.visible.length) {
                clearTimers();
                var timerId = setTimeout(function(a, b) { return function() { self.showItem(a, b); } } (this.id, self.itemShowCnt), self.delay.show);
                self.timers.push(timerId);
            }
        }
    }

    /* event, item:onmouseout */
    function itemOut() {
				//debug("itemOut("+this.id+") , visible = " + self.visible);
        self.itemShowCnt++;
        var id_section = this.id + "-section";
        if (self.sections.contains(id_section)) {
            self.sectionsShowCnt[self.sections.indexOf(id_section)]++;
            if (self.visible.contains(id_section)) {
                var cnt = self.sectionsHideCnt[self.sections.indexOf(id_section)];
                var timerId = setTimeout(function(a, b) { return function() { self.hideSection(a, b); } }(id_section, cnt), self.delay.hide);
                self.timers.push(timerId);
            }
        }
    }

    /* event, section:onmouseover */

		function activeClasses(objectWithCl) {
  		firstClasses = objectWithCl.className.split(" ");
  		newClassName=' specialseparator624 '
  		for (te=1;te<firstClasses.length;te++) {
    		if (te==(firstClasses.length-1)) additionalSpace=""; else {additionalSpace=" "}
    		newClassName+=firstClasses[te]+"-active"+additionalSpace;
  		}
		  return newClassName;
		}
		
    function sectionOver() {
				//debug("sectionOver("+this.id+") , visible = " + self.visible);
        self.sectionsHideCnt[self.sections.indexOf(this.id)]++;
        var el = new Element(this.id);
        var parent = document.getElementById(el.getParent().id);
        if (!/item\d-active/.test(parent.className)) {
				    parent.className = parent.className.replace(/(item\d)/, "$1-active")+activeClasses(parent);
				}
		}

    /* event, section:onmouseout */
    function sectionOut() {
        //debug("sectionOut("+this.id+") , visible = " + self.visible);
        self.sectionsShowCnt[self.sections.indexOf(this.id)]++;
        var cnt = self.sectionsHideCnt[self.sections.indexOf(this.id)];
        var timerId = setTimeout(function(a, b) { return function() { self.hideSection(a, b); } }(this.id, cnt), self.delay.hide);
        self.timers.push(timerId);
		}

    /* Show section (1 argument passed)
     * Try to show section (2 arguments passed) - check cnt with sectionShowCnt */
    this.showSection = function(id, cnt) {
				if (typeof cnt != "undefined") {
            if (cnt != this.sectionsShowCnt[this.sections.indexOf(id)]) { return; }
        }
        //debug("showSection("+id+", "+cnt+") , visible = " + this.visible);
        this.sectionsShowCnt[this.sections.indexOf(id)]++;
        if (this.visible.length) {
            if (id == this.visible.getLast()) { return; }
            var el = new Element(id);
            var parents = el.getParentSections();
            //debug("getParentSections("+el.id+") = " + parents);
            for (var i = this.visible.length - 1; i >= 0; i--) {
                if (parents.contains(this.visible[i])) {
                    break;
                } else {
                    this.hideSection(this.visible[i]);
                }
            }
        }
        var el = new Element(id);
				var parent = document.getElementById(el.getParent().id);
        if (!/item\d-active/.test(parent.className)) {
            parent.className = parent.className.replace(/(item\d)/, "$1-active")+activeClasses(parent);
				}
        if (document.all) { document.getElementById(id).style.display = "block"; }
        document.getElementById(id).style.visibility = "visible";
        document.getElementById(id).style.display = "block";
        document.getElementById(id).style.zIndex = this.zIndex.visible;
        if (!stopScriptPositioning&&this.fixIeSelectBoxBug && this.browser.ie6) {
            var div = document.getElementById(id);
            var iframe = document.getElementById(id+"-iframe");
            
						if (isNaN(div.currentStyle.borderLeftWidth)) {borL=0;} else {borL=div.currentStyle.borderLeftWidth}
						if (isNaN(div.currentStyle.borderRightWidth)) {borR=0;} else {borR=div.currentStyle.borderRightWidth}
						if (isNaN(div.currentStyle.borderTopWidth)) {borT=0;} else {borT=div.currentStyle.borderTopWidth}
						if (isNaN(div.currentStyle.borderBottomWidth)) {borB=0;} else {borB=div.currentStyle.borderBottomWidth}
						
						iframe.style.width = div.offsetWidth + parseInt(borL) + parseInt(borR);
            iframe.style.height = div.offsetHeight + parseInt(borT) + parseInt(borB);
            iframe.style.top = -parseInt(borT);
            iframe.style.left = -parseInt(borL);
            iframe.style.zIndex = div.style.zIndex - 1;
            iframe.style.display = "block";
        }
        this.visible.push(id);
    }

    /* Emulating an empty non-existent section, we have to hide elements, works like showSection() */
    this.showItem = function(id, cnt) {
        if (typeof cnt != "undefined") {
            if (cnt != this.itemShowCnt) { return; }
        }
        this.itemShowCnt++;
        if (this.visible.length) {
            var el = new Element(id + "-section");
            var parents = el.getParentSections();
            //debug("showItem() getParentSections("+el.id+") = " + parents);
            for (var i = this.visible.length - 1; i >= 0; i--) {
                if (parents.contains(this.visible[i])) {
                    break;
                } else {
                    this.hideSection(this.visible[i]);
                }
            }
        }
    }

    /* 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[this.sections.indexOf(id)]) { return; }
            if (id == this.visible.getLast()) {
                //debug("hideSectionAll("+id+", "+cnt+") , visible = " + this.visible);
                for (var i = this.visible.length - 1; i >= 0; i--) {
                    this.hideSection(this.visible[i]);
                }
                return;
            }
        
				}
				//debug("hideSection("+id+", "+cnt+") , visible = " + this.visible);
        var el = new Element(id);
        var parent = document.getElementById(el.getParent().id);
        if (/item\d-active/.test(parent.className)) {
            parent.className = parent.className.replace(/(item\d)-active/, "$1");
						if (parent.className.indexOf('specialseparator624')!=-1) parent.className=parent.className.substring(0,(parent.className.indexOf('specialseparator624')-1))
        }
        document.getElementById(id).style.zIndex = this.zIndex.hidden;
        document.getElementById(id).style.visibility = "hidden";
        document.getElementById(id).style.display = "none";
        if (document.all) { document.getElementById(id).style.display = "none"; }
        if (!stopScriptPositioning&&this.fixIeSelectBoxBug && this.browser.ie6) {
            var iframe = document.getElementById(id+"-iframe");
            iframe.style.display = "none";
        }
        if (this.visible.contains(id)) {
            if (id == this.visible.getLast()) {
                this.visible.pop();
            } else {
                //throw "DropDownMenuX.hideSection('"+id+"', "+cnt+") failed, trying to hide a section that is not the deepest visible section";
                return;
            }
        } else {
            //throw "DropDownMenuX.hideSection('"+id+"', "+cnt+") failed, cannot hide element that is not visible";
            return;
        }
        this.sectionsHideCnt[this.sections.indexOf(id)]++;
    }

    /* Element (.section, .item2 etc) */
    function Element(id) {
				this.menu = self;
        this.id = id;
        /* Get Level of given id
         * Examples: menu-1 (1 level), menu-1-4 (2 level) */
        this.getLevel = function() {
            var s = this.id.substr(this.menu.id.length);
            return s.substrCount("-");
        }

        /* 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("-"));
        }

        /* Check whether an element has a parent element */
        this.hasParent = function() {
            var s = this.id.substr(this.menu.id.length);
            var a = s.split("-");
            return a.length > 2;
        }

        /* Check whether an element has a sub-section */
        this.hasChilds = function() {
            return Boolean(document.getElementById(this.id + "-section"));
        }

        /* Get parent section elements for current section */
        this.getParentSections = function() {
            var s = this.id.substr(this.menu.id.length);
            s = s.substr(0, s.length - "-section".length);
            var a = s.split("-");
            a.shift();
            a.pop();
            var s = this.menu.id;
            var parents = [];
            for (var i = 0; i < a.length; i++) {
                s += ("-" + a[i]);
                parents.push(s + "-section");
            }
            return parents;
        }
        
        this.level = this.getLevel();
    }

    /* Clear all timers set with setTimeout() */
    function clearTimers() {
        for (var i = self.timers.length - 1; i >= 0; i--) {
            clearTimeout(self.timers[i]);
            self.timers.pop();
        }
    }

    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.itemShowCnt = 0;
    this.timers = []; // timeout ids
    this.visible = []; /* visible section, ex. Array("menu-0-section", ..) , succession is important: top to bottom */
}

/* Finds the index of the first occurence of item in the array, or -1 if not found */
if (typeof Array.prototype.indexOf == "undefined") {
    Array.prototype.indexOf = function(item) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === item) {
                return i;
            }
        }
        return -1;
    }
}

/* Check whether array contains given string */
if (typeof Array.prototype.contains == "undefined") {
    Array.prototype.contains = function(s) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === s) {
                return true;
            }
        }
        return false;
    }
}

/* Counts the number of substring occurrences */
if (typeof String.prototype.substrCount == "undefined") {
    String.prototype.substrCount = function(s) {
        return this.split(s).length - 1;
    }
}

/* Get the last element from the array */
if (typeof Array.prototype.getLast == "undefined") {
    Array.prototype.getLast = function() {
        return this[this.length-1];
    }
}


intervalV1=setInterval("liOrDivToMenu()",100)

