
function BarMenu(id){this.box1Hover=true;this.box2Hover=true;this.highlightActive=false;this.init=function(){if(!document.getElementById(this.id)){alert("Element '"+this.id+"' does not exist in this document. BarMenu cannot be initialized");return;}
this.parse(document.getElementById(this.id).childNodes,this.tree,this.id);this.load();if(window.attachEvent){window.attachEvent("onunload",function(e){self.save();});}else if(window.addEventListener){window.addEventListener("unload",function(e){self.save();},false);}}
this.parse=function(nodes,tree,id){for(var i=0;i<nodes.length;i++){if(nodes[i].nodeType!=1){continue;}
if(nodes[i].className){if("box1"==nodes[i].className.substr(0,4)){nodes[i].id=id+"-"+tree.length;tree[tree.length]=new Array();eval('nodes[i].onmouseover = function() { self.box1over("'+nodes[i].id+'"); }');eval('nodes[i].onmouseout = function() { self.box1out("'+nodes[i].id+'"); }');eval('nodes[i].onclick = function() { self.box1click("'+nodes[i].id+'"); }');}
if("section"==nodes[i].className){id=id+"-"+(tree.length-1);nodes[i].id=id+"-section";tree=tree[tree.length-1];}
if("box2"==nodes[i].className.substr(0,4)){nodes[i].id=id+"-"+tree.length;tree[tree.length]=new Array();eval('nodes[i].onmouseover = function() { self.box2over("'+nodes[i].id+'", "'+nodes[i].className+'"); }');eval('nodes[i].onmouseout = function() { self.box2out("'+nodes[i].id+'", "'+nodes[i].className+'"); }');}}
if(this.highlightActive&&nodes[i].tagName&&nodes[i].tagName=="A"){if(document.location.href==nodes[i].href){nodes[i].className=(nodes[i].className?' active':'active')}}
if(nodes[i].childNodes){this.parse(nodes[i].childNodes,tree,id);}}}
this.box1over=function(id){if(!this.box1Hover)return;if(!document.getElementById(id))return;document.getElementById(id).className=(this.id_openbox==id?"box1-open-hover":"box1-hover");}
this.box1out=function(id){if(!this.box1Hover)return;if(!document.getElementById(id))return;document.getElementById(id).className=(this.id_openbox==id?"box1-open":"box1");}
this.box1click=function(id){if(!document.getElementById(id)){return;}
var id_openbox=this.id_openbox;if(this.id_openbox){if(!document.getElementById(id+"-section")){return;}
this.hide();if(id_openbox==id){if(this.box1hover){document.getElementById(id_openbox).className="box1-hover";}else{document.getElementById(id_openbox).className="box1";}}else{document.getElementById(id_openbox).className="box1";}}
if(id_openbox!=id){this.show(id);var className=document.getElementById(id).className;if("box1-hover"==className){document.getElementById(id).className="box1-open-hover";}
if("box1"==className){document.getElementById(id).className="box1-open";}}}
this.box2over=function(id,className){if(!this.box2Hover)return;if(!document.getElementById(id))return;document.getElementById(id).className=className+"-hover";}
this.box2out=function(id,className){if(!this.box2Hover)return;if(!document.getElementById(id))return;document.getElementById(id).className=className;}
this.show=function(id){if(document.getElementById(id+"-section")){document.getElementById(id+"-section").style.display="block";this.id_openbox=id;}}
this.hide=function(){document.getElementById(this.id_openbox+"-section").style.display="none";this.id_openbox="";}
this.save=function(){if(this.id_openbox){this.cookie.set(this.id,this.id_openbox);}else{this.cookie.del(this.id);}}
this.load=function(){var id_openbox=this.cookie.get(this.id);if(id_openbox){this.show(id_openbox);document.getElementById(id_openbox).className="box1-open";}}
function Cookie(){this.get=function(name){var cookies=document.cookie.split(";");for(var i=0;i<cookies.length;i++){var a=cookies[i].split("=");if(a.length==2){a[0]=a[0].trim();a[1]=a[1].trim();if(a[0]==name){return unescape(a[1]);}}}
return"";}
this.set=function(name,value){document.cookie=name+"="+escape(value);}
this.del=function(name){document.cookie=name+"=; expires=Thu, 01-Jan-70 00:00:01 GMT";}}
var self=this;this.id=id;this.tree=new Array();this.cookie=new Cookie();this.id_openbox="";}
if(typeof String.prototype.trim=="undefined"){String.prototype.trim=function(){var s=this.replace(/^\s*/,"");return s.replace(/\s*$/,"");}}
function DropMenu1(id){this.type="horizontal";this.delay={"show":0,"hide":300}
this.position={"top":0,"left":0}
this.zIndex={"visible":1,"hidden":-1};this.browser={"ie":Boolean(document.body.currentStyle),"ie5":(navigator.appVersion.indexOf("MSIE 5.5")!=-1||navigator.appVersion.indexOf("MSIE 5.0")!=-1)};if(!this.browser.ie){this.browser.ie5=false;}
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);}
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 nowrap="nowrap">'+elements[i].innerHTML+'</div>';}}}
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;}
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 parse(nodes,tree,id){for(var i=0;i<nodes.length;i++){if(1!=nodes[i].nodeType){continue;}
switch(true){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());break;case/\bsection\b/.test(nodes[i].className):nodes[i].id=id+"-"+(tree.length-1)+"-section";nodes[i].onmouseover=sectionOver;nodes[i].onmouseout=sectionOut;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";}}
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);}}}}
function item1over(){var id_section=this.id+"-section";if(self.visible){var el=new Element(self.visible);el=document.getElementById(el.getParent().id);if(/item1-active/.test(el.className)){el.className=el.className.replace(/item1-active/,"item1");}}
if(self.sections.contains(id_section)){self.sectionsHideCnt[self.sections.indexOf(id_section)]++;var cnt=self.sectionsShowCnt[self.sections.indexOf(id_section)];setTimeout(function(a,b){return function(){self.showSection(a,b);}}(id_section,cnt),self.delay.show);}else{if(self.visible){var cnt=self.sectionsHideCnt[self.sections.indexOf(self.visible)];setTimeout(function(a,b){return function(){self.hideSection(a,b);}}(self.visible,cnt),self.delay.show);}}}
function item1out(){var id_section=this.id+"-section";if(self.sections.contains(id_section)){self.sectionsShowCnt[self.sections.indexOf(id_section)]++;if(id_section==self.visible){var cnt=self.sectionsHideCnt[self.sections.indexOf(id_section)];setTimeout(function(a,b){return function(){self.hideSection(a,b);}}(id_section,cnt),self.delay.hide);}}}
function sectionOver(){self.sectionsHideCnt[self.sections.indexOf(this.id)]++;var el=new Element(this.id);el=document.getElementById(el.getParent().id);if(!/item1-active/.test(el.className)){el.className=el.className.replace(/item1/,"item1-active");}}
function sectionOut(){self.sectionsShowCnt[self.sections.indexOf(this.id)]++;var cnt=self.sectionsHideCnt[self.sections.indexOf(this.id)];setTimeout(function(a,b){return function(){self.hideSection(a,b);}}(this.id,cnt),self.delay.hide);}
this.showSection=function(id,cnt){if(typeof cnt!="undefined"){if(cnt!=this.sectionsShowCnt[this.sections.indexOf(id)]){return;}}
this.sectionsShowCnt[this.sections.indexOf(id)]++;var el=new Element(id);var parent=document.getElementById(el.getParent().id);if(!/item1-active/.test(parent.className)){parent.className=parent.className.replace(/item1/,"item1-active");}
if(this.visible){if(id==this.visible){return;}
this.hideSection(this.visible);}
document.getElementById(id).style.visibility="visible";document.getElementById(id).style.zIndex=this.zIndex.visible;this.visible=id;}
this.hideSection=function(id,cnt){if(typeof cnt!="undefined"){if(cnt!=this.sectionsHideCnt[this.sections.indexOf(id)]){return;}}
var el=new Element(id);var parent=document.getElementById(el.getParent().id);parent.className=parent.className.replace(/item1-active/,"item1");document.getElementById(id).style.zIndex=this.zIndex.hidden;document.getElementById(id).style.visibility="hidden";if(id==this.visible){this.visible="";}
else{return;}
this.sectionsHideCnt[this.sections.indexOf(id)]++;}
this.hideSelf=function(cnt){if(this.visible&&cnt==this.sectionsHideCnt[this.sections.indexOf(this.visible)]){this.hideSection(this.visible);}}
function Element(id){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;this.tree=[];this.sections=[];this.sectionsShowCnt=[];this.sectionsHideCnt=[];this.visible="";}
if(typeof Array.prototype.indexOf=="undefined"){Array.prototype.indexOf=function(item){for(var i=0;i<this.length;i++){if((typeof this[i]==typeof item)&&(this[i]==item)){return i;}}
return-1;}}
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;}}


