Shadowbox.init({
    language: 'en',
    players:  ['iframe','img']
});

jQuery.noConflict();

Event.observe(window, 'load', initPage, false);

function initPage(){
	resizeWindow();
}

/************************************************************************************
*									MEnu de dessus
************************************************************************************/

var timeout_tohide = 300;
var selected_li = null;
var selected_li2 = null;
var selected_ul = null;
var lis = null;
var actu_id = null;

for( var i = 0; i < 100; i++ ){
    eval("var timeoutli" + i + " = false;");
}

function initTopMenu(){
    
	if ( browser.isDOM1 
    && !( browser.isMac && browser.isIE ) 
    && !( browser.isOpera && browser.versionMajor < 7 )
    && !( browser.isIE && browser.versionMajor < 5 ) ) {
        var menu = document.getElementById('menu'); // the root element
        var lis = menu.getElementsByTagName('li'); // all the li
        
		selected_lis = towns = $("menu").getElementsBySelector('li.selected');
		if (selected_lis && selected_lis.length>0) {
			selected_li =selected_lis[0];
			if (selected_li.getElementsByTagName('ul').length > 0) selected_ul = selected_li.getElementsByTagName('ul');
			if (selected_lis.length>1){
				selected_li2 = selected_lis[1]
			}
		}
        menu.className='menu';
        
        for ( var i=0; i<lis.length; i++ ){
            if ( lis.item(i).getElementsByTagName('ul').length > 0 ) {        
                if ( browser.isIE ){
                    addAnEvent(lis.item(i),'keyup',show);
                }
                addAnEvent(lis.item(i),'mouseover',show);
                addAnEvent(lis.item(i),'mouseout',timeoutHide);
                addAnEvent(lis.item(i),'blur',timeoutHide);
                addAnEvent(lis.item(i),'focus',show);
                
                // add an id to list item
                lis.item(i).setAttribute( 'id', "li"+i );
            }
        }
    }
	reset();
}

function reset(){
	if (selected_li && selected_li2 && actu_id==null){
		selected_li.getElementsByTagName('a')[0].className = 'linkOver';
		selected_li2.getElementsByTagName('a')[0].className = 'linkOver';
		selected_li.getElementsByTagName('ul')[0].style['visibility'] = 'visible';	
	}
}

function addAnEvent( target, eventName, functionName ){
    if ( browser.isIE ){
        //attachEvent dont work properly with this
        eval('target.on'+eventName+'=functionName');
    }
    else    {
        target.addEventListener( eventName , functionName , true ); // true is important for Opera7
    }
}
    
function timeoutHide(){
	actu_id = null;
    eval( "timeout" + this.id + " = window.setTimeout('hideUlUnder( \"" + this.id + "\" )', " + timeout_tohide + " );");
}

function hideUlUnder( id ){   
	if (document.getElementById(id).getElementsByTagName('ul')[0]) {
		document.getElementById(id).getElementsByTagName('ul')[0].style['visibility'] = 'hidden';
	    var as = document.getElementById(id).getElementsByTagName('a');
	    for ( var i=0; i<as.length; i++ ){
	        as.item(i).className="";
	    }
	}
	reset();
}

function show(){
	actu_id = this.id;
	if (this.getElementsByTagName('ul')[0]) {
		this.getElementsByTagName('ul')[0].style['visibility'] = 'visible';
    	var currentNode=this;
	    while(currentNode)   {
	            if( currentNode.nodeName=='LI'){
	                currentNode.getElementsByTagName('a')[0].className = 'linkOver';
	            }
	            currentNode=currentNode.parentNode;
	    }
	    eval ( "clearTimeout( timeout"+ this.id +");" );
	    hideAllOthersUls( this );
	}
}

function hideAllOthersUls( currentLi ){
    var lis = currentLi.parentNode;
    for ( var i=0; i<lis.childNodes.length; i++ )   {
        if ( lis.childNodes[i].nodeName=='LI' && lis.childNodes[i].id != currentLi.id ){
            hideUlUnderLi( lis.childNodes[i] );
        }
    }
}

function hideUlUnderLi( li ){
    var as = li.getElementsByTagName('a');
    for ( var i=0; i<as.length; i++ ){
        as.item(i).className="";
    }
    var uls = li.getElementsByTagName('ul');
    for ( var i=0; i<uls.length; i++ ){
        uls.item(i).style['visibility'] = 'hidden';
    }
} 


/************************************************************************************
*									MEnu de gauche
************************************************************************************/

function initLeftMenu(selected_id, selected_subid){
	/*
	var divs = $("leftmenu_container").getElementsByClassName("sub_elements");
	for ( var i = 0 ; i< divs.length ; i++) {
		divs[i].hide();
	}
	
	if ($('sub_elements_'+selected_subid) )$('sub_elements_'+selected_subid).show();

	jQuery(function() {
		jQuery("#leftmenu_container").accordion({
			event: "click", 
			collapsible: true,
			autoHeight: false,
			active: selected_id,
			navigation: true
		});
	});
	*/


}

function showSubMenu(menu){
	jQuery('#'+menu).toggle("fast");
}


/************************************************************************************
*									Gestion de la taille de la fenêtre
************************************************************************************/

function resizeWindow(){ 	
		
	if ($('background_pict')){
		if( typeof( window.innerWidth ) == 'number' ) {	//Non-IE
			window_h = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
			window_h = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {	//IE 4 compatible
			window_h = document.body.clientHeight;
		}
		window_w = document.getElementById("background_container").offsetWidth;
		
		if ($('background_pict')){
			bg_img_w = $('background_pict').getWidth();
			bg_img_h = $('background_pict').getHeight();
			delta = bg_img_w/bg_img_h;
		

			if ( document.getElementById("background_pict").style.height!= null ){
				if ((window_w/window_h)>delta) Element.setStyle("background_pict", { width: px(window_w), height: px(window_w/delta) } );
				else                           Element.setStyle("background_pict", { width: px(window_h*delta), height: px(window_h) } );
			}
		
			 //new Effect.Appear('background_pict', {delay:0, duration: 1 } );
			Element.show('background_pict');  
		}  
	
		//if ( $("background_container").getHeight() > ($("global_container").getHeight()) ) Element.setStyle("footer",{height: ($("background_container").getHeight()-$("global_container").getHeight())+"px"});
		//alert($("background_container").getHeight()+" "+$("footer").getHeight());
		if ( $("background_container").getHeight() > ($("global_container").getHeight()) ) Element.setStyle("footer_container",{top: ($("background_container").getHeight()-$("global_container").getHeight()-$("footer").getHeight())+"px"});
	}
	else if ( $("background_container").getHeight() > ($("global_container").getHeight()+$("footer_container").getHeight()) ) Element.setStyle("footer",{height: ($("background_container").getHeight()-$("global_container").getHeight())+"px"});

}

onresize = resizeWindow;


/************************************************************************************
*									Footer box
************************************************************************************/


jQuery(document).ready(function(){
	/*
	if (getCookieVal("footer_box_closed")==1)  {
		//hideFooterbox();
		//jQuery("#footer_box_content").toggle();
    	jQuery("#footer_box_content").css("height", "18px");
    	
		$("footer_box_close_button").hide();
   		$("footer_box_open_button").show();
	}
	else {
		jQuery("#footer_box_open_button").hide();
    	jQuery("#footer_box_content").css("height", "140px");
	}
	*/
	//Event.observe($("footer_box_open_button"), "click", function() {  showFooterbox(); }, false);
	//Event.observe($("footer_box_close_button"), "click", function() { hideFooterbox(); }, false);
	Event.observe($("footer_box_control"), "click", function() { switchFooterbox(); }, false);  
});


function switchFooterbox(){
	if (getCookieVal("footer_box_closed")==1) showFooterbox();
	else 	hideFooterbox(); 
}

function showFooterbox(){
   	//jQuery("#footer_box_content").slideToggle();
    jQuery("#footer_box_content").animate({"height": "140"}, {duration: "slow" });
   	$("footer_box_close_button").show();
   	$("footer_box_open_button").hide();
	document.cookie =  "footer_box_closed=0";	
}

function hideFooterbox(){
	//jQuery("#footer_box_content").slideToggle();
    jQuery("#footer_box_content").animate({"height": "18"}, {duration: "slow" });
    $("footer_box_close_button").hide();
   	$("footer_box_open_button").show();
	document.cookie =  "footer_box_closed=1";
}

function getCookieVal (name) {
	var deb,fin
      deb = document.cookie.indexOf(name + "=")
      if (deb >= 0) {
         deb += name.length + 1
         fin = document.cookie.indexOf(";",deb)
         if (fin < 0) fin = document.cookie.length
         return unescape(document.cookie.substring(deb,fin))
         }
      return ""
}

/************************************************************************************
*									En plus
************************************************************************************/

function px(x){
	return ''.concat(Math.round(x), 'px');
}