$('.js-confirm').live('click', function(event){
    var message = $(this).attr('data-confirm-message');
    return confirm(message);
});

$product_list_onload = (function(){


    // don't show speech bubbles if there's nothing to show
    $('.js-bubble-trigger').each(function () {
        $description = $(this)
            .parent()
            .next('.js-bubble')
            .children('.js-description');
        if ($.trim($description.html()).length === 0) {
            $(this).remove();
        }
    });

    // pop up speech bubble
    $('.js-bubble-trigger').hover(function () {
        $bubble = $(this).parent().next('.js-bubble');
        $bubble.css({
            'top': String(-$bubble.height() + 10) +'px'
        });
        $bubble.fadeIn();
    }, function () {
        $bubble.stop(true, true).delay(1000).fadeOut();
    });

    $.facebox.settings.closeImage = BASE_URL+'js/facebox/closelabel.png';
    $.facebox.settings.loadingImage = BASE_URL+'js/facebox/loading.gif';
    $('.js-image').each(function () {
        $(this).click($popup_function = function(event) {
            event.preventDefault();
            $(this).info_popup();
        });
    });
    $('.js-product img').asynchImageLoader();
});
$(function() {
    $(".fancybox").facebox();
    $("#facebox").click(function(){
        $.facebox.close();
    });
    $product_list_onload();
});

(function($) {
    $.fn.extend({
        info_popup: function(){
            return this.each(function(){
                $this = this;
                $popup =  $(this).siblings('.js-popup-info');

                $.facebox(function() {
                    $('#facebox .content').html($popup.html());
                    $.facebox.reveal();
                    $('#facebox .js-close').click(function (event){
                        event.preventDefault();
                        $.facebox.close();
                    });
                    $('#facebox .js-popup-image a').click(function(event) {
                        event.preventDefault();
                        $('#facebox .content').html($('<img>').attr('src', $(this).attr('href')));
                        $.facebox.reveal();
                        $('#facebox img').click(function(){
                            $($this).info_popup();
                        });
                    });
                });

            });
        }
    });
})(jQuery);

