

/*****************************MESSAGE ATTENTE********************************/

function MessageAttente() {

$get('lbl_100').innerHTML = "<div id=DIV_LigneArticleCommentaire></div><div id='DIV2_LigneArticleCommentaire' style='TEXT-ALIGN:CENTER; overflow:hidden'><center><img border='0' src='Image/WEB/loading.gif' class='ImgLoading100' /><br><br>Chargement en cours<br>Merci de patienter.</center></div>";
showTextLightbox(150, 150, true);

}

/* checked Adresse compte
--------------------------------*/
function CheckAdresse(Adresse1, Adresse2, Adresse3) {
var mValid = false;
try {
if($('#' + Adresse1).val() !='' ){mValid = true;}
if($('#' + Adresse2).val() !=''){mValid = true;}
if($('#' + Adresse3).val() !='' ){mValid = true;} 
return mValid;
}
catch(ex){return false;}
}

/* repositionner titre page
--------------------------------*/
$(document).ready(function() {
    $('#bloc_titre_page').append($('#TitreHead'));
});

/* Fonction de debugage InfoDev
--------------------------------*/
function InfoDev(message, cumul) { if (!$('#InfoDev').length) { $('BODY').append('<div id="InfoDev" style="position: absolute; top:0; left:0; font-size:15px; color:#fff"></div>'); } cumul ? $('#InfoDev').append("<br>" + message) : $('#InfoDev').html(message); }


/* lihoverFix
--------------------------------*/
$(document).ready(function() {
    $('.lignes li, .vignettes li, #bloc_meilleursVentes li').hover(function() { $(this).addClass("hover"); }, function() { $(this).removeClass("hover"); });
});

/* mini panier
--------------------------------*/
$(document).ready(function () {
    $('.mini_panier li').qtip({
        content: $("#mini_panier_detail", this).html(),
        style: { width: { max: 420 }, border: {width: 1, radius:3, color: '#D5006E' } },
        position: { corner: { target: 'bottomRight', tooltip: 'topRight' }, adjust: { x: 5, y: 0} },
        hide: { fixed: true }
    });
    $('.mini_panier').hover(function () { //quand on arrive sur la zone on update le panier au cas ou il a ete rempli
        $('.mini_panier li').qtip("api").updateContent($("#mini_panier_detail", this).html());
        if ($("#mini_panier_detail").html().length > 25) { $('.mini_panier li').qtip("api").updateWidth(410); }
    });
});

/* bullesCarousel : le carousel + les bulles
--------------------------------*/
(function($) {
    $.fn.bullesCarousel = function(options) {

        var defaults = {
            mini: 3, // nb mini d'elements dans le caroussel
            display: 5
        };

        var options = $.extend(defaults, options);        
        if ($('.vignettes li', this).length > (options.mini - 1)) {
            /*caroussel*/
            $(this).tinycarousel({ display: options.display });

            /*bulles*/
            $('.vignettes li', this).addClass('vignetteLeft');
            $('.vignettes li:nth-child(5n), .vignettes li:nth-child(5n-1)', this).removeClass('vignetteLeft').addClass('vignetteRight');
            $('.vignettes li.vignetteLeft', this).each(function() {
                $(this).qtip({
                    content: $(".bulle", this).html(),
                    style: { tip: true, border: { radius: 5 }, name: 'light' }, // Give it a crea mstyle to make it stand out
                    position: { corner: { tooltip: 'leftMiddle', target: 'rightMiddle'} },
                    hide: { fixed: true }
                });
            });
            $('li.vignetteRight', this).each(function() {
                $(this).qtip({
                    content: $(".bulle", this).html(),
                    style: { tip: true, border: { radius: 5 }, name: 'light' }, // Give it a crea mstyle to make it stand out
                    position: { corner: { tooltip: 'rightMiddle', target: 'leftMiddle'} },
                    hide: { fixed: true }
                });
            });
        }
        else {
            $(this).hide();
        }
    };
})(jQuery);


/* Ajouter aux favoris
--------------------------------*/

$(document).ready(function () {
    // add a "rel" attrib if Opera 7+
    if (window.opera) {
        if ($("a.jqbookmark").attr("rel") != "") {
            $("a.jqbookmark").attr("rel", "sidebar");
        }
    }

    $("a.jqbookmark").click(function (event) {
        event.preventDefault();
        var url = this.href;
        var title = this.title;

        if (window.sidebar) { // Mozilla Firefox Bookmark
            window.sidebar.addPanel(title, url, "");
        } else if (window.external) { // IE Favorite
            window.external.AddFavorite(url, title);
        } else if (window.opera) { // Opera 7+
            return false; // do nothing
        } else {
            alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
        }

    });
}); 


/* Par contexte
--------------------------------*/

$(document).ready(function() {
    var contexte = $("#H_MEM_CONTEXTE").val();
    switch (contexte) {

        case "Accueil": /*############################ CONTEXTE ACCUEIL ###################################*/
            /******Caroussel******/

            $("#slide_AccueilFocus").bullesCarousel({ mini: 3 }); //mini: 3 articles minimumus

            break;
        case "View": /*############################### CONTEXTE VIEW ######################################*/

            /******Infobule sur bouton panier inactif ou choix taille ******/
            $('#bloc_DA_acheter .ajout_panier_disable, #bloc_list_article .ajout_panier_disable').each(function () {
                $(this).qtip({
                    content: 'Cet article est actuellement indisponible',
                    style: { tip: true, border: { radius: 5 }, name: 'dark' }, // Give it a crea mstyle to make it stand out
                    position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle'} }
                });
            });
            if ($('#bloc_DA_vignettes li').length < 2) { $('#bloc_DA_vignettes').remove(); }
            if ($('#bloc_noeud_description span').length) { if ($('#bloc_noeud_description span').html().length < 3) { $('#bloc_noeud_description').remove(); } }
            /****** Boite à onglets ******/

            $("#bloc_DA_onglet_content .bloc div[id^='sub_'] > div[id^='lbl_'] > div[id^='lbl_']").each(function(i) { if ($(this).html().length < 3) { $(this).parent().parent().remove(); } }); //enlever contenus vides
            $("#bloc_DA_onglet_content .bloc").each(function(i) { if ($(this).html().length < 5) { $("#bloc_DA_onglet_menu li:eq(" + i + ")").addClass("delete"); $(this).remove(); } });
            $("#bloc_DA_onglet_menu li.delete").each(function() { $(this).remove(); });
            $("#bloc_DA_onglet_menu").facileTabs({ targetElements: ".bloc" });    //lancer boite à onglets

            /******Caroussel******/

            $('#slide_listes .titre').html('S&eacute;lection ' + $('#bloc_noeud_titre h2').html());
            $("#slide_listes").bullesCarousel({ mini: 3 });
            $("#slide_fils").bullesCarousel({ mini: 1 });
            $("#slide_freres").bullesCarousel({ mini: 1 });

            $("#bloc_DA_vignettes").tinycarousel({ display: 3, viewport: '#detailArticl_Galr', overview: '#detailArticl_Galr ul' });
            $('#bloc_DA_photos a').hover(function() { $('#bloc_DA_photos .zoom').show(); }, function() { $('#bloc_DA_photos .zoom').hide(); });


            /****** images en grand sur hover ******/
            $('img[tooltip]').each(function() {
                $(this).qtip({
                    content: '<img src="I-Moyenne-' + $(this).attr('tooltip') + '-.net.jpg" />', // Use the tooltip attribute of the element for the content
                    position: { corner: { tooltip: 'leftMiddle', target: 'rightMiddle'} },
                    style: { tip: true, name: 'light', width: 250 }
                });
            });
            /******* enlever txt RESUME si vide*******/
            $('.lignes .text_court').each(function() {
                if ($('.txt', this).html().length < 3) { $(this).hide(); }
            });
			
			/***** Video ******/

            $('.Video').click(function () {

                $('body').append('<div id="video"></div>');
                var flashVideo = $(this).attr('rel');

                $.colorbox({
                    inline: true,
                    href: "#video",
                    initialWidth: 50,
                    innerWidth: 660,
                    innerHeight: 390,
                    onCleanup: function () { $('#video').remove(); }
                });

                jwplayer("video").setup({
                    autostart: true,
                    controlbar: "none",
                    file: "/File.aspx?FileName=" + flashVideo,
                    flashplayer: "/flash/player.swf", volume: 80, width: 660, height: 390
                });

                return false;
            });

            break;
        case "PageStatique": /*####################### CONTEXTE PAGES SATTIQUES ###########################*/
        
        $("#slide_panier").bullesCarousel({ mini: 3 }); //mini: 3 articles minimumus

        /****commande directe*****/
            function CommandeDirecte() {
                document.getElementById('lbl_005').innerHTML = '<center><img border=0 src=Image/WEB/loading.gif /></center>';
                AjaxAjoutPanierExpress(document.getElementById('ReferenceArticle').value, document.getElementById('QuantiteArticle').value);
                $("#bloc_panier_compte #elemt1").addClass("minipaniervisible");
                document.getElementById('ReferenceArticle').value = "";
                $('#ReferenceArticle').focus();
                document.getElementById('QuantiteArticle').value = "1";
            }
            //remplissage au clavier
            if ($('#retourAjoutPanierExpress').length != 0) {
                $("#bloc_panier_compte #elemt1").addClass("minipaniervisible");
                $('#ReferenceArticle').attr('autocomplete', 'off');
                $('#ReferenceArticle, #QuantiteArticle').keydown(function (e) {
                    switch (e.keyCode) {
                        case 13:
                            CommandeDirecte(); return false;
                            break;
                    }
                });
                $('#detailArticl_bts a').click(
                            function () {
                                CommandeDirecte(); return false;
                            })
            }

        break
        case "Identification": /*##################### CONTEXTE IDENTIFICATION ############################*/

            /****** suivi commande******/
            $('.sc_detail').click(function() {
                var $tab1 = $(this).parent().parent().parent().parent('#suivi_commande_liste');
                $tab1.next('.sc_detail_tab').slideToggle('slow');
                return false;
            });

            /****** login (nouveau et ancien compte) ******/
            if ($('#r_compte_old').attr('checked') == true) {
                $('#div_compte_new').hide(); $('#a_compte_old').addClass('checked');
            }
            else {
                $('#div_compte_old').hide(); $('#a_compte_new').addClass('checked');
            }

            $('#a_compte_old').click(function() {
                $('#r_compte_old').attr('checked', 'checked');
                $('#r_compte_new').removeAttr('checked');
                $('#a_compte_old').addClass('checked');
                $('#a_compte_new').removeClass('checked');
                $('#div_compte_new').fadeOut('slow');
                $('#div_compte_old').fadeIn('slow');
            });

            $('#a_compte_new').click(function() {
                $('#r_compte_old').removeAttr('checked');
                $('#r_compte_new').attr('checked', 'checked');
                $('#a_compte_old').removeClass('checked');
                $('#a_compte_new').addClass('checked');
                $('#div_compte_old').fadeOut('slow');
                $('#div_compte_new').fadeIn('slow');
            });


            break
        case "AfficheResultatRechercheAvancee": /*#### CONTEXTE RECHERCHE #################################*/

            /******Caroussel******/
            $("#slide_panier").bullesCarousel({ mini: 3 }); //mini: 3 articles minimumus
            
            /******* enlever txt RESUME si vide*******/
            $('.lignes .text_court').each(function() {
                if ($('.txt', this).html().length < 3) { $(this).hide(); }
            });

            $(' #bloc_list_article .ajout_panier_disable').each(function () {
                $(this).qtip({
                    content: 'Cet article est actuellement indisponible',
                    style: { tip: true, border: { radius: 5 }, name: 'dark' }, // Give it a crea mstyle to make it stand out
                    position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle'} }
                });
            });

            break
        case "ValidationPanier": /*################### CONTEXTE PANIER ####################################*/

            /******Point Relais ******/
            $(document).ready(function() {
                $('#gk_listerelais .horaire').each(function(i) {
                    $(this).qtip({
                        content: "<div class='BulleKiala'>" + $('#gk_listerelais p').eq(i).html() + "</div>",
                        show: 'mouseover',
                        hide: 'mouseout',
                        position: { corner: { tooltip: 'bottomMiddle', target: 'topMiddle'} },
                        style: { border: { width: 2, radius: 5, color: '#BAB3B3' }, tip: true, width: '400' }
                    });
                    $(this).click(function() { return false });
                });
            });

            /******Caroussel******/
            $("#slide_panier").bullesCarousel({ mini: 3 }); //mini: 3 articles minimumus


            break
        default: /*################################## AUTRES #############################################*/

    }
});


