

function hidePrint(){ // usata solo in LayoutGallery.tpl
    document.getElementById("print").style.display="none";
}



function addIDtoLIandA(){
	var i;
	var ATags=document.getElementById("startMenuSx").getElementsByTagName("a");
	var LITags=document.getElementById("startMenuSx").getElementsByTagName("li");
	var totAInMenu=ATags.length;
	
	// alert(totAInMenu);
	
	for (i=0; i<totAInMenu; i++){
		var idA="LinkMenuSx"+i;
		var idLI="LIMenuSx"+i;
		ATags[i].setAttribute('id',idA);
		LITags[i].setAttribute('id',idLI);
		if (navigator.appName.indexOf("Explorer")!=-1){
				ATags[i].attachEvent("onclick",setLinkMenuSx);
		} else{
				ATags[i].addEventListener("click",setLinkMenuSx,false);
		  }
	}
	
}	
function openMenu(q){
    if(q){
    	var elementClicked;
    	elementClicked=document.getElementById(q);
    	var brw=navigator.appName.indexOf("Expl");
    	brw!=-1?att="className":att="class";
    	elementClicked.setAttribute(att,"active");
    	var ULinElementClicked=elementClicked.getElementsByTagName("ul");
    	if (ULinElementClicked.length!=0){
    		ULinElementClicked[0].style.display="";
    	}
    	
    	var newObjParentOfElementClicked=elementClicked;
    	while(newObjParentOfElementClicked.id!="startMenuSx"){
    		
    		if(newObjParentOfElementClicked.parentNode.nodeType==1){
    			
    			if(newObjParentOfElementClicked.parentNode.nodeName=="LI"){
    				
    				newObjParentOfElementClicked.parentNode.setAttribute(att,"active");
    			} else if(newObjParentOfElementClicked.parentNode.nodeName=="UL"){
    				
    				newObjParentOfElementClicked.parentNode.style.display="";
    			}
    		}
    		newObjParentOfElementClicked=newObjParentOfElementClicked.parentNode
    	}
    }
	
	
}

function menuSx(LIClicked){
    
    if(LIClicked.id=="LIMenuSx0"){
        LIClicked=document.getElementById("LIMenuSx1")
    }
    
    if(LIClicked.id=="LIMenuSx5"){
        LIClicked=document.getElementById("LIMenuSx6")
    }
    var brw;
    var att;
    var classAttribute;
    var LIBrothers;
    var ULInMenu;
    var newObjLIPrev;
    var newObjLINext;
    var ULInBrother;
    var totULInBrother;
    var LIInBrother;
    var totLIInBrother;
	ULInMenu=LIClicked.getElementsByTagName("ul");
	brw=navigator.appName.indexOf("Expl");
	brw!=-1?att="className":att="class";
	
	newObjLIPrev=LIClicked;
	newObjLINext=LIClicked;
	while (newObjLIPrev.previousSibling) {
	   if (newObjLIPrev.previousSibling.nodeType==1){
	       newObjLIPrev.previousSibling.setAttribute(att,"");
    	   ULInBrother=newObjLIPrev.previousSibling.getElementsByTagName("ul");
    	   LIInBrother=newObjLIPrev.previousSibling.getElementsByTagName("li");
    	   totULInBrother=ULInBrother.length;
    	   totLIInBrother=LIInBrother.length;
	       if(totULInBrother!=0){
	           for(var i=0; i<totULInBrother; i++) {
	       	       ULInBrother[i].style.display="none";
	           }    
	       }
	       if(LIInBrother.length!=0){
	           for(var k=0; k<totLIInBrother; k++) {
	       	       LIInBrother[k].setAttribute(att,"");
	           }    
	       }
	       
    	   
	   }
	   newObjLIPrev=newObjLIPrev.previousSibling;
	}
	
	while (newObjLINext.nextSibling) {
	   if (newObjLINext.nextSibling.nodeType==1){
	   newObjLINext.nextSibling.setAttribute(att,"");
	   ULInBrother=newObjLINext.nextSibling.getElementsByTagName("ul");
	   LIInBrother=newObjLINext.nextSibling.getElementsByTagName("li");
	   totULInBrother=ULInBrother.length;
	   totLIInBrother=LIInBrother.length;
	  // alert(LIInBrother.length);
    	   if(totULInBrother!=0){
	           for(var i=0; i<totULInBrother; i++) {
	       	       ULInBrother[i].style.display="none";
	           }    
	       }
	       if(LIInBrother.length!=0){
	           for(var k=0; k<totLIInBrother; k++) {
	       	       LIInBrother[k].setAttribute(att,"");
	           }    
	       }
	   }
	   
	   newObjLINext=newObjLINext.nextSibling;
	}
	
	
	LIClicked.setAttribute(att,"active");
	if (ULInMenu[0]){
		ULInMenu[0].style.display="";	
	}
	
	
	
//	LIBrothers=LIClicked.parentNode.getElementsByTagName("ul");
//	alert(LIBrothers.length)

}

	function setLinkMenuSx(e){
		
		var eventType;
		var voceMenu;
		if (window.event && window.event.srcElement){
			eventType=window.event.type;
			voceMenu = window.event.srcElement;
		} else if (e && e.target){
			eventType=e.type;
			voceMenu = e.target;
		}
		if (voceMenu.href!="#"){
		var whichLI=voceMenu.id.replace("LinkMenuSx","LIMenuSx");
		
		/* se non c'è pagina di atterraggio rimando al primo link di primo livello */
		switch (whichLI) {
			case "LIMenuSx0":
				whichLI="LIMenuSx1"
				break;
            case "LIMenuSx5":
				whichLI="LIMenuSx6"
				break;
		}

		
		
		// alert(voceMenu.href+"?idLiMenuSx="+whichLI);
		//voceMenu.href=voceMenu.href+"?idLiMenuSx="+whichLI;
		voceMenu.href=voceMenu.href+"&idLiMenuSx="+whichLI;
		}
	}
	
		
		
	
	function addEventOnGallery(){
		var tableGallery=document.getElementById("ContGallery")
		var imgs=tableGallery.getElementsByTagName("img");
		var contCaption=tableGallery.getElementsByTagName("p");
		var totImg=imgs.length;
		
		for (i=0; i<totImg; i++){
			var idImg="img"+i;
			var idP="p"+i;
			if (navigator.appName.indexOf("Explorer")!=-1){
				imgs[i].attachEvent("onclick",openPopupGallery);
			} else{
				imgs[i].addEventListener("click",openPopupGallery,false);
			}	
			imgs[i].setAttribute('id',idImg);	
			contCaption[i].setAttribute('id',idP);	
		}
	}
	
	function addEventToFotoDx(){
	    if (document.getElementById("FotoDx1")){
	        if (navigator.appName.indexOf("Explorer")!=-1){
				document.getElementById("FotoDx1").attachEvent("onclick",openPopupFotoDx);
			} else{
				document.getElementById("FotoDx1").addEventListener("click",openPopupFotoDx,false);
			}	
	    }
	    if (document.getElementById("FotoDx2")){
	        if (navigator.appName.indexOf("Explorer")!=-1){
				document.getElementById("FotoDx2").attachEvent("onclick",openPopupFotoDx);
			} else{
				document.getElementById("FotoDx2").addEventListener("click",openPopupFotoDx,false);
			}	
	    }
	}
	
	function openPopupGallery(e){
		var eventType;
		var img;
		if (window.event && window.event.srcElement){
			eventType=window.event.type;
			imgClicked = window.event.srcElement;
		} else if (e && e.target){
			eventType=e.type;
			imgClicked = e.target;
		}
		var imgSrc=imgClicked.src;
		var numFoto=imgClicked.id.replace("img","");
		// var imgName=imgSrc.substring(imgSrc.lastIndexOf("/")+1,imgSrc.lastIndexOf("."));
		var imgName=imgSrc.substring(imgSrc.lastIndexOf("/")+1);
		
		var linkToPopup="./?page=ZegnaGroup.PopupGalleryCommon&imgToZoom="+imgName+"&imgNum="+numFoto;
		window.open(linkToPopup,'nome','scrollbars=no,resizable=no,width=606,height=550,status=no,location=no,toolbar=no');
		
	} 
	
	
	
    function openPopupFotoDx(e){
          
       var eventType;
		var img;
		if (window.event && window.event.srcElement){
			eventType=window.event.type;
			imgClicked = window.event.srcElement;
		} else if (e && e.target){
			eventType=e.type;
			imgClicked = e.target;
		}
		var imgSrc=imgClicked.id;
		var numFoto=imgSrc.replace("FotoDx","");
		if (numFoto=="") numFoto=1;	
		window.open('./?page=ZegnaGroup.PopupFotoDxCommon&numFoto='+numFoto+'','nome','scrollbars=no,resizable=no,width=606,height=550,status=no,location=no,toolbar=no');
	  
	} 
	
	
	