/*
 * Fonctions lancées au démarrage
 */

function changeSecureImage(relative) {
    $("#captcha").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;
}


//Affiche plus de realisation dans le portfolio
//deleted by jda
/*function moreRealisation (start) {

    var Container  = $("#references");
    var filter = $("#active-filter").val();

    end = parseInt(start)+24;
    $("#more_rea").attr('rel',end);
    $("#loader").fadeIn("fast");

    var stocklastrea = '<li id="btnNext" class="btnNext">'+$("#btnNext").html()+'</li>';

    $("#btnNext").remove();

    $.ajax({
        type: "POST",
        url: urlConfig+"/wm-public/scripts/getMoreRea.ajax.php",
        dataType: "json",
        data: "start="+start+"&end="+end+"&filter="+filter,

        success: function(data){

                var i       = 0;

                for (i=0; i<data.length; i++) {
                    Container.append( '<li style="display:none" id="li-'+i+'"><a href="'+data[i].url+'"><img src="'+data[i].image1+'" alt="'+data[i].title+'" /><img class="logo" src="'+data[i].image2+'" alt="'+data[i].title+'" /></a></li>');
                }

                Container.append(stocklastrea);


                if(data.length<24)$(".btnNext").remove();
                
        },

        complete : function(data) {

            //On déroule le div
            $("li").slideDown("2400",function(){

                //ajoute le loader
                
            });
            $("#loader").fadeOut("fast");
             $(".logo").hide();

             $("#references li a").hover(
                function () {
                        $(this).children(".bgColor").fadeTo(300, 0.8);
                        $(this).children(".logo").fadeIn(500);
                },
                function () {
                        $(this).children(".bgColor").fadeOut(300);
                        $(this).children(".logo").fadeOut(500);
                }
            );

            $("#more_rea").click(function(){

               moreRealisation ($(this).attr("rel"));

           })

        }

    });
}
*/
//Affiche plus de realisation dans le portfolio
function moreNews (start) {

    var Container  = $("#load");

    end = parseInt(start)+24;
    $("#more_news").attr('rel',end);

    $.ajax({
        type: "POST",
        url: urlConfig+"/wm-public/scripts/getMoreNews.ajax.php",
        dataType: "json",
        data: "start="+start+"&end="+end,
        success: function(data){

                var content = "";
                var i       = 0;

                for (i=0; i<data.length; i++) {

                   content += '<div class="item '+data[i].classe+'"><span class="date">'+data[i].date+'</span><a href="'+data[i].url+'"><img src="'+data[i].image+'" alt="'+data[i].title+'"><span class="hover"></span></a><h2><a href="'+data[i].url+'">'+data[i].title+'</a></h2><p class="chapo">'+data[i].chapo+'</p></div>';

                }

                if(data.length<6)$(".btnNext").remove();

                Container.html(content);

                Container.slideDown("1500");

                Container.attr("id","");

                Container.append('<span id="load" style="display:none"></span>');

                 $(".hover").parent("a").mouseover (
                        function () {
                                $(this).children(".hover").animate({
                                         "opacity": ".80"
                                }, 300);
                        }
                );
                //mouseout
                $(".hover").parent("a").mouseout (
                        function () {
                                $(this).children(".hover").animate({
                                         "opacity": "0"
                                }, 300);
                        }
                );

                $("#news .item h2 a").mouseover (
                        function () {
                                $(this).parent().parent().children("a").children(".hover").animate({
                                         "opacity": ".80"
                                }, 300);
                        }
                );
                //mouseout
                $("#news .item h2 a").mouseout (
                        function () {
                                $(this).parent().parent().children("a").children(".hover").animate({
                                         "opacity": "0"
                                }, 300);
                        }
                );
        }
    });
}



//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($("#fonction").length>0) {

        $("#fonction").change(function(){

            val = $(this).val();

            linkHref = $("#"+val).attr("rel");

            window.location.href = linkHref;

        })

    }

    if($(".wm-gallery li a").length) {

        $("a[rel=gallery_link]").fancybox({
                'transitionIn'		: 'elastic',
                'transitionOut'		: 'elastic',
                'titlePosition'             : 'over',
                'overlayOpacity'            : 0.8,
                'overlayColor'          : '#fff',
                'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
                        return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
                }

        });
    }

    if($("a.wm-gallery").length) {

        $("a.wm-gallery").fancybox({
                'transitionIn'		: 'elastic',
                'transitionOut'		: 'elastic',
                'titlePosition'             : 'over',
                'overlayOpacity'            : 0.8,
                'overlayColor'          : '#fff',
                'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
                        return (title.length ?'<span id="fancybox-title-over">'+ title + '</span>' : '') ;
                }

        });
    }


    // -- delete par julian
   /*$("#more_rea").click(function(){
       
       moreRealisation ($(this).attr("rel"));

   })*/

   /*$("#more_news").click(function(){

       //moreNews ($(this).attr("rel")); -- changé par julian

   })*/
    // -- fin du delete

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

    $("#frm-contact input").focus(function()  {if(this.value == this.defaultValue) {this.value = "";}});
    $("#frm-contact input").blur(function()  {if(this.value == "") {this.value = this.defaultValue;}});
    $("#frm-contact textarea").focus(function()  {if(this.value == this.defaultValue) {this.value = "";}});
    $("#frm-contact textarea").blur(function()  {if(this.value == "") {this.value = this.defaultValue;}});



    /*
     * menu services
     */

    $("#our-services-menu li").hover(
        function () {$(this).children("ul").fadeIn(150);},
        function () {$(this).children("ul").fadeOut(150);}
    );

});
