// JavaScript Document

$(document).ready(function() {
   Page_Init();
 });


function Page_Init(){

    Cufon_Init();
    Window_Init();
    Menu_Init();
    Top_Init();

    try {
        $("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'facebook', opacity: 0.2 });
    }
    catch(e){
    }

    $('.Slider_Container').alpSlider({
        speed: 1200,
        direction: 'horizontal',
        animation: 'fadeIn',
        animationItemDelay: 100,
        wrapperClass: 'Slider_Wrapper',
        itemClass: 'Slider_Item',
        prevNextIs: false,
        autoplay: true,
        autoplayTime: 5000
    });
}

function Cufon_Init() {
   // Cufon.replace('.Century_Gothic', { fontFamily: 'Century_Gothic' });
}

function Window_Init() {
    var Hauteur = 0;
    $(window).load(function () {
        //Agrandie la page si le contenu est plus petit que l'écran
        if (parseInt($('body').outerHeight()) < parseInt(document.documentElement.clientHeight)) {
            Hauteur = parseInt(document.documentElement.clientHeight) - parseInt($('body').outerHeight());
            $('#Hauteur').height(Hauteur + 'px');
        }

        //Si page d'accueil ou page avec un post-it en absolute on redimensionne
        if ($('#PostIt_Container').length > 0) {

            var PostIt_Bottom = $('#PostIt_Container').offset().top + $('#PostIt_Container').outerHeight(true);
            var Bottom_Bottom = $('#Bottom').offset().top + $('#Bottom').outerHeight(true);
            if (PostIt_Bottom >= Bottom_Bottom) {

                Hauteur = parseInt($('#Hauteur').height(), 10) + (PostIt_Bottom - Bottom_Bottom)
                //Hauteur += $('#Bottom').outerHeight(true);
                $('#Hauteur').height(Hauteur + 'px');
            }
        }
    });
}

function Menu_Init() {

    if ($('.Menu_Item.Actif').find('.SsMenu_Container').length > 0) {
        $('.Menu_Item.Actif').find('.SsMenu_Container').show();
        $('.Menu_Item.Actif').find('.SsMenu_Container').addClass('Open');
    }

    $('.Menu_Item.SsMenu .Menu_Link').click(
        function () {
            if ($(this).parent().find('.SsMenu_Container').length > 0) {
                if ($(this).parent().find('.SsMenu_Container').hasClass("Open") == true) {
                    $(this).parent().find('.SsMenu_Container').stop(true, true).slideUp(350);
                    $(this).parent().find('.SsMenu_Container').removeClass('Open');

                }
                else {
                    $('.Menu_Item').find('.SsMenu_Container').stop(true, true).slideUp(350);
                    $(this).parent().find('.SsMenu_Container').stop(true, true).slideDown(500);
                    $(this).parent().find('.SsMenu_Container').addClass('Open');
                }
            }
            return false;
        }
    );

    }

    function Top_Init() {
        if ($('.Top_Link').length > 0) {
            $('.Top_Link').hover(
                function () {
                    $(this).find('.Forme_01').stop(true, true).animate({ left: '0px' }, 250);
                },
                function () {
                    $(this).find('.Forme_01').stop(true, true).animate({ left: '-40px' }, 250);
                }
            );   
        }
    }
