﻿$(document).ready(function () {
    // Format the menus.
    $('#menu-horizontal ul').amenu({
        'speed': 200,
        'animation': 'none'
    });

    // Deals
    try {
        // Activate the countdown clock.
        $('#clock').countdown({ compact: true,
            compactLabels: ['y', 'm', 'w', ' days '],
            format: 'DHMS',
            timezone: -5,
            until: dealEnd
        });

        // Resize the window.        
        if ($.browser.webkit) {
            $('#dealContainer').height(($('#deal').outerHeight() + $('#confirmation').outerHeight()) * 1.5);
        }
        if ($.browser.msie) {
            $('#dealContainer').height($('#deal').outerHeight() + $('#confirmation').outerHeight());
        }
    }
    catch (err) {
    }



    // Product Pages

    // Format the bread crumb control.
    $('.breadCrumb').jBreadCrumb({ easing: 'swing' });

    // Resize productContainer to fit the content.
    $('#productContainer').height($('#productDetails').outerHeight());

    // Resize the content to fit the deal.    

    // Resize the product image to fit its container and maintain aspect ratio.
    var productImage = $('#productImage img');
    if (productImage != null) {
        var ratioHeight = productImage.parent().height() / productImage.height();
        var ratioWidth = productImage.parent().width() / productImage.width();
        if (ratioHeight < 1 || ratioWidth < 1) {
            if (ratioHeight > ratioWidth) {
                productImage.height(productImage.height() * ratioWidth);
                productImage.width(productImage.width() * ratioWidth);
            }
            else {
                productImage.height(productImage.height() * ratioHeight);
                productImage.width(productImage.width() * ratioHeight);

            };
        };

        // Center the image vertically and horizontally.
        productImage.css('margin-top', (productImage.height() / -2) + 'px');
        productImage.css('margin-left', (productImage.width() / -2) + 'px');
    };




});
