// hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

jQuery(function($) {

    /**
            *   Gestion du carousel
            **/

    // Largeur d'un bouton
    var elementWidth = 194;

    // Ajout des boutons de defilement
    $('#barre-casino .zone').before('<div class="switch prev"><a href="#" title="Site pr&eacute;c&eacute;dent"><img src="http://navigation.casino.fr/images/defilement-gauche.png" alt="Site pr&eacute;c&eacute;dent" /></a></div>').after('<div class="switch next"><a href="#" title="Site suivant"><img src="http://navigation.casino.fr/images/defilement-droit.png" alt="Site suivant" /></a></div>');

    // Gestion de defilement arriere
    $('#barre-casino .prev').one("click", function barrePrev(){
        $('.element:last').clone().insertBefore('.element:last');
        $('.element:last').insertBefore('.element:first');

        var marginEnd = $('.boutons').css('marginLeft');
        var marginBegin = marginEnd.replace(/px/, '');
        marginBegin = marginBegin-elementWidth;
        marginBegin = marginBegin+'px';

        $('.boutons').css('marginLeft', marginBegin);
        $('.boutons').animate({"marginLeft": marginEnd}, "slow", function() {
            $('.element:last').remove();
            $('#barre-casino .prev').one('click', barrePrev);
        });
        return false;
    });

    // Gestion de defilement avant
    $('#barre-casino .next').one("click", function barreNext(){
        $('.element:first').clone().insertAfter('.element:first');
        $('.element:first').insertAfter('.element:last');

        var marginEnd = ($('.boutons').css('marginLeft'));
        var marginBegin = marginEnd.replace(/px/, '');
        marginBegin = marginBegin-elementWidth;
        marginBegin = marginBegin+'px';

        $('.boutons').animate({"marginLeft": marginBegin}, "slow", function() {
            $('.boutons').css('marginLeft', marginEnd);
            $('.element:first').remove();
            $('#barre-casino .next').one('click', barreNext);
        });
        return false;
    });


    /**
            *   Gestion de la descritpion detaillee
            **/
            
    $('#barre-casino .detail').bind("click", function(){
        window.location.href = $(this).prev('a').attr('href');
    });

    $('#barre-casino .element').hoverIntent({
        sensitivity: 7, interval: 100, over: barreShowNav, timeout: 200, out: barreHideNav
    });
    
    function barreShowNav() {
        //$(this).addClass('hover').find('.detail').show('slow');
        //$(this).addClass('hover').find('.detail').show();
        //$(this).addClass('hover').find('.detail').show('fast');
        $(this).addClass('hover').find('.detail').slideDown('slow');
        //$(this).addClass('hover').find('.detail').slideDown();
        //$(this).addClass('hover').find('.detail').slideDown('fast');
        //$(this).addClass('hover').find('.detail').fadeIn('slow');
        //$(this).addClass('hover').find('.detail').fadeIn();
        //$(this).addClass('hover').find('.detail').fadeIn('fast');
    }
    function barreHideNav() {
        //$(this).removeClass('hover').find('.detail').hide('slow');
        //$(this).removeClass('hover').find('.detail').hide();
        //$(this).removeClass('hover').find('.detail').hide('fast');
        //$(this).removeClass('hover').find('.detail').slideUp('slow');
        //$(this).removeClass('hover').find('.detail').slideUp();
        $(this).removeClass('hover').find('.detail').slideUp('fast');
        //$(this).removeClass('hover').find('.detail').fadeOut('slow');
        //$(this).removeClass('hover').find('.detail').fadeOut();
        //$(this).removeClass('hover').find('.detail').fadeOut('fast');
        
    }
    
    
    $('#barre-casino .element a').bind("focus", function(){
        $(this).parent().addClass('hover').find('.detail').show();
    });
    $('#barre-casino .element a').bind("blur", function(){
        $(this).parent().removeClass('hover').find('.detail').hide();
    });

});
