jQuery(function () {
    'use strict';

    var indexURL = jQuery('link[rel="header_link"]').attr('href');
    var iframeTagPart = ['<iframe allowtransparency="true" ' , 'background-color:transparent;filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);"></iframe>'];
    if(indexURL && jQuery('header.clickable').length) {
        if(jQuery('#bd-header-bg').length) {
            jQuery('header').append(
                (jQuery.browser.msie ? iframeTagPart[0] + 'style="position:absolute;height:100%;width:40000px;left:-20000px;' + iframeTagPart[1] : '' ) +
                '<a style="position:absolute;height:100%;width:40000px;left:-20000px;top:0px;z-index:1000;" href="' + indexURL + '"></a>');
        } else {
            jQuery('header').append(
                (jQuery.browser.msie ? iframeTagPart[0] + 'style="position:absolute;height:100%;width:100%;' + iframeTagPart[1] : '' ) +
                '<a style="position:absolute;height:100%;width:100%;" href="' + indexURL + '"></a>');
        }
    }

    $('body').bind('added_to_cart', function() {
        $('.add_to_cart_button.added').text('ADDED');
    });
});

function equalHeight(selector, child, layouts, itemsInRow, forceOneRow) {
    'use strict';

    var deferreds = [];
    $(child).find('img').each(function () {
        if (this.complete)
            return;
        var deferred = $.Deferred();
        $(this).load(deferred.resolve);
        deferreds.push(deferred.promise());
    });
    $.when.apply($, deferreds).done(function () {
        jQuery(selector).equalHeight(
            child,
            layouts,
            itemsInRow,
            forceOneRow
        );
    });
}

@baseTemplate
