window.addEvent('domready', function(){
  initSearchByCatSubMenus();
 // initLayerBehavior();
});

/* Search By Cat SubMenus Handlers */
function initSearchByCatSubMenus(){
    
	/* Habitat subMenus */
	$$('#habitat dl').each( function(e1){
            e1.getElement('dt').addEvent('mouseenter', showHabitatSubMenu);
    });
    $('habitat').addEvent('mouseleave', hideAllHabitatSubMenus);
    $$('#habitat h1').addEvent('mouseenter',hideAllHabitatSubMenus);
	
	// Services subMenus 
	$$('#services dl').each( function(e1){
            e1.getElement('dt').addEvent('mouseenter', showServicesSubMenu);
    });
	$('services').addEvent('mouseleave', hideAllServicesSubMenus);
    $$('#services h1').addEvent('mouseenter',hideAllServicesSubMenus);

	// Services personne subMenus
	/*$$('#servicesPersonne dl').each( function(e1){
            e1.getElement('dt').addEvent('mouseenter', showServicesPersonneSubMenu);
    })
	$('servicesPersonne').addEvent('mouseleave', hideAllServicesPersonneSubMenus);
    $$('#servicesPersonne h2').addEvent('mouseenter',hideAllServicesPersonneSubMenus);*/

	// Assurance subMenus
	$$('#assurance dl').each( function(e1){
            e1.getElement('dt').addEvent('mouseenter', showAssuranceSubMenu);
    })
	$('assurance').addEvent('mouseleave', hideAllAssuranceSubMenus);
    $$('#assurance h1').addEvent('mouseenter',hideAllAssuranceSubMenus);

	// Credit subMenus
	$$('#credit dl').each( function(e1){
            e1.getElement('dt').addEvent('mouseenter', showCreditSubMenu);
    })
	$('credit').addEvent('mouseleave', hideAllCreditSubMenus);
    $$('#credit h1').addEvent('mouseenter',hideAllCreditSubMenus);
}

function showHabitatSubMenu( event ){
    hideAllHabitatSubMenus( event );
    var event    = new Event(event);
    var newWidth = 0;
	this.getElement('a').setStyle('background-image','none').setStyle('text-decoration','underline');
	this.getParent().setStyle('background-color','#f1f0f0');
	
	if ( this.getParent().hasClass('evenCat') ) newWidth = '234px';
	else newWidth = '233px';
	
	this.getParent().setStyle('border-right',0).setStyle('width',newWidth);
    var subMenu  = this.getNext(); // SubMenu is the next dom element
   
    var topOffset = this.getParent().getTop() - 1;
    var leftOffset = ( this.getParent().hasClass('evenCat') ) ? 239 : 472;

	if( window.ie6 ) leftOffset += 2;
		
     subMenu.setStyle('display','block')
    .setStyle('top', topOffset + 'px')
    .setStyle('left', leftOffset +'px');
}

function hideAllHabitatSubMenus( event ){
	$$('#habitat dt a').setStyle('background-image','url(images/habitat_icons.png)').setStyle('text-decoration','none');
    $$('#habitat dl dd').setStyle('display','none');
	$$('#habitat dl').setStyle('background-color','white');
    $$('.evenCat').setStyle('border-right','4px solid #508dba').setStyle('width','230px');
    $$('.oddCat').setStyle('border-right','3px solid #508dba').setStyle('width','231px');
    
}

function showServicesSubMenu(event) {
	hideAllServicesSubMenus();
	
	var topOffset = this.getParent().getTop() - 1;
    var leftOffset = 717;
	
	if(window.ie6) leftOffset += 3;
	
	this.getElement('a').setStyle('text-decoration','underline');
	this.getParent().setStyle('background-color','#f5edf8');
	this.getParent().setStyle('border-right',0).setStyle('width','230px');
	var subMenu  = this.getNext(); // SubMenu is the next dom element
	subMenu.setStyle('display','block')
    .setStyle('top', topOffset )
    .setStyle('left', leftOffset );
}

function hideAllServicesSubMenus( event ){
	$$('#services dt a').setStyle('text-decoration','none');
	$$('#services dl dd').setStyle('display','none');
	$$('#services dl').setStyle('width','230px')
	.setStyle('border-right','3px solid #cc7fe5')
	.setStyle('background-color','white');
}

function showServicesPersonneSubMenu( event ) {
	hideAllServicesPersonneSubMenus();
	var topOffset = this.getParent().getTop() - 1;
    var leftOffset = 545;
	if( window.ie6 ) leftOffset += 2;
	
	this.getParent().setStyle('background-color','#fcf4fa');
	this.getParent().setStyle('border-left',0).setStyle('width','210px')
	this.getElement('a').setStyle('padding-left','15px').setStyle('text-decoration','underline');;
	var subMenu  = this.getNext(); // SubMenu is the next dom element
	subMenu.setStyle('display','block')
    .setStyle('top', topOffset + 'px' )
    .setStyle('left', leftOffset + 'px');
}




function hideAllServicesPersonneSubMenus( event ) {
	$$('#servicesPersonne dl dd').setStyle('display','none');
	$$('#servicesPersonne dl').setStyle('width','207px')
	.setStyle('border-left','3px solid #ff86d9')
	.setStyle('background-color','white')
	$$('#servicesPersonne dt a').setStyle('padding-left','12px').setStyle('text-decoration','none');
}





function showAssuranceSubMenu( event ){
    hideAllAssuranceSubMenus( event );
	var subMenu  = this.getNext(); // SubMenu is the next dom element
	
	if( subMenu ){
		var event    = new Event(event);
		var newWidth = 0;
		this.getElement('a').setStyle('text-decoration','underline');
		this.getParent().setStyle('background-color','#f3f7e9');
		
		if ( this.getParent().hasClass('assurance_evenCat') ) newWidth = '234px';
		else newWidth = '233px';
		
		//this.getParent().setStyle('border-right',0).setStyle('width',newWidth);
		var subMenu  = this.getNext(); // SubMenu is the next dom element
	   
		var topOffset = this.getParent().getTop() - 1;
		var leftOffset = ( this.getParent().hasClass('assurance_evenCat') ) ? 235 : 472;
	
		if( window.ie6 ) leftOffset += 2;
			
		this.getParent().setStyle('background-color','#f3f7e9');
		this.getParent().setStyle('border-right',0).setStyle('width','235px')
		this.getElement('a').setStyle('padding-left','15px').setStyle('text-decoration','underline');;
		
		 subMenu.setStyle('display','block')
		.setStyle('top', topOffset + 'px')
		.setStyle('left', leftOffset +'px');
	}
}

/*function showAssuranceSubMenu( event ) {
	hideAllAssuranceSubMenus();
	
	var subMenu  = this.getNext(); // SubMenu is the next dom element
	
	if( subMenu ){
	var topOffset = this.getParent().getTop() - 1;
    var leftOffset = 545;
	
	if( window.ie6 ) leftOffset += 2;
	
	this.getParent().setStyle('background-color','#f3f7e9');
	this.getParent().setStyle('border-left',0).setStyle('width','210px')
	this.getElement('a').setStyle('padding-left','15px').setStyle('text-decoration','underline');;
	
	subMenu.setStyle('display','block')
    .setStyle('top', topOffset + 'px')
    .setStyle('left', leftOffset + 'px');
	}
}*/

function hideAllAssuranceSubMenus( event ){
		$$('#assurance dt a').setStyle('text-decoration','none');
    $$('#assurance dl dd').setStyle('display','none');
	$$('#assurance dl').setStyle('background-color','white');
    $$('.assurance_evenCat').setStyle('border-right','4px solid #8EC100').setStyle('width','231px');
    $$('.assurance_oddCat').setStyle('border-right','3px solid #8EC100').setStyle('width','232px');
    
}

/*function hideAllAssuranceSubMenus(event){
	
	$$('#assurance dl dd').setStyle('display','none');
	$$('#assurance dl').setStyle('width','207px')
	.setStyle('border-left','3px solid #8ec102')
	.setStyle('background-color','white')
	$$('#assurance dt a').setStyle('padding-left','12px').setStyle('text-decoration','none');
	 $$('.assurance_evenCat').setStyle('border-right','4px solid #8EC100').setStyle('width','230px');
    $$('.assurance_oddCat').setStyle('border-right','3px solid #8EC100').setStyle('width','230px');
}*/



function showCreditSubMenu( event ){
    hideAllCreditSubMenus( event );
	var subMenu  = this.getNext(); // SubMenu is the next dom element
	
	if( subMenu ){
		var event    = new Event(event);
		var newWidth = 0;
		this.getElement('a').setStyle('text-decoration','underline');
		this.getParent().setStyle('background-color','#FCF6EC');
		
		if ( this.getParent().hasClass('credit_evenCat') ) newWidth = '234px';
		else newWidth = '233px';
		
		//this.getParent().setStyle('border-right',0).setStyle('width',newWidth);
		var subMenu  = this.getNext(); // SubMenu is the next dom element
	   
		var topOffset = this.getParent().getTop() - 1;
		var leftOffset = ( this.getParent().hasClass('credit_evenCat') ) ? 731 : 472;
	
		if( window.ie6 ) leftOffset += 2;
			
		this.getParent().setStyle('background-color','#FCF6EC');
		this.getParent().setStyle('border-right',0).setStyle('width','245px')
		this.getElement('a').setStyle('padding-left','15px').setStyle('text-decoration','underline');
		
		 subMenu.setStyle('display','block')
		.setStyle('top', topOffset + 'px')
		.setStyle('left', leftOffset +'px');
	}
}

function hideAllCreditSubMenus( event ){
		$$('#credit dt a').setStyle('text-decoration','none');
    $$('#credit dl dd').setStyle('display','none');
	$$('#credit dl').setStyle('background-color','white');
    $$('.credit_evenCat').setStyle('border-right','4px solid #FF9C00').setStyle('width','241px');
    $$('.credit_oddCat').setStyle('border-right','3px solid #FF9C00').setStyle('width','241px');
    
}

