﻿//
// Left Menu : Permet d'ajouter une class sur la div "leftSidebarRayonTitle" pour les rayons qui doivent s'afficher sur 2 lignes
// La classe "twoLinesRayonTitle" permet ceci.


(function($) {

    //History Navigation
    function historyDisplay() {
        $(".historyDisplayBlock").hide();
        $(".displayPdtList li").each(function() {
            if ($(this).hasClass("active")) {
                var urlBlock = $(this).find("a").attr("rel");
                $("#" + urlBlock).show();
            }
            $(this).find("a").hover(function() {
                $(this).parent("li").siblings().removeClass("active");
                $(this).parent("li").addClass("active");
                var urlBlockDisplay = $(this).attr("rel");
                $("#" + urlBlockDisplay).show();
                $("#" + urlBlockDisplay).siblings().hide();
            }, function() {
            });
        });
    }


    /**
    * Empty some fields and replace with a default value on load/focus
    * 
    * @todo base that on placeholder attribute to allow HTML5 fallback and nice degradation
    * @todo documentation
    * 
    * @author  Thomas Parisot <tparisot@clever-age.com>
    * @version 1.0
    */
    $.fn.emptyValue = function(inputValue) {
        var value = inputValue;

        return this
	   
    };


    /****** ! DOCUMENT READY EVENT ******/
    $(function() {
        historyDisplay();
        $("input.inputMailValue").emptyValue("Votre email");

        // Main Navigation
        // Nouvelle gestion des onglets et overlayers tetiere  
        $('.mainNavItem').each(function(i) {
            var $this = $(this);

            //Mouse hover
            $this.hover(function() {
                if ($this.hasClass('jqNoOverLayer')) {
                    $this.find('.universLink').addClass('currentLink')
                                        .addClass('activeLink');
                }
                else {
                    $this.find('.universLink').removeClass('currentLink')
                                  .addClass('activeLink');
                    $this.find('.navLayer').show();
                }
            },
        function() {
            $this.find('.navLayer').hide();
            if ($this.hasClass('jqCurrentLink')) {
                $this.find('.universLink').addClass('currentLink');
            } else {
                $this.find('.universLink').removeClass('activeLink');
            }

            if ($this.hasClass('jqNoOverLayer')) {
                $this.find('.universLink').removeClass('currentLink')
                                        .removeClass('activeLink');
            }
        });
        });





        /**
        * Fix the css z-index bug on Ie7 and previous version
        */
        if (typeof $.fn.fixZIndex != 'undefined') {
            $('.jq-fixZIndex').fixZIndex();
        }
        /**
        * Infobulle
        *
        * to call the infobull, put the class .infobulle in the link where you want it appear
        * 
        * @see                 js/layout_R2.js
        * 
        * <code>
        *   <span class="infobulle"></span>
        * </code>
        *
        * @author  Nicolas Goueset <nicolas.goueset@cdiscount.com>
        * @version 1.0
        */
        $(".callinfobulle").mouseover(function(){
            if($(this).attr("title")=="") return false;
        
            $("body").append('<span class="infobulle"></span>');
            var bulle = $(".infobulle:last");
            bulle.append($(this).attr("title"));
            $(this).attr("title","");
            var posTop = $(this).offset().top-$(this).height();
            var posLeft = $(this).offset().left+$(this).width()/2-bulle.width()/2;
            bulle.css({
                left:posLeft,
                top:posTop-7,
                opacity:0
            });
            bulle.animate({
                top:posTop-7,
                opacity:0.99
            });
        });

        $(".callinfobulle").mouseleave(function(){
            var bulle = $(".infobulle:last");
            $(this).attr("title",bulle.text());
            bulle.animate(
                {
                    top:bulle.offset().top+7,
                    opacity:0
                },
                50,
                "linear",
                function(){
                    bulle.remove();  
                }
            );
        });
    });


    //
})(jQuery);
//

