// <![CDATA[
$(document).ready(function() {
    /**/
    if (document.getElementById('panier'))
    {
        var nbdoc = getnbTotalDoc();

        if (nbdoc >0)
        {
            constructTable();
        }
    }

    // Accordeon - Les documents utiles
    $('div#accordion-results div.one-element').addClass("close").eq(0).removeClass("close");
    $('div#accordion-results div.hta a.simple').click(function(){
    	$_e = $(this).parent().parent();
		$('div#accordion-results div.one-element').addClass("close");
    	$_e.removeClass('close');
    });
    $('div#accordion-results div.hta a.toggle').click(function(){
    	$(this).parent().parent().toggleClass('close');
    });
 
    // png fix
    $('.pngfix').ifixpng();
    //$('.mainmenuitem').ifixpng();
	
    // preload et rollover menu haut
    $("img.mainmenuitem.off").each(function(){
        $.preloadImages(this.src.replace("_off","_on"));
        $(this).hover(
            function(){
                this.src=this.src.replace("_off","_on");
            },
            function(){
                this.src=this.src.replace("_on","_off");
            },
            function(){
                this.style=this.style.replace("_off","_on");
            },
            function(){
                this.style=this.style.replace("_on","_off");
            }
            );
    });
    // preload et rollover img zoom
    $("img.rollzoom.off").each(function(){
        $.preloadImages(this.src.replace("-off","-on"));
        $(this).hover(
            function(){
                this.src=this.src.replace("-off","-on");
            },
            function(){
                this.src=this.src.replace("-on","-off");
            }
            );
    });


    // onglets
    $('ul.onlget').onglet();

    // diaporama
    $('div.diaporama').s3Slider({
        timeOut: 5000
    });
	
    $('div.fm_home_diaporama').s3Slider({
        timeOut: 5000
    });
	
    // carousel
    $('div.carousel').carousel({
        dx:2,
        dt:50
    });

    //Accordeons dl dt
    $('div.accordeon').accordeon();

    // fontsizer
    var options = {
        obj:'#main',
        min: 0,
        max: 5
    };
    $.FontSizer.Init(options);

    $("#zoomm").click(function(){
        $.FontSizer.DecreaseSize(".left");
        $.FontSizer.DecreaseSize(".center");
        $.FontSizer.DecreaseSize(".right");
        return false;
    });
    $("#zoomp").click(function(){
        $.FontSizer.IncreaseSize(".left");
        $.FontSizer.IncreaseSize(".center");
        $.FontSizer.IncreaseSize(".right");
        return false;
    });
	
    // flash accor dans le monde
    $('#flashWorldWide').flash({
        src: '/fileadmin/templates/flash/AccorWorldWide/'+$('html').attr('lang')+'/index.swf',
        width: '900',
        height: '507'
    },
    {
        version: 9
    }
    );/**/
	
    // sitemap
    $("div.sitemap > ul > li > ul > li > ul").addClass("close");
    $("div.sitemap > ul > li > ul > li").each(function(){
        var e = this;
        var a = $("a.toggle",e);
        a.addClass("open");
        a.click(function(){
            var ul = $("ul",e);
            ul.blocdp();
            if(ul.hasClass("close")) {
                a.removeClass("close");
                a.addClass("open");
            }else{
                a.removeClass("open");
                a.addClass("close");
            }
            return false;
        })
    });
	
    // flux symex
    /***/

    //$.getScript('http://accor2.symexbelgium.com/graph/finance.js', function() {
    //$.getScript('http://fo.accor.typo3.valtech-agency.fr/fileadmin/templates/js/finance.js', function() {


    if(typeof(symex_date) != "undefined") {
        var symex_formatted_date = symex_date.split('/');
        var symex_formatted_var = symex_var_per;
        if($('html').attr('lang') != 'fr') {
            symex_formatted_date = symex_formatted_date[1]+'-'+symex_formatted_date[0]+'-'+symex_formatted_date[2];
            symex_formatted_var = symex_formatted_var.replace('.',',');
        }else{
            var symex_formatted_date = symex_formatted_date[0]+'-'+symex_formatted_date[1]+'-'+symex_formatted_date[2];
        }
	
        var symex_img_var = '<img src="/fileadmin/templates/images/action_up.gif" width="7" height="7" alt="" />';
        if(parseFloat(symex_var_per) < 0) {
            symex_img_var = '<img src="/fileadmin/templates/images/action_down.gif" width="7" height="7" alt="" />';
        }
		
        var html = 'Euronext Paris '+symex_formatted_date+' '+symex_time+' - '+symex_img_var+' '+symex_last+' &euro; '+symex_formatted_var+' %';
        $('#symex_info').html(html);
        $('#symex_finance').html(html);
    }
    //});
	


    getMyBasketli();
    getMyBasketh2();
    getMyBasketp();
    getMyBasketspan();

    /*si on ne se trouve pas sur la homepage*/
    if ((!document.getElementById('homeflash')) && (!document.getElementById('flashWorldWide')))
    {
        getElementsByClass();
        faqrollimg();
        getTotalDoc();
      
    }
	
	// Tableau des marques
    $("div.brands tr").each(function(){
    	obj = $("td:not(:first), th:not(:first)", this);
        for(i = 0; i < obj.length; i++){
        	obj.eq(i).toggleClass("col_" + i);
        }
        obj.hover(
	    	function(){
	    		col = $(this).attr('class');
	    		$("div.brands ." + col).addClass("hover");
	    	},
	    	function(){
	    		classList = $(this).attr("class").split(" ");
	    		$("div.brands ." + classList[0]).removeClass("hover");
        });
        obj.click(function(){
    		classList = $(this).attr("class").split(" ");
			url = $("div.brands th." + classList[0] + " div.image a").attr("href"); /* JPR 31/03/2011 */
        	/*$(location).attr('href',$('base').attr('href')+url);*/ /* JPR 31/03/2011 */
    		window.location.href = $('base').attr('href')+url; /* JPR 31/03/2011 */
        });
    });
});


function getElementsByClass()
{
	$("a.lexiquelink").mouseover(function(){
		if($(this).attr("title")!="")
		{
		var mylabel = $(this).text();
		$(this).html(mylabel+"<span><strong>"+$(this).attr('title')+"</strong></span>");
		}
		$(this).attr('title','');
		$(this).addClass("lexiquelinkon");
	});
	$("a.lexiquelink").mouseout(function(){
		$(this).removeClass("lexiquelinkon");
	});
}

/*Add crm metrics*/
function getElementsByCRM()
{
    var target= document.getElementById('push') ;
    if (document.getElementById('push'))
    {
        var maclasse="crm";
        var as = target.getElementsByTagName('a');
        for(var i=0; i<as.length; i++)
        {
            if(as[i].className == maclasse)
            {
            
                as[i].onclick = function(){
                    // alert("crm clic");
                    visit();
                    i++;
                }
          
            }
        }
    }
}

function getSearchEngineLinks()
{
	
    if (document.getElementById('tx_indexedsearch') )
    {
	
        var target= document.getElementById('content') ;
        var maclasse="tx-indexedsearch-title";
        var mytitle = target.getElementsByTagName('h3');
        for(var i=0; i<mytitle.length; i++)
        {
            var as = mytitle[i].getElementsByTagName('a');
            as[0].onmouseover = function(){
                this.target="_blank";
            //alert(this.href);
					
            }
        }
	
    }


}

 
function gettipfriend()
{
    var myurl= document.location.href;
    if(document.getElementById('tipurlA'))
        document.getElementById('tipurlA').value = myurl ;
    if(document.getElementById('tipurlB'))
        document.getElementById('tipurlB').value = myurl ;

}
     
function faqrollimg()
{
    var target= document.getElementById('content') ;
    var maclasse="faqlegend";
    var mycontainer = target.getElementsByTagName('div');
    for(var i=0; i<mycontainer.length; i++)
    {
        if(mycontainer[i].className == maclasse)
        {
            var mylink= mycontainer[i].getElementsByTagName('a');
            for(j=0;j<mylink.length;j++)
            {
                mylink[j].onclick = function(){
                    if(this.className == "off")
                    {
                        document.getElementById('faqLienH').className = "on";
                        document.getElementById('faqLienB').className = "on";
                    }
                    else
                    {
                        document.getElementById('faqLienH').className = "off";
                        document.getElementById('faqLienB').className = "off";
                    }
                }
            }
        }
     
    }
}
     
     

function getNewPagination()
{
    var activeClassName = "on";


    if (document.getElementById("paginationActive"))
    {
        var activepage = $('#paginationActive').text();
        $('ul.lastpagination').jcarousel({
            start: jQuery.jcarousel.intval(activepage),
            scroll:10,
            visible: 10,
            animation:"fast",
            initCallback: mycarousel_initCallback

        });

        $(".jcarousel-item-"+activepage).addClass(activeClassName);

        if ($('ul.lastpagination:eq(0) li').length < 11)
        {
            $('div.containerpagin').addClass("simplepagin");
        }

    }
}
function mycarousel_initCallback(carousel) {

    jQuery('.jcarousel-next').bind('click', function() {

        //console.log(carousel);
        //carousel.options.scroll = jQuery.jcarousel.intval(10);
        carousel.options.scroll = 10;
        carousel.next();

        return false;
    });

    jQuery('.jcarousel-prev').bind('click', function() {
        //carousel.options.scroll = jQuery.jcarousel.intval(10);
        carousel.options.scroll = 10;
        carousel.prev();

        return false;
    });


    jQuery('.nextbtn').bind('click', function() {
        //console.log($('ul.lastpagination:eq(0) li').length+1);
        carousel.options.scroll = jQuery.jcarousel.intval($('ul.lastpagination:eq(0) li').length);
        carousel.next();

        return false;
    });

    jQuery('.prevbtn').bind('click', function() {
        //alert($('ul.lastpagination:eq(0) li').length+1);
        carousel.options.scroll = jQuery.jcarousel.intval($('ul.lastpagination:eq(0) li').length);
        carousel.prev();

        return false;
    });
}  

$(document).ready(function() {


    $('.tx-indexedsearch-rules a').click(function(){
        if ($('.tx-indexedsearch-rules .ruletext').css('display') == 'none')
        {
            $('.tx-indexedsearch-rules .ruletext').css('display','block');
        }
        else
        {
            $('.tx-indexedsearch-rules .ruletext').css('display','none');
        }

    });
	checkActionActusearch();


});
function checkActionActusearch()
{
	
 $('strong.searchactuaction').parent().mouseover(function(){
	var request= "?motclefs="+$("#motclefs").val();
		request += "&themes="+$("#themes").val();
		request += "&types="+$("#types").val();
		request += "&type="+$("#type").val();
 
 
$(this).attr("href",$("form#actualites").attr("action")+request);
 
 
//$("#actualites").submit();
 

 });
}



window.onload = function() {
    gettipfriend();
    getElementsByCRM();
    getSearchEngineLinks();
    //on va regarder si il y a une pagination, si ce n'est pas le cas, on supprime tout
    if (document.getElementById("paginationActive"))
    {
        // Au quel cas si c'est l'agenda 
        if(document.getElementById("actupagin") && document.getElementById("actupagin").firstChild != null){
            if(document.getElementById("actupagin").firstChild.innerHTML != "")
            {
                getNewPagination();
            }

        }else{
            getNewPagination();
        }

        
    }

}



/*
function changeImageOn(span,etat)
{
	if(etat == "off")
	{
		alert("test");
		span.innerHTML=span.innerHTML.replace("_on","_off");
	}
	
	if(etat == "on")
	{
		//span.innerHTML=span.innerHTML.replace("_off","_on");
		document.getElementbyId("footerBloc").innerHTML = "test";
		alert("essai");
	}
}

function changeImageOff(span)
{
	alert("pass2");
	//span.innerHTML=span.innerHTML.replace("_on","_off");	
}
*/


// ]]>


 $(document).ready(function() {	
		//alert('ok'); 
		//$('#content').hide();
		//$('a.tt_content_9386').click(function(event){
		$('a.tt_content_31016').click(function(event){
			event.preventDefault();
			$('#content').append('<div id="content_popin_video" style="width: 552px;height: 346px;text-align:right;padding:20px;background:black;" ><div id="content_popin_video_flash" style="width:552px;height:336px;"></div><div style="padding-top: 7px;" ><a href="#" class="close" style="color:white;font-family:arial;">Fermer</a></div></div>');
			$('#content_popin_video_flash').flash({ flashvars: { vxml: 'fr/mediatheque/10461/flvPlayer.xml?tx_accorcontentblocks_pibase[typemedia]=', imgURL: 'fileadmin/user_upload/Contenus_Accor/Commun/img/mediatheque/video/accor_video_2010.jpg', autoPlay : true} ,src: '/fileadmin/templates/flash/LecteurFlash/player_FLV.swf',width: 552,height: 336, allowfullscreen: true, quality: "high", allowScriptAccess: "sameDomain", wmode: "transparent"  },{ version: 9 });
			$('#content_popin_video').lightbox_me({centered: true, destroyOnClose: true, overlayCSS: {background: 'black',opacity: .8}});
		});
		if ($(".tx-accorfmblocs-pi2 .marques .table").size()>0){
			width=$(".tx-accorfmblocs-pi2 .marques .table").width() - $(".tx-accorfmblocs-pi2 .marques .table th[class*=first]").width();
			width=width/($(".tx-accorfmblocs-pi2 .marques .table th[class!=first]").size());
			$(".tx-accorfmblocs-pi2 .marques .table th[class!=first]").width(width);
		}
		if ($("table.content-all-blocks td").size()==2){
			minHeight=134;
			height_1_1=$("table.content-all-blocks td:eq(0) .bloctexte:eq(0) div.body").height();
			if (height_1_1<minHeight){height_1_1=minHeight;}
			height_2_1=$("table.content-all-blocks td:eq(1) .bloctexte:eq(0) div.body").height();
			if (height_2_1<minHeight){height_2_1=minHeight;}
			if (height_1_1<height_2_1){
				$("table.content-all-blocks td:eq(0) .bloctexte:eq(0) div.body").css("height",height_2_1+"px");
				$("table.content-all-blocks td:eq(1) .bloctexte:eq(0) div.body").css("height",height_2_1+"px");
			}else{
				$("table.content-all-blocks td:eq(0) .bloctexte:eq(0) div.body").css("height",height_1_1+"px");
				$("table.content-all-blocks td:eq(1) .bloctexte:eq(0) div.body").css("height",height_1_1+"px");
			}
			minHeight=142;
			height_1_2=$("table.content-all-blocks td:eq(0) .bloctexte:eq(1) div.body").height();
			if (height_1_2<minHeight){height_1_2=minHeight;}
			height_2_2=$("table.content-all-blocks td:eq(1) .bloctexte:eq(1) div.body").height();
			if (height_2_2<minHeight){height_2_2=minHeight;}
			if (height_1_2<height_2_2){
				$("table.content-all-blocks td:eq(0) .bloctexte:eq(1) div.body").css("height",height_2_2+"px");
				$("table.content-all-blocks td:eq(1) .bloctexte:eq(1) div.body").css("height",height_2_2+"px");
			}else{
				$("table.content-all-blocks td:eq(0) .bloctexte:eq(1) div.body").css("height",height_1_2+"px");
				$("table.content-all-blocks td:eq(1) .bloctexte:eq(1) div.body").css("height",height_1_2+"px");
			}
		}
		

}); 
//function chargerVideoFlash(width, height, flashvars, src){
function chargerVideoFlash(width, height, vxml, imgURL, src){
	height_div=height*1+10;
	$('#content').append('<div id="content_popin_video" style="width: '+width+'px;height: '+height_div+'px;text-align:right;padding:20px;background:black;" ><div id="content_popin_video_flash" style="width:'+width+'px;height:'+height+'px;"></div><div style="padding-top: 7px;" ><a href="#" class="close" style="color:white;font-family:arial;">Fermer</a></div></div>');
	$('#content_popin_video_flash').flash({ flashvars: { vxml: vxml, imgURL: imgURL, autoPlay : true} ,src: src,width: width,height: height, allowfullscreen: true, quality: "high", allowScriptAccess: "sameDomain", wmode: "transparent"  },{ version: 9 });
	$('#content_popin_video').lightbox_me({centered: true, destroyOnClose: true, overlayCSS: {background: 'black',opacity: .8}});
	return false;
}

$(document).ready(function() {
	$('div.content-block-fw-bordeau a.visual div.info').hide();
    $('div.content-block-fw-bordeau a.visual').mouseenter(function(){
    	$(this).find('div.info').fadeIn('normal');
    }).mouseleave(function(){
    	$(this).find('div.info').fadeOut('fast');   	
    });

});


//pour l'ajout de la video en lightbox sur l'image dans la page franchise
 $(document).ready(function() {	
		// $("a#c9962 + div.bloctexte div.img img").mouseover(function () {
		$("a#c33744 + div.bloctexte div.img img").mouseover(function () {

			$(this).css('cursor', 'pointer');

		});
		// $("a#c9962 + div.bloctexte div.img img").click(function(event){
		$("a#c33744 + div.bloctexte div.img img").click(function(event){
			event.preventDefault();
			//on recherche si on est dans une url FR
			var langue = document.location.href.split("/fr/");
			//on prepare le contenu de la popin
			$('#content').append('<div id="content_popin_video" style="width: 552px;height: 346px;text-align:right;padding:20px;background:black;" ><div id="content_popin_video_flash" style="width:552px;height:336px;"></div><div style="padding-top: 7px;" ><a href="#" class="close" style="color:white;font-family:arial;">Fermer</a></div></div>');
			//si on est en langue FR
			if(langue.length > 1){ //pour langue FR
				//on charge le Flash a partir de l'url FR
				$('#content_popin_video_flash').flash({ flashvars: { vxml: 'fr/franchise-et-management/nos-contrats/contrat-de-franchise/mediavideo1/33744/flvPlayer.xml', imgURL: 'typo3temp/pics/event_manager_pullman_bercy_2fa45a7a36.jpg', autoPlay : true} ,src: '/fileadmin/templates/flash/LecteurFlash/player_FLV.swf',width: 552,height: 336, allowfullscreen: true, quality: "high", allowScriptAccess: "sameDomain", wmode: "transparent"  },{ version: 9 });
			}else{
				//sinon on charge le Flash a partir de l'url EN
				$('#content_popin_video_flash').flash({ flashvars: { vxml: 'en/franchise-and-management/our-contracts/franchise-agreement/mediavideo1/33745/flvPlayer.xml', imgURL: 'typo3temp/pics/event_manager_pullman_bercy_2fa45a7a36.jpg', autoPlay : true} ,src: '/fileadmin/templates/flash/LecteurFlash/player_FLV.swf',width: 552,height: 336, allowfullscreen: true, quality: "high", allowScriptAccess: "sameDomain", wmode: "transparent"  },{ version: 9 });
			}
			//on met le tout en lightbox
			$('#content_popin_video').lightbox_me({centered: true, destroyOnClose: true, overlayCSS: {background: 'black',opacity: .8}});
		});
}); 





//pour l'ajout du nombre d offre pour le compteur RH
 $(document).ready(function() {	
	$.get('fileadmin/feeds/rh_counter.xml',function(xml){
		var nb = $(xml).find("nb")[0].firstChild.nodeValue;
		$('#compteur-rh-nbroffre').html(nb);
	});
}); 
