$(document).ready(function(){
   $(".ajax_button_gauche a").click(loadpage); 
   
    $("ul#topmenu li.drop").hover(function() {//When trigger is clicked...
        //Following events are applied to the subnav itself (moving subnav up and down)
        $(this).parent().find("ul.subnav").slideDown('fast').show();
        //Drop down the subnav on click
        $(this).parent().hover(function() {
        }, function() {
            $(this).parent().find("ul.subnav").slideUp('slow');
            //When the mouse hovers out of the subnav, move it back up
        });
        //Following events are applied to the trigger (Hover events for the trigger)
    }).hover(function() {
        $(this).addClass("subhover");
        //On hover over, add class "subhover"
    }, function() {//On Hover Out
        $(this).removeClass("subhover");
        //On hover out, remove class "subhover"
    });
    
    //Communiques
    $("div#prev a").click(function() {
        $("div.communique").hide(500);
    });
    $("div#next a").click(function() {
        $("div.communique").hide(500);
    });
    $("#navigation").css({"display":"block"});
    $("div.date a").click(load_com);

    init_com();
    
    $("#video-index a img").mouseover(function(){$(this).attr("src", "/videos/preview/corpo_over.jpg")}); 
    $("#video-index a img").mouseout(function(){$(this).attr("src", "/videos/preview/corpo.jpg")});
});

function loadpage(ev) {
    ev.preventDefault();
    $(".active_left").removeClass("active_left");
    $(this).addClass("active_left");
    $("div#ajax_loader").load($(this).attr("href") + " #ajax_content", function(response, status, xhr){
                                                                                $("div#ajax_loader a.photosfancy").fancybox({
                                                                                        'speedIn'       :   200, 
                                                                                        'speedOut'      :   150, 
                                                                                        'overlayShow'   :   false
                                                                                    });});
}

//Communiques
function init_com() {
    /*Communiques*/
    $("#list_communiques").css({"width":"40000px"});
    $("#list_communiques h3.colapse").click(toggle_com);
    $("#list_communiques h3.colapse").css({"cursor":"pointer"});
    $(".content #list_communiques div.items").css({"margin-top":"7px",
                                                    "margin-bottom":"7px"
                                                    });
    $(".content #list_communiques div.items ul li").css({"border":"none"});
                                                    
    $(".communique").css("display","none");
    var scroll = $("#ajax_comm").scrollable({items : "#list_communiques", next:"#next a", prev:"#prev a"});
    
}

function toggle_com(ev) {
    if($(this).next("div.communique").css("display")=="none") {
        $(this).next("div.communique").show(500);
    } else {
        $(this).next("div.communique").hide(500);
    }
}

function load_com(ev) {
    ev.preventDefault();
    var href = $(this).attr("href").split("?"); 
    var lien = href[0];
    var annee = (href[1].split("="))[1];

    $("div#ajax_loader").load(lien + " #ajax_comm", {"date" : annee}, function(response, status, xhr){init_com();});
    
}
