var justDisplay = false;
var justDisplay2 = true;

function onHover(el)
{
    //decoupe "map" de la class
    var nompays = $(el).attr("class");
    nompays = nompays.substring(3,40);
		
    if($.browser.msie && $.browser.version=="6.0") {
	//uniquement IE6
	justDisplay2 = !justDisplay2;
	if(!justDisplay2 || !$.browser.msie) {
	    $(".mapCartesImplantations img").remove();
	    $(".mapCartesImplantations").html('<img src="img/carte_nos_implantation_'+nompays.toLowerCase()+'.jpg" alt="" usemap="#carte" />');
	}
	else
	    justDisplay2 = !justDisplay2;

    } else {
	//tout sauf IE6

	$("#roll" + nompays).show();
	justDisplay2 = !justDisplay2;

    }

}

function onOut(el)
{
    if($.browser.msie && $.browser.version=="6.0") {
	//uniquement IE6
	$(".mapCartesImplantations img").remove();
	$(".mapCartesImplantations").html('<img src="img/carte_nos_implantation_complete.jpg" alt="" usemap="#carte" />');
	justDisplay2 = !justDisplay2;
    } else {
	//tout sauf IE6

	//decoupe "map" de la class
	var nompays = $(el).attr("class");
	nompays = nompays.substring(3,40);
	
	$("#roll" + nompays).hide();
	justDisplay2 = !justDisplay2;

    }
}

function onClick(el)
{ 
    //var title = ($(el).attr("title") != undefined) ? $(el).attr("title") : el;
    // si proviens de la redirection
    if ($(el).attr("class") == undefined) {
	
	var nompays = el;
	
    } else {
	// si click direct sur pays
	var nompays = $(el).attr("class");
	nompays = nompays.substring(3,40);
	
    }
	
    $(".conteneurblocPays").hide();
    $(".blocFrance01").hide();
    $(".blocFrance02").hide();
	$(".blocFrance03").hide();
    $("#roll" + nompays).show();
    $("#" + nompays).toggle();
    justDisplay = true;
}

function onClickFrance()
{
    $(".conteneurblocPays").hide();
    $(".blocFrance02").hide();
	$(".blocFrance03").hide();
    $(".blocFrance01").show();
    justDisplay = true;
}
 
$(document).ready(function () {
	
    $("#slider").easySlider({
	auto: true,
        pause: 5000,
	continuous: true
    });
	
    ////////// Home - DEBUT ///////////
    if($.browser.msie && $.browser.version=="6.0") {
	$(".acacherssie6").remove();
    }
    ////////// Home - FIN ///////////
	
    ////////// Carte Nos Implantations - DEBUT ///////////
	
    //pour ie6 change l'image transparente en carte de base
    if($.browser.msie && $.browser.version=="6.0") {

	$(".mapCartesImplantations img").remove();
	$(".mapCartesImplantations").html('<img src="img/carte_nos_implantation_complete.jpg" alt="" usemap="#carte" />');

    }
    //fonction pour la carte nos Implantations - exception fenetre 2 de france
    $(".lien1").click(

		function () {
			$(".conteneurblocPays").hide();
			$(".blocFrance02").toggle();
			$(".blocFrance01").hide();
			justDisplay = false;
		}
	);
	
	$(".lien2").click(

		function () {
			$(".conteneurblocPays").hide();
			$(".blocFrance03").toggle();
			$(".blocFrance01").hide();
			justDisplay = false;
		}
	);
	
    var nom_url = window.location.pathname;
    var nom_url2 = window.location.search;
    var  reg=new  RegExp("[ /]+", "g");
    var  reg2=new  RegExp("[ =]+", "g");
	
    //if(nom_url.search(/implantations/i) > 0) {
		
    var  tableau=nom_url.split(reg);
    var  tableau2=nom_url2.split(reg2);
    tableau.reverse();
    tableau2.reverse();
    if(tableau[0] == undefined)
	tableau = ["accueil"];
    for  (var  i=0; i<1; i++)  {

	var debut = tableau[i].substr(0, 1).toUpperCase();
	var fin = tableau[i].substring(1, 25);
	var debut2 = tableau2[i].substr(0, 1).toUpperCase();
	var fin2 = tableau2[i].substring(1, 25);
	onClick(debut+fin);
	if (nom_url2 != '') onClick(debut2+fin2);
    }
				
    //}
	
    // click sur carte qui ferme toutes les fenetres
    $(".mapCartesImplantations").click(function () {
	if(!justDisplay || !$.browser.msie) {
	    $(".conteneurblocPays").hide();
	    $(".blocFrance01").hide();
	    $(".blocFrance02").hide();
		$(".blocFrance03").hide();
	    $(".rollCartes").hide();
		
	}
	else
	    justDisplay = !justDisplay;
    });
	
    ////////// Carte Nos Implantations - FIN ///////////

    //////// Fonction pour le sous menu g�n�ral - DEBUT //////////
    //cache les sous menu
    $("div.sub_menu").css("display","none");

    //supprime une div doublon si javascript activ�
    $("div#slides").insertBefore("div#conteneur_ssjs");
    $("div#conteneur_ssjs").remove();

    //animation pour les sous menu
    $("div.navigation ul li").hover(

	function () {
	    //empeche la repetition d'animations
	    if ($(this).children("div.sub_menu").is(':animated')) {

	    } else {
		$(this).children("div.sub_menu").fadeIn('normal');
	    }
	},

	function () {
	    $(this).children("div.sub_menu").fadeOut('normal');
	}

	);
    //////// Fonction pour le sous menu g�n�ral - FIN //////////


    //target blank - respect w3c
    $('a[rel=external]').attr('target', '_blank');
	
    //////////////// tooltip calendrier - DEBUT  //////////////////
    $('.calendrier_actus').tooltip({
	track: true,
	delay: 0,
	showURL: false,
	showBody: " - ",
	extraClass: "fancy",
	fixPNG: true,
	opacity: 0.65,
	top: -30
    });
    //////////////// tooltip calendrier - FIN  //////////////////
	
    return false;

});

//***** Fonction slider - DEBUT *****/
$(function() {
    $("div#controller").jFlow({
	slides: "#slides",
	width: "698px"
    });
});
//***** Fonction slider - FIN *****/


// Autocomplétion ajax du moteur de recherche
function lookup(inputString) {
    if(inputString.length < 4)
    {
	// Hide the suggestion box.
	$('#suggestions').hide();
    }
    else
    {
	$.post("rpcSearch.php", {
	    queryString: ""+inputString+""
	}, function(data){
	    if(data.length >0) {
		$('#suggestions').show();
		$('#autoSuggestionsList').html(data);
	    }
	    else
	    {
		$('#suggestions').hide();
		$('#autoSuggestionsList').html("");
	    }
	});
    }
}

// Glossaire en ajax
function rpcGlossary(kwords, leasing, factoring, letter, curPage)
{
   
    $.post("rpcGlossary.php", {
	kwords: kwords,
	leasing: leasing,
	factoring: factoring,
	letter: letter,
	curPage: curPage
    }, function(data){
	$('#glossary').html(data);
    },
    "text");


}

// Remplace les caractères accentués d'une chaîne par leur voyelles correspondante, remplace les caractères spéciaux par un "_"
function cleanTxt(txt)
{
    //pagetitle = pagetitle.toLowerCase();
    txt = txt.replace(/[êéèë]/g,"e");
    txt = txt.replace(/[îï]/g,"i");
    txt = txt.replace(/[ôö]/g,"o");
    txt = txt.replace(/[àâ]/g,"a");
    txt = txt.replace(/[ùüû]/g,"u");
    txt = txt.replace(/[^a-z,^A-Z,0-9]/g,"_");
    return txt;
}


$(document).ready(function(){

    $('form.jqtransform').jqTransform({
	imgPath:'jqtransformplugin/img/'
    });

    // Affiche / masque "rechercher" dans le champ "rechercher"
    // du formulaire de recherche
    $("#rechercher_id").focus(function(){
	$(this).val( $(this).val() == $(this)[0].defaultValue ? '' : $(this).val() );
    });
    $("#rechercher_id").blur(function(){
	$(this).val( $.trim( $(this).val() ).length==0 ? $(this)[0].defaultValue : $(this).val() );
    });

    // Affiche / masque "rechercher" dans le champ "rechercher"
    // du formulaire de recherche de news
    $("#rechercher_actus_id").focus(function(){
	$(this).val( $(this).val() == $(this)[0].defaultValue ? '' : $(this).val() );
    });
    $("#rechercher_actus_id").blur(function(){
	$(this).val( $.trim( $(this).val() ).length==0 ? $(this)[0].defaultValue : $(this).val() );
    });

    // Correctif IE6 du glossaire alphabet
    $(".lettres_repertoire ul li").hover(
	function(){ // Sur le onmouseover
	    $(this).css("paddingLeft", "20px");
	    $(this).css("background", "#79a92e");
	    $(this).children("a").css("color", "#ffffff");
	},
	function(){ // Sur le onmouseout
	    $(this).css("paddingLeft", "10px");
	    $(this).css("background", "transparent");
	    $(this).children("a").css("color", "#666666");
	}
	);

    $("div.lettres_repertoire ul li a").click(function(){
	rpcGlossary('', '', '', $(this).text(), '');
    });

    // Effet accordéon sur des pages de contenus
    $("h2.title_11").next('.box_questions_facturages').hide();

    $("h2.title_11").click( function () {
	if( $(this).is('.open_11') ) {
	    //$(this).next('p').next('.box_questions_facturages').hide("slide", { direction: "up" }, "slow");
	    $(this).next('.box_questions_facturages').slideToggle();
	    $(this).removeClass('open_11');
	} else {
	    $(this).addClass('open_11');
	    $(this).next('.box_questions_facturages').slideToggle();
	// $(this).next('p').next('.box_questions_facturages').show("slide", { direction: "up" }, "slow");
	}
	return false;
    });

    //Effet accordéon sur des pages gouvernance
    $("div.personnel_gouvernance").next('.box_personnel_gouvernance').hide();

    $("div.personnel_gouvernance").click( function () {
	if( $(this).is('.open_11') ) {
	    $(this).next('.box_personnel_gouvernance').slideToggle();
	    $(this).removeClass('open_11');
	} else {
	    $(this).addClass('open_11');
	    $(this).next('.box_personnel_gouvernance').slideToggle();
	}
	return false;
    });

});
