(function($) {
    $(function() {
        var conf_bbar = [];
        var show_bbar = false;
        var repeat_show = 4;
        var cookie_bbar = {
            name: "delices_bbar",
            options: {
                path: "/"
            }
        };
        var cookie_bbar_val = $.cookie(cookie_bbar.name);

/*        conf_bbar.push({
            a: {
                href: "/devenir-membre/?source=delices_bbar",
                title: "Inscription"
            },
            img: {
                src: "/img/bottombar/ban-inscription-delices.jpg"
            },
            name: "Inscription Delices"
        });
*/
/*
        conf_bbar.push({
            a: {
                href: "http://adserver.adtech.de/adlink/3.0/869/3010624/0/1768/ADTECH;grp=2010-12-06",
                title: "Bulle Privee"
            },
            img: {
                src: "http://adserver.adtech.de/adserv/3.0/869/3010624/0/1768/ADTECH;grp=2010-12-06"
            },
            name: "Bulleprivee"
        });
*/
	conf_bbar.push({
            a: {
                href: "http://www.bulleprivee.com/customer/account/create/?source=delices-pub-v5-bottombar&xtor=AL-81",
                title: "Bulle Privee"
            },
            img: {
                src: "http://www.delices-defrance.com/img/bottombar/bulle_1129.gif"
            },
            name: "Bulleprivee"
        });

/*        conf_bbar.push({
            a: {
                href: "http://www.beaute-conseils.com/jeuxconcours/sothys/inscription.php?source=delices_bbar_01",
                title: "Jeu concours Beaute conseils"
            },
            img: {
                src: "/img/bottombar/ban-jc-beaute.jpg"
            },
            name: "Jc Beaute Sothys"
        });
*/

        // Choose a random message and display it in the bottom bar
        var conf = conf_bbar[Math.floor(Math.random() * conf_bbar.length)],
            pageTracker = _gat._getTracker("UA-9799757-2");
        $('#panel_content .body_content a').attr(conf.a);
        $('#panel_content .body_content a img').attr(conf.img);
        $('#panel_content .body_content a').click(function() {
            try {
                pageTracker._trackEvent('BottomBar', 'Click ' + conf.name || 'noname');
            } catch(e) {}
        });

        // Add a close handler
        $(".btn-slide").click(function() {
            var $btn_slide = $(this);
            $("#panel_content").slideUp("slow",
            function() {
                $btn_slide.hide();
            });
            return false;
        });

        // count page view for the session
        if (cookie_bbar_val !== null) {
            $.cookie(cookie_bbar.name, parseInt(cookie_bbar_val, 10) + 1, cookie_bbar.options);
        } else {
            $.cookie(cookie_bbar.name, 0, cookie_bbar.options);
        }
        show_bbar = !($.cookie(cookie_bbar.name) % repeat_show);
        // Show the bottom bar only if the takeover is not visible
        if (show_bbar && !$('#takeover').is(':visible')) {
            $(".btn-slide").show('slow',
            function() {
                $("#panel_content").slideDown("slow");
                try {
                    pageTracker._trackEvent('BottomBar', 'Show ' + conf.name || 'noname');
                } catch(e) {}
            });
        }
    });
})(jQuery);

