var PROMOFLEX = {};
var headerTop = 17;
var footerHeight = 40; 
var sliderHeight = 471;

PROMOFLEX.originals_heights = function(){
	var contentHeight, windowHeight;
	contentHeight = $('div#contentZone').height();
	$('div#contentZone').css({'min-height':contentHeight}); 
	$('div#sidebarArea, div#navWrapper').css({'height':contentHeight+footerHeight});
}

PROMOFLEX.set_heights = function() {
	//$BK_Debug.append("PROMOFLEX.set_heights");
	//Positionnement de l'adresse du footer
	var windowHeight,contentHeight,newContentHeight,contentListHeight;
	windowHeight = $('div#master').height();
	contentHeight = $('div#contentZone').height();
	
	//$BK_Debug.append(document.body.offsetWidth + ", " + window.innerWidth);
	
	//$BK_Debug.append("windowHeight = " + windowHeight);
	//$BK_Debug.append("contentHeight = " + contentHeight);
	
	$('div#sidebarArea, div#navWrapper').css({'height':contentHeight+footerHeight});
	$('#sliderWrapper .slides_container .slides_control a img').width($('#sliderWrapper').width());

	if(windowHeight > contentHeight){
	    
	    newContentHeight = (windowHeight) - footerHeight;		

	    //$BK_Debug.append("newContentHeight = " + newContentHeight);

	    $('div#contentZone').css({'height':newContentHeight});
	    $('div#sidebarArea, div#navWrapper').css({'height':newContentHeight + footerHeight});
		
		if($('div#sliderWrapperInterne').length != 0){sliderHeight = $('div#sliderWrapperInterne').height();}
	    contentListHeight = newContentHeight - (sliderHeight + headerTop);
		//alert(contentListHeight);
	    //$BK_Debug.append("contentListHeight = " + contentListHeight);

	    $('ul.ul-middle').css({'height':contentListHeight});
	    $('#sliderWrapper .slides_container .slides_control a img').width($('#sliderWrapper').width());
	}
	
	//$BK_Debug.append("*******************");
	//$BK_Debug.append(" ");
}

PROMOFLEX.fix_cufon_flick = function( elements, correction ){
    for ( var i = 0; i < elements.length; i++ ) {
	$(elements[ i ]).each(function(){
	    $(this).css({'text-indent' : correction});
	});
    }
}

$(window).load(function () {
  PROMOFLEX.originals_heights();
  PROMOFLEX.set_heights();
});

//jQuery
$(document).ready(function(){
	
	$('ul.sous-menu li a').hover(function(){
		PROMOFLEX.originals_heights();
		PROMOFLEX.set_heights();
	});
    	/*var fix_cufon_array = new Array(
	     'h1',
	     'h2',
	     'h3',
	     '#abreviation ul li',
	     'div#menu ul li a',
	     '.left .left-bottom-absolute ul li a',
	     '#contentWrapper #contentArea #contentZone .ul-middle .first-ul-middle-interne ul.menu li a',
	     '.right-top a',
	     '#langue a'
	 );
	     
	 PROMOFLEX.fix_cufon_flick( fix_cufon_array, '-9999px' );*/
	
	/*----------------------*/
    /* =	SLIDER          */
	/*----------------------*/
	$('#sliderWrapper').slides({
            preload: true,
            preloadImage: 'img/loading.gif',
            play: 5000,
            effect : 'fade',
            pause: 2500,
            generatePagination  :false,
            hoverPause: true
    });	
	$('#sliderWrapper .slides_container .slides_control a img').width($('#sliderWrapper').width());
	
	PROMOFLEX.originals_heights();
	PROMOFLEX.set_heights();

	$(window).resize(function(){
	    //$BK_Debug.append("$(window).resize");
	  PROMOFLEX.set_heights();
	});

	$('#menu').hide();
	//Animation du menu
	$('div#navWrapper').hover(
	    function(e){
		    $('#abreviation').fadeOut(100);
		    $('#menu').fadeIn(100);
		    var wrapper = $(this); //Objet courant
		    wrapper.stop(e).animate({width: "235px"}, 300);
		    //wrapper.clearQueue(e); //Clear des évènements
	    },
	    function(e){
		    $('#abreviation').fadeIn(100);
		    $('#menu').fadeOut(100);
		    var wrapper = $(this); //Objet courant
		    wrapper.stop(e).animate({width: "68px"}, 300);
		    //wrapper.clearQueue(e);//Clear des évènements
	    }
	);
	
	/*----------------------------------------------*/
	/* =	FONT                                    */
	/*----------------------------------------------*/
	
	Cufon('h1')
	 ('h3')
	 ('#abreviation ul li')
	 ('div#menu ul li a',{hover: {color: '#000'}})
	 ('h2')
	 ('.left .left-bottom-absolute ul li a')
	 ('#contentWrapper #contentArea #contentZone .ul-middle .first-ul-middle-interne ul.menu li a',{hover: {color: '#aaa'}})
	 ('.right-top a')
	 ('#langue a')('.cufonTxt')('.titleOption')('.listeTrousse label');
	 
	 

	 //PROMOFLEX.fix_cufon_flick( fix_cufon_array, '0' );

	 
	 /*----------------------------------------------*/
    /* =	MENU ( LETTRE GRISÉ )                   */
	/*----------------------------------------------*/

	/* var currentpage = $('#menu ul li a.actif').text();
	if (currentpage != "") {
		var chaine = "#abreviation ul li." + currentpage;
		$("'" + chaine + "'").css('color', '#CCCCCC');
	}else{
		var currentpage2 = $('#menu ul li.currentpage a').text();
		var chaine = "#abreviation ul li." + currentpage2;
		$("'" + chaine + "'").css('color', '#CCCCCC');
	
	}; */
	
	/*$('#abreviation ul li:first-child').css('color', '#CCCCCC');
	$('#menu ul li:nth-child(1) a').html($('#menu ul li:nth-child(1) a').html().replace('P','<span class="black">P</span>'));
	$('#menu ul li:nth-child(2) a').html($('#menu ul li:nth-child(2) a').html().replace('r','<span class="black">r</span>'));
	$('#menu ul li:nth-child(3) a').html($('#menu ul li:nth-child(3) a').html().replace('o','<span class="black">o</span>'));
	$('#menu ul li:nth-child(4) a').html($('#menu ul li:nth-child(4) a').html().replace('m','<span class="black">m</span>'));
	$('#menu ul li:nth-child(5) a').html($('#menu ul li:nth-child(5) a').html().replace('o','<span class="black">o</span>'));
	$('#menu ul li:nth-child(6) a').html($('#menu ul li:nth-child(6) a').html().replace('f','<span class="black">f</span>'));
	$('#menu ul li:nth-child(7) a').html($('#menu ul li:nth-child(7) a').html().replace('l','<span class="black">l</span>'));   
	$('#menu ul li:nth-child(8) a').html($('#menu ul li:nth-child(8) a').html().replace('e','<span class="black">e</span>'));  
	$('#menu ul li:nth-child(9) a').html($('#menu ul li:nth-child(9) a').html().replace('X','<span class="black">X</span>')); 
	$('#menu ul li:nth-child(9) a').html($('#menu ul li:nth-child(9) a').html().replace('x','<span class="black">x</span>')); */

	$('#contentWrapper #contentArea #contentZone .ul-middle .first-ul-middle-interne  ul.menu li ul.sous-menu li').hover(function(){
        $(this).addClass("selected");
    }, function(){
        $(this).removeClass("selected");
    });
	
	
    
});

//$BK_Debug.setState(true);
