/*
 * Fonctions lancées au démarrage
 */
function changeImg(relative) {
    $(".image").attr("src",relative+"/wm-public/tools/securimage/securimage_show.php?sid=" + Math.random());
    return false;
}

function lookup2event(inputString, relative, evt) {
    if(inputString.length == 0) {
        $("#suggestions2event").hide();
    }
    else {
        $.ajax({
            url:relative,
            async: false,
            type: "GET",
            data: "evt="+evt+"&queryString="+inputString,
            success: function(msg){
                $("#suggestions2event").show();
                $("#autoSuggestionsList2event").html(msg);
            },
            error:function(r, t, e) {alert(t)}
        });
    }
}

function lookup(inputString, relative) {
    if(inputString.length == 0) {
        $("#suggestions").hide();
    }
    else {
        $.post(relative, {queryString: ""+inputString+""}, function(data){
            if(data.length >0) {
                $("#suggestions").show();
                $("#autoSuggestionsList").html(data);
            }
        });
    }
}

function fill(thisValue) {
    $("#queryString").val(thisValue);
    $("#suggestions").hide();
}

function moreResults(page) {
            $("#paginator li").removeClass("current");
            $("#P"+page).addClass("current");
            $('.temp').slideUp(300);
            $('#temp'+page).slideDown('fast');

}


function disableEnterKey(e) {
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
     if(key == 13)
          return false;
     else
          return true;
}


//var gk=window.Event?1:0;

$(document).ready( function () {

    /*$(window).keyup(function(e) {

       var touche=gk?e.which:window.event.keyCode;

        if(touche == 13) {
            document.getElementById("contents").focus();
            return false;
        }
   });*/

    if ( $("#language-switcher").length ) {
        $("#language-switcher").slideDown(1000);
    }

    $(".wm-gallery a").lightBox({
        overlayBgColor: "#000",
        containerResizeSpeed: 350,
        txtImage: "",
        txtOf: "/"
    });

    $("a.wm-gallery").lightBox({
        overlayBgColor: "#000",
        containerResizeSpeed: 350,
        txtImage: "",
        txtOf: "/"
    });

    $(".wm-galleryNews a").lightBoxNews({
        overlayBgColor: "#000",
        containerResizeSpeed: 350,
        txtImage: "",
        txtOf: "/"
    });

    $("a.wm-galleryNews").lightBoxNews({
        overlayBgColor: "#000",
        containerResizeSpeed: 350,
        txtImage: "",
        txtOf: "/"
    });

    $(".wm-gallery a:nth-child(5n)").addClass("lastColumn");
    $(".wm-galleryNews a:nth-child(5n)").addClass("lastColumn");


    $(".txt-body").hide();
    $(".btnMore a").html($(".btnMore a").attr("show"));
    
    //on regarde si il faut afficher une news en particulier ou la premiere (si on en a pas précisé)
    if ($(".showthatone").length) {
        $(".showthatone .txt-body").show();
        $(".showthatone .btnMore a").html($(".btnMore a").attr("hide"));
    }
    else {
        //$(".txt-body:first").show();
        //$(".btnMore:first a").html($(".btnMore a").attr("hide"));
    }


    $(".btnMore a").click(
        function () {
            if ($(this).html() == $(this).attr("show")) {
                $(".txt-body").slideUp();
                $(".btnMore a").html($(".btnMore a").attr("show"));
                $(this).parent().prev(".txt-body").slideDown();
                $(this).html($(this).attr("hide"));
            }
            else {
                $(this).parent().prev(".txt-body").slideUp();
                $(this).html($(this).attr("show"));
            }
        }
    );



    //cette partie du code gère les "lire la suite" multiple au sein d'une page
    $("a.wm-readmore-multiple").html($("a.wm-readmore-multiple").attr("show"));

    $("a.wm-readmore-multiple").click(
        function () {
            $(this).hide();
            $('.wm-readmore-multiple-hidden:hidden:first').slideDown();
        }
    );

	// id #multimedia
	$("#multimedia li:nth-child(5n)").addClass("marginRightNone");


});
