﻿var selectedTab = "#acc-tab-1";
var FeaturesTabState = 1;

//  var randomVal = Math.random() * 2; // random number between 0 and 2
//  if (randomVal >= 1) {
//      var selectedTab = "#acc-tab-2";
//  }

$(document).ready(function() {
    homePageInit();

    $(".acc-tabs li").click(function() {
        $(".acc-tabs li").removeClass("tab-selected");
        $(this).addClass("tab-selected");

        $("#tabs div.cedb").removeClass("tab-content-selected");
        $($(this).children("a").attr("href")).addClass("tab-content-selected");

//        $("#tabs div.cedb").hide();
//        var activeTab = $(this).children("a").attr("href");
//        $(activeTab).fadeIn();

        return false;
    });

    $(".ui-accordion-header").click(function() {
        if ($(this).attr("id") != "featured-offers-tab") {
            if (FeaturesTabState == 1) {
                $(".acc-tabs").hide();
                FeaturesTabState = 0;
            }
        }
        else {
            if (FeaturesTabState == 0) {
                $(".acc-tabs").fadeIn(function() {
                    FeaturesTabState = 1;
                });
            }
        }
        
        return false;
    });
});

function homePageInit() {
    // tracking for homepage featured products
    $(".ta3").each(function() {
        attachtracking($(this));
    });
    $(".ta1").each(function() {
        attachtracking($(this));
    });
    $(".ta2").each(function() {
        attachtracking($(this));
    }); 
    
    // homepage accordion
    $("#accordion").accordion({ header: "div.ui-accordion-header", active: 1, autoHeight: false, collapsible: false });

    // initializing homepage tabs
    $(".tab-content-selected").removeClass("tab-content-selected"); // need this for equal height to be calculated first
    $("li:has(a[href='" + selectedTab + "'])").addClass("tab-selected");
    $(selectedTab).addClass("tab-content-selected");

    if ($.browser.msie) {
        $('#accordion div').css('zoom', '1');
        $('#accordion div.swatches').css('zoom', 'normal');
        $('#accordion div.color-options').css('zoom', 'normal');
    };
}
