jQuery(document).ready(function () {
    jQuery('#search_field').focus(function () {
        jQuery(this).addClass('focus');
    });
    jQuery('#search_field').blur(function () {
        if (jQuery(this).val() == '') {
            jQuery(this).removeClass('focus');
        }
    });


    // PRODUCT TABS
    jQuery("#product_tabs").show();
    jQuery("#product_tabs > ul a").click(function () {
        var tab = jQuery(this).attr('data-tab');
        jQuery(this).closest('li').addClass('ui-tabs-selected').siblings().removeClass('ui-tabs-selected');
        var show = jQuery(this).closest('#product_tabs').children('div#' + tab).show();
        show.siblings('div').hide();
    });


    // HIDE TAB IF ONLY ONE EXISTS
    if (jQuery("#product_tabs > ul a").length === 1)
        jQuery("#product_tabs > ul").remove();


    // PRODUCT SCROLLER
    //var productScrollerIndex = 0;
    //var productScrollerTotal = jQuery('.productscroller .product').length;
    jQuery('.productscroller .product:lt(2)').show();

    var showHideArrows = function () {
        if (jQuery('.productscroller .product:visible').first().prev('.product').length === 1)
            jQuery('.productscroller .leftarrow').show();
        else
            jQuery('.productscroller .leftarrow').hide();

        if (jQuery('.productscroller .product:visible').last().next('.product').length === 1)
            jQuery('.productscroller .rightarrow').show();
        else
            jQuery('.productscroller .rightarrow').hide();

        // add a border to the left cell.
        jQuery('.productscroller .product').css({ 'border-left': 'none' }).width(479);
        jQuery('.productscroller .product:visible:first').css({ 'border-left': '1px solid #CECFCE' }).width(478);
    }
    showHideArrows();

    jQuery('.productscroller .leftarrow').click(function (e) {
        e.stopPropagation();
        if (jQuery('.productscroller .product:visible').first().prev('.product').length === 1)
            jQuery('.productscroller .product:visible').last().hide().prev('.product').prev('.product').show();

        showHideArrows();
    });
    jQuery('.productscroller .rightarrow').click(function (e) {
        e.stopPropagation();
        if (jQuery('.productscroller .product:visible').last().next('.product').length === 1)
            jQuery('.productscroller .product:visible').first().hide().next('.product').next('.product').show();

        showHideArrows();
    });



    // SOME QUICK STYLING HACKS FOR CHROME.
    if (jQuery.browser.webkit) {
        jQuery('input.search_field').height(15);
    }
});

