/*##############################################################################################
######################## JS DES FONCTIONS DU TREE DU RAYON #################################### 
/*############################################################################################## */	

/*############################################################################################## */
var dhtmlgoodies_slmenuObj;
var divToScroll = false;
var ulToScroll = false;	
var divCounter = 1;
var otherDivsToScroll = new Array();
var divToHide = false;
var parentDivToHide = new Array();
var ulToHide = false;
var slideMenuHeightOfCurrentBox = 0;
var objectsToExpand = new Array();
var initExpandIndex = 0;
/*############################################################################################## */	
function popMenusToShow() {
    var obj = divToScroll;
    var endArray = new Array();
    while(obj && obj.tagName!='BODY'){
    	if(obj.tagName=='DIV' && obj.id.indexOf('slideDiv')>=0){
    		var objFound = -1;
    		for(var no=0;no<otherDivsToScroll.length;no++){
    			if(otherDivsToScroll[no]==obj){
    				objFound = no;		
    			}					
    		}	
    		if(objFound>=0){
    			otherDivsToScroll.splice(objFound,1);	
    		}		
    	}	
    	obj = obj.parentNode;
    }	
}
/*############################################################################################## */
function showSubMenu(e,inputObj) {
    
        if (document.getElementById('da')) {document.getElementById('da').style.backgroundPosition='0 0'}
        if (this.style) {if(typePage == "rayon"){this.style.backgroundPosition='-38px 0';}this.setAttribute('id','da');}
    
    if (this && this.tagName) inputObj = this.parentNode;
    if (inputObj && inputObj.tagName=='LI'){
    	divToScroll = inputObj.getElementsByTagName('DIV')[0];
    	for (var no=0;no<otherDivsToScroll.length;no++){
    		if (otherDivsToScroll[no]==divToScroll){
    		    divToScroll = '';
    		    autoHideMenus();
    		    return;
    		}
    	}			
    }
    hidingInProcess = false;
    if (otherDivsToScroll.length>0){
    	if(divToScroll){				
    		if(otherDivsToScroll.length>0){
    			popMenusToShow();
    		}
    		if(otherDivsToScroll.length>0){	
    			autoHideMenus();
    			hidingInProcess = true;
    		}
    	}	
    }		
    if(divToScroll && !hidingInProcess){
    	divToScroll.style.display='';
    	otherDivsToScroll.length = 0;
    	otherDivToScroll = divToScroll.parentNode;
    	otherDivsToScroll.push(divToScroll);	
    	while(otherDivToScroll && otherDivToScroll.tagName!='BODY'){
    		if(otherDivToScroll.tagName=='DIV' && otherDivToScroll.id.indexOf('slideDiv')>=0){
    			otherDivsToScroll.push(otherDivToScroll);    								
    		}
    		otherDivToScroll = otherDivToScroll.parentNode;
    	}			
    	ulToScroll = divToScroll.getElementsByTagName('UL')[0];
    	if(divToScroll.style.height.replace('px','')/1<=1)scrollDownSub();
    }		
}
/*############################################################################################## */
function autoHideMenus() {
    if(otherDivsToScroll.length>0){
    	divToHide = otherDivsToScroll[otherDivsToScroll.length-1];
    	divToHide.parentNode.firstChild.setAttribute('id','');
    	parentDivToHide.length=0;
    	var obj = divToHide.parentNode.parentNode.parentNode;
    	while(obj && obj.tagName=='DIV'){			
    		if(obj.id.indexOf('slideDiv')>=0)parentDivToHide.push(obj);
    		obj = obj.parentNode.parentNode.parentNode;
    	}
    	var tmpHeight = (divToHide.style.height.replace('px','')/1 - slideMenuHeightOfCurrentBox);
    	if(tmpHeight<0)tmpHeight=0;
    	if(slideMenuHeightOfCurrentBox)divToHide.style.height = tmpHeight  + 'px';
    	ulToHide = divToHide.getElementsByTagName('UL')[0];
    	slideMenuHeightOfCurrentBox = ulToHide.offsetHeight;
    	scrollUpMenu();		
    }else{
    	slideMenuHeightOfCurrentBox = 0;
    	showSubMenu();			
    }
}
/*############################################################################################## */
function scrollUpMenu() {
    var height = divToHide.offsetHeight;
    height-=15;
    if(height<0)height=0;
    divToHide.style.height = height + 'px';
    
    for(var no=0;no<parentDivToHide.length;no++){	
    	parentDivToHide[no].style.height = parentDivToHide[no].getElementsByTagName('UL')[0].offsetHeight + 'px';
    }
    if(height>0){
    	setTimeout('scrollUpMenu()',1);
    }else{
    	divToHide.style.display='none';
    	otherDivsToScroll.length = otherDivsToScroll.length-1;
    	autoHideMenus();			
    }
}	
/*############################################################################################## */
function scrollDownSub() {
    if(divToScroll){			
    	var height = divToScroll.offsetHeight/1;
    	var offsetMove =Math.min(15,(ulToScroll.offsetHeight - height));
    	height = height +offsetMove ;
    	divToScroll.style.height = height + 'px';
    	
    	for(var no=1;no<otherDivsToScroll.length;no++){
    		var tmpHeight = otherDivsToScroll[no].offsetHeight/1 + offsetMove;
    		otherDivsToScroll[no].style.height = tmpHeight + 'px';
    	}			
    	if(height<ulToScroll.offsetHeight)setTimeout('scrollDownSub()',1); else {
    		divToScroll = false;
    		ulToScroll = false;
    		if(objectsToExpand.length>0 && initExpandIndex<(objectsToExpand.length-1)){
    			initExpandIndex++;    			
    			showSubMenu(false,objectsToExpand[initExpandIndex]);
    		}
    	}
    }
}
/*############################################################################################## */
ela=new Array()
var n=0
function initSubItems(inputObj,currentDepth) {		
    divCounter++;		
    var div = document.createElement('DIV');	// Creating new div		
    div.style.overflow = 'hidden';	
    div.style.position = 'relative';
    div.style.display='none';
    div.style.height = '1px';
    div.id = 'slideDiv' + divCounter;
    div.className = 'slideMenuDiv' + currentDepth;		
    inputObj.parentNode.appendChild(div);	// Appending DIV as child element of <LI> that is parent of input <UL>		
    div.appendChild(inputObj);	// Appending <UL> to the div
    var menuItem = inputObj.getElementsByTagName('LI')[0];
    while(menuItem){
    	if(menuItem.tagName=='LI'){
    		var aTag = menuItem.getElementsByTagName('A')[0];
    		ela[n]=aTag;
    		n++;
    		/* gestion des classes actif */
    		if (aTag.className=='actif'){aTag.className='slMenuItem_depth'+currentDepth+' actif'}
    		else {aTag.className='slMenuItem_depth'+currentDepth;}
    		var subUl = menuItem.getElementsByTagName('UL');
    		if(subUl.length>0){
    			initSubItems(subUl[0],currentDepth+1);	
    	                }
    	}			
    	menuItem = menuItem.nextSibling;						
    }		
}
/*############################################################################################## */
function initSlideDownMenu(expandMenuItemByUrl) {
    dhtmlgoodies_slmenuObj = document.getElementById('menu_coulissant');   
    var mainUl = dhtmlgoodies_slmenuObj.getElementsByTagName('UL')[0];		
    var mainMenuItem = mainUl.getElementsByTagName('LI')[0];
    mainItemCounter = 1;
    while(mainMenuItem){			
    	if(mainMenuItem.tagName=='LI'){
    		var aTag = mainMenuItem.getElementsByTagName('A')[0];    		
    		 var subUl = mainMenuItem.getElementsByTagName('UL');
    		if(subUl.length>0){
    			aTag.className='slMenuItem_depth1';
    			mainMenuItem.id = 'mainMenuItem' + mainItemCounter;
    			initSubItems(subUl[0],2);
    			aTag.onclick = showSubMenu;
    			mainItemCounter++;
    		}				
    	}			
    	mainMenuItem = mainMenuItem.nextSibling;	
    }	
    
    if(expandMenuItemByUrl)    {
    	var aTags = dhtmlgoodies_slmenuObj.getElementsByTagName('A');
    	for(var no=0;no<aTags.length;no++){
    		var hrefToCheckOn = aTags[no].href;	
    		if(location.href.indexOf(hrefToCheckOn)>=0 && hrefToCheckOn.indexOf('#')<hrefToCheckOn.length-1){    			
    			var obj = aTags[no].parentNode;    			
    			while(obj && obj.id!='menu_coulissant'){    			
    				if(obj.tagName=='LI'){							
    					var subUl = obj.getElementsByTagName('UL');    					
    					if(subUl.length>0){	
    					var objTabA=obj.getElementsByTagName('A');
    					for (var num=1 ; num<objTabA.length ; num++){
    					    var hrefFamille=objTabA[num].href;
    					    var url = location.href;
    					    if(url.indexOf("?") != -1) url = url.substring(0,url.indexOf("?"));
    					    if (hrefFamille==url){
                					 objTabA[num].className = AddClassName(objTabA[num].className, 'actif');  
    					    }
    					}
    					objectsToExpand.unshift(obj);
            				    }
    				}
    				obj = obj.parentNode;	
    			}
    			showSubMenu(false,objectsToExpand[0]);
    			break;					
    		}			
    	}
    }
   
    // Hauteur de la partie basse du menu gauche
    var TsObj00 = document.getElementById('middle_content');
    var TsObj01 = document.getElementById('menu_coulissant');
    var TsObj02 = document.getElementById('a-voir-aussi-dl');
    if(TsObj00 && TsObj01 && TsObj02){
    	if(TsObj00.offsetHeight > TsObj01.offsetHeight){
    		TsObj02.style.height = TsObj02.offsetHeight + (TsObj00.offsetHeight - TsObj01.offsetHeight) + 'px'
    	}
    }   
    /* Dans le cas ou on clique sur un sous rayon dans le header univers, on deplie le tree avec le bon sous rayon*/
    if(window.location.search !=''){
    	showSubMenu(true,document.getElementById('mainMenuItem' +window.location.search.substring(1)));	
    }
}