function getMenuImage(elem){
try{
	if(elem.childNodes[0].nodeName=="H2" && elem.childNodes[0].childNodes[0].nodeName=="IMG")
		return elem.childNodes[0].childNodes[0];
	else if(elem.childNodes[1].nodeName=="H2" && elem.childNodes[1].childNodes[0].nodeName=="IMG")
		return elem.childNodes[1].childNodes[0];
	else if(elem.childNodes[1].nodeName=="H2" && elem.childNodes[1].childNodes[1].nodeName=="IMG")
		return elem.childNodes[1].childNodes[1];
	}catch(e){}
}

function overMenu(elem){
try{
	var MenuImg=getMenuImage(elem);
	if(MenuImg.src.indexOf("_on")==-1 && MenuImg.src.indexOf("_over")==-1)
		MenuImg.src=MenuImg.src.split(".gif").join("_over.gif");
	AjaxDestroySuggestion();
	closeWarenkorb();
	}catch(e){}
}
function outMenu(elem){
try{
	var MenuImg=getMenuImage(elem);
	if(MenuImg.src.indexOf("_on")==-1 && MenuImg.src.indexOf("_over")!=-1)
		MenuImg.src=MenuImg.src.split("_over.gif").join(".gif");
	}catch(e){}
}

function initMenu(){
try{
	var menuElem=document.getElementById("horizontalMenu");
	var ListNodes=menuElem.getElementsByTagName("UL");
	
	try{
	if(Browser!="Safari" && Browser!="MSIE"){
		var em=document.createElement('style');
			em.type="text/css";
			em.innerHTML="div.horizontalMenu ul li{position:relative;}";
		document.getElementsByTagName("BODY")[0].insertBefore(em,document.getElementsByTagName("BODY")[0].firstChild)
	} else if(Browser=="Safari"){
		var em=document.createElement('style');		
			em.type="text/css";
			em.appendChild(document.createTextNode("div.artikel_block{display:block;}div.header #navigation{height:57px;}"));
		document.getElementsByTagName("HEAD")[0].appendChild(em);
		
		var entr = menuElem.getElementsByTagName("ul");
		var tmp=0;
		for(var i=0;i<entr.length;i++){
			var elm = entr[i].getElementsByTagName("li")[0];
			elm.style.height="22px";
			//elm.style.overflow="hidden";
			entr[i].style.height="22px";
			elm.style.top = Math.round(i*22*-1)+"px";
			var wd = elemWidth(elm.getElementsByTagName("img")[0]);
			entr[i].style.width=wd+"px";
			entr[i].style.marginLeft = tmp+"px";
			if(i!=0) tmp+=1;
			tmp+=wd;
		}
	}
	}catch(e){}
	
	var MenuPoints=menuElem.getElementsByTagName("A");
	for(var i=0;i<MenuPoints.length;i++){
		if(MenuPoints[i].parentNode.className=="on"){
			var MenuImg=getMenuImage(MenuPoints[i].parentNode.parentNode.parentNode);
			if(MenuImg.src.indexOf("_on")==-1){
				MenuImg.src=MenuImg.src.split(".gif").join("_on.gif")
			}
			i=MenuPoints.length;
		}
	}
	
	// erzeutg das hover event und beseitigt css bugs in <IE7 und anderen ausser FF 
	
	if((Browser=="MSIE" && Version<7)){
	
		var H2Element=ListNodes[0].getElementsByTagName("H2");
			H2Element[0].style.marginLeft="0px";
			for(var i=0;i<ListNodes.length;i++){
				var HoverElem=ListNodes[i].getElementsByTagName("LI");
				HoverElem[0].oldonmouseover = HoverElem[0].onmouseover;
				HoverElem[0].onmouseover=function(evt){
											try{
												if(this.oldonmouseover)
													{this.oldonmouseover(evt);}
												var Obj=this.getElementsByTagName("OL")[0];
												Obj.style.display="block";
												if((Browser=="MSIE"&&Version<7)){
												if(Version<6){
													makeTopMost(Obj,-1,-16);
												} else {
													makeTopMost(Obj,-1,-0);
												};
												};
											}catch(e){}
											};
				HoverElem[0].oldonmouseout = HoverElem[0].onmouseout;
				HoverElem[0].onmouseout=function(evt){
										try{
											if(this.oldonmouseout)
												{this.oldonmouseout(evt);};
											var Obj=this.getElementsByTagName("OL")[0];
											Obj.style.display="none";
											removeTopMost(Obj);
										}catch(e){}
										};
				var LinkElement=ListNodes[i].getElementsByTagName("A");
				LinkElement[0].style.borderTop="none";
			}
	}
	
	// weite der dropdowns setzen 
	var corr=0;
	var OperaElemWidth=0;
	var SafariElemWidth=0;
	var tmp = 0;
		for(var i=0;i<ListNodes.length;i++){
			var DropDown=ListNodes[i].getElementsByTagName("OL");
			var H2Element=ListNodes[i].getElementsByTagName("H2");
			var H2Width=elemWidth(H2Element[0]);
			var wd = elemWidth(ListNodes[i].getElementsByTagName("img")[0]);
			
			if(Browser=="MSIE"){
				var SubLinks=DropDown[0].getElementsByTagName("A");
				var maxWidth=0;
				if(Version < 7)
					DropDown[0].style.width="1%";
				DropDown[0].className="open";
				for(var j=0;j<SubLinks.length;j++){
				if(maxWidth < elemWidth(SubLinks[j]))
					maxWidth=elemWidth(SubLinks[j]);
				}
				DropDown[0].className="";
				if(maxWidth<(H2Width-2)){
					if(Version<6){
						DropDown[0].style.width=(H2Width)+"px";
					} else {
						DropDown[0].style.width=(H2Width-3)+"px";
					}
				} else if(Version<7){
					DropDown[0].style.width=maxWidth+"px";
				} else {
					DropDown[0].style.width=(maxWidth-1)+"px";
				}
				
				if(Version>6 && i!=0){
					DropDown[0].style.paddingLeft="1px";
					DropDown[0].style.marginLeft="-"+(H2Width)+"px";
				}else if(i!=0 || Version > 6){
					DropDown[0].style.marginLeft="-"+(H2Width)+"px";
				} else {
					DropDown[0].style.marginLeft="-"+(H2Width+1)+"px";
				}

			} else if(Browser=="Opera" || (Browser=="Firefox" && Version>=3)){
				if((i+1)<ListNodes.length){
					DropDown[0].style.left=(OperaElemWidth+1)+"px";
				} else {	
					DropDown[0].style.left=(OperaElemWidth+2)+"px";
				}
				OperaElemWidth+=elemWidth(H2Element[0]);
				DropDown[0].style.minWidth=(H2Width-2)+"px";
			}else{
				DropDown[0].style.minWidth=(H2Width-2)+"px";
			}
			
			if((i+1)==ListNodes.length && Browser!="Safari"){
				DropDown[0].className="open";
				if(elemWidth(DropDown[0])>0){
				if(Browser=="MSIE"){
					DropDown[0].style.marginLeft="-"+((H2Width+1)+(elemWidth(DropDown[0])-H2Width))+"px";
				} else if(Browser=="Opera" || (Browser=="Firefox" && Version>=3)) {
					DropDown[0].style.left=(getPosLeft(DropDown[0],false)-elemWidth(DropDown[0])+H2Width-2)+"px";
				} else {
					DropDown[0].style.left=(getPosLeft(DropDown[0],false)-elemWidth(DropDown[0])+H2Width)+"px";
				}
				}
				DropDown[0].className="";	
			} else if(Browser=="Safari"){
				SafariElemWidth-=tmp;
				if(i!=0 && (i+1)!=ListNodes.length){
					DropDown[0].style.left=SafariElemWidth+"px";
				} else if((i+1)==ListNodes.length){
					
					DropDown[0].className="open";
					var over=elemWidth(DropDown[0])-H2Width;
					DropDown[0].className="";
					DropDown[0].style.left=(SafariElemWidth-over)+"px";
				}
				SafariElemWidth+=elemWidth(H2Element[0]);
			}
			tmp = wd;
		}

	var Images=menuElem.getElementsByTagName("IMG");
	var ImagePreload = new Array();
	for(var i=0;i<Images.length;i++){
		ImagePreload[ImagePreload.length]=Images[i].src.split(".gif").join("_over.gif");
		ImagePreload[ImagePreload.length]=Images[i].src.split(".gif").join("_on.gif");
	}
	preloadImages(ImagePreload);
	}catch(e){}
}

