function goLocation(theObject) {
    if ($(theObject).find("a.biglink").attr('target') == "_blank") {
        window.open($(theObject).find("a.biglink").attr("href"), "_blank");
    }
    else {
        window.location=$(theObject).find("a.biglink").attr("href");
    }
    
    //alert($(theObject).find("a.biglink").attr("href"));
    return false;
}

$(document).ready(function() {
    /*
     * Police
     **********************************/
    Cufon.replace('#menu ul, #footerAdresse h2, #footerAdresse h3, #footerAdresse p, #footerBranche p, #footerRight h2, #distributeur, #contact .menu li a, #footerCategorie ul li a, .libelle-cat h1, .libelle-cat h2, #liste-home #filtre h3, #liste-home #focus h3, #liste-home #focus ul li a, #accueil, #familleproduit_ente1 #barre-pied h2, #barre-pied #title h1, #familleproduit_liste ul li a, #plan-du-site',  {
        fontFamily: 'din',
        hover: true
    });
    
    
    /*
     * Sélecteur de langue + categorie en home
     *********************************/
    $('select.regularSelect').tzSelect();
    
    
    /*
     * Menu principal
     *********************************/
    $('#menu > div > ul > li').hoverIntent(function() {
        $('#menu > div > ul li').removeClass('hover');
        $(this).addClass('hover');
        
        $('#menu > div > ul li:not(.hover) ul').fadeOut();
        
        $(this).find('ul').fadeIn();
    }, function() {});
    
    $('#menu > div > ul > li ul').hoverIntent(function() {}, function() {
        $(this).fadeOut();
    });
    
    
    /*
     * Menu Pied Catégorie
     ********************************/
    $('#footerCategorie ul li').hover(function() {
        $(this).prepend('<div>&nbsp;</div>');
        $(this).find('div').animate({width: "190px"}, 400);
    }, function() {
        $(this).find('div').animate({width: "0px"}, 400, function() {
            $(this).remove();
        });
    });
    
    
    /*
     * Bloc produit (présent sur Home + qui sommes nous)
     ********************************/
    $("#bloc-produits > li:not(.large, .medium)").click(function(){ // clic sur un bloc
        goLocation(this);
    });
    $("#bloc-produits .libelle-cat, #bloc-produits ul.branche > li").css('display', 'none');
    $('#bloc-produits > li').mouseover(function() {
        $(this).find(".visuel").animate({width: '180px', height: '180px', top: '10px', left: '10px'}, 200);

        //pas de FadeIn sur IE
        if($.browser.msie) {
            $(this).find(".libelle-cat").slideDown();
            $(this).find('.branche > li:eq(0)').show();
            $(this).find('.branche > li:eq(1)').delay(100).show();
            $(this).find('.branche > li:eq(2)').delay(200).show();
            $(this).find('.branche > li:eq(3)').delay(300).show();
            $(this).find('.branche > li:eq(4)').delay(400).show();
        }
        else {
            $(this).find(".libelle-cat").fadeIn();
            $(this).find('.branche > li:eq(0)').fadeIn();
            $(this).find('.branche > li:eq(1)').delay(100).fadeIn();
            $(this).find('.branche > li:eq(2)').delay(200).fadeIn();
            $(this).find('.branche > li:eq(3)').delay(300).fadeIn();
            $(this).find('.branche > li:eq(4)').delay(400).fadeIn();
        }
    });
    $('#bloc-produits > li').mouseout(function() {
        $(this).find(".visuel").animate({width: '200px', height: '200px', top: '0px', left: '0px'}, 200);
                
        //pas de FadeOut sur IE
        if($.browser.msie) {
            $(this).find(".libelle-cat").slideUp();
            $(this).find('.branche > li:eq(4)').hide();
            $(this).find('.branche > li:eq(3)').delay(100).hide();
            $(this).find('.branche > li:eq(2)').delay(200).hide();
            $(this).find('.branche > li:eq(1)').delay(300).hide();
            $(this).find('.branche > li:eq(0)').delay(400).hide();
        }
        else {
            $(this).find(".libelle-cat").fadeOut();
            $(this).find('.branche > li:eq(4)').fadeOut();
            $(this).find('.branche > li:eq(3)').delay(100).fadeOut();
            $(this).find('.branche > li:eq(2)').delay(200).fadeOut();
            $(this).find('.branche > li:eq(1)').delay(300).fadeOut();
            $(this).find('.branche > li:eq(0)').delay(400).fadeOut();
        }

    });
    
    
    /*
     * Home
     ********************************/
    //Caroussel Focus
    $('#focus ul').width($('#focus ul li').length * $('#focus ul li').width() + 15);
    
    $('#focus ul').jcarousel({
        scroll : 1
    });
    
    
    /*
     * Page famille produit
     *******************************/
    //Animation produit**********************************
    $('#familleproduit_liste ul li a.group').fancybox({
        'transitionIn'  :   'elastic',
        'transitionOut' :   'elastic',
        'speedIn'       :   600, 
        'speedOut'      :   200, 
        'overlayShow'   :   false,
        'hideOnOverlayClick' : true
    });
    $('#familleproduit_liste ul li a div.zoom').css('display', 'none');
    $('#familleproduit_liste ul li div.zone-sensibilite').mouseover(function() {
        $(this).parent().find('div.zoom').fadeIn();
        $(this).parent().animate({width: '180px', height: '180px', top: '10px', left: '10px'}, 200);
        $(this).parent().find('img').animate({width: '180px', height: '155px'}, 200);
    });
    $('#familleproduit_liste ul li div.zone-sensibilite').mouseout(function() {
        $(this).parent().find('div.zoom').fadeOut();
        $(this).parent().animate({width: '200px', height: '200px', top: '0px', left: '0px'}, 200);
        $(this).parent().find('img').animate({width: '200px', height: '175px'}, 200);
    });
    
    //Animation sidebar**********************************
    $("#sidebar > ul > li").click(function(){ // clic sur un bloc
        goLocation(this);
    });
    $("#sidebar .libelle-cat").css('display', 'none');
    $('#sidebar > ul > li').mouseover(function() {
        $(this).find(".visuel").animate({width: '180px', height: '180px', top: '10px', left: '10px'}, 200);
        $(this).find(".libelle-cat").fadeIn();
    });
    $('#sidebar > ul > li').mouseout(function() {
        $(this).find(".visuel").animate({width: '200px', height: '200px', top: '0px', left: '0px'}, 200);
        $(this).find(".libelle-cat").fadeOut();
    });
});
