$(document).ready(function()
{
    // init the carousel
    $("#carousel").jCarouselLite({
        btnNext: "#next",
        btnPrev: "#prev",
        visible: 4
    });


    var jGreatDealsContent = $("div.deals_form");
    var jNameYourPriceContent = $("div.name_price_form");

    // bind the great deals toggle
    $("#great_deals").toggle(
        function()
        { 
            if (jNameYourPriceContent.is(":not(:hidden)"))
                $("#name_your_price").trigger("click");

            jGreatDealsContent.slideDown(500); 
        },
        function() { jGreatDealsContent.slideUp(500); }
    );

    // bind the name your price toggle
    $("#name_your_price").toggle(
        function()
        {   
            if (jGreatDealsContent.is(":not(:hidden)"))
                $("#great_deals").trigger("click");

            jNameYourPriceContent.slideDown(500); 
        },
        function() { jNameYourPriceContent.slideUp(500); }
    );

    // bind the upsell toggle
    var jUpsellItems = $("div.upsell_items");
    var jUpsellIndicator = $("#upsell_indicator");
    $("#upsell_items").toggle(
        function() { jUpsellItems.slideDown(500, function() { jUpsellIndicator.attr("src", "images/minus.gif"); }); },
        function() { jUpsellItems.slideUp(500, function() { jUpsellIndicator.attr("src", "images/plus.gif"); }); }
    );

    // init the tooltips
    $("a[title]").qtip({
        style: {
            name: 'light',
            tip: true
        },
        position: {
            corner: {
                target: 'rightMiddle',
                tooltip: 'leftMiddle'
            }
        }
    });



    // init the tabs
    var boolAllowClick = true;

    $("div.tabs_content > div:not(:first)").hide();

    $(document).ready(function()
    {
        var imgPath = "images/product/";

        $("div.tab_header img").click(function()
        {
        	// October 30, 2009 WSH // HOMO // THIS LINE BELOW STOPS JS FROM DOING ANYTHING WHEN PADDING IS CLICKED, THE LINE FURTHER BELOW IS FOR WHEN CLICKING ON OTHER TABS TO NOT CHANGE PADDING TO ITS DEFAULT IMAGE
        	if( $(this).attr("src") == "images/tab_padding.gif" ) {
        		return;
        	}
        
            if (boolAllowClick)
            {
                boolAllowClick = false;

                $(this).parent().siblings("div").children("img").each(function()
                {
                	// October 30, 2009 WSH // HOMO // DON'T SET ANYTHING IF PADDING IS USED (TAB NOT AVAILABLE FOR PRODUCT)
                	if( $(this).attr("src") == "images/tab_padding.gif" ) {
	                	
                	}
                	else {
	                    var imgDefaultUrl = $(this).attr("id");
	                    $(this).attr("src", imgPath + imgDefaultUrl + ".gif");
                    }
                });

                var imgID = $(this).attr("id");
                $(this).attr("src", imgPath + imgID + "_hover.gif");

                $("div.tabs_content > div:not(:hidden)").slideUp(300, function() { $("#" + imgID + "_content").slideDown(300); boolAllowClick = true; });
            }
        });
    });

});
