var itemTimer;

jQuery(function($) {
    // Your code using failsafe $ alias here...

    $(".enterZip").live("click", function() {
        $(this).parent().siblings(".shipData").toggle();
        return false;
    });

    $("ul.sf-menu").superfish({
        animation: { height: 'show' },
        speed: 300,
        delay:500,
        autoArrows: false,
        dropShadows: false
    }).find("ul").bgIframe();

    $(".itemRow").equalHeights(true);
    $(".modCarousel .items").equalHeights(true);
    $(".columnRow").equalHeights(true);

    $(".itemWrapper ul.swatchList li a").live("mouseover", function() {
        $(this).parents(".swatchList").find("a").removeClass("active");
        $(this).addClass("active");
        var newImg = $(this).find(".swatchAlt").html();
        $(this).parents(".itemWrapper").find(".itemImage").attr({ src: newImg });
    });

    $('.altViews li a').live("click", function() {
        //the new image
        var newimg = $(this).attr("href");

        //update active status
        var altViews = $(".altViews li")
        altViews.each(function(i) {
            var children = altViews.eq(i).children("a");
            children.each(function(j) {
            if (newimg.replace('/large/', '').replace('/regular/', '') == children.eq(j).attr("href").replace('/large/', '').replace('/regular/', '')) {
                    children.eq(j).addClass("active");
                } else {
                    children.eq(j).removeClass("active");
                }
            });
        });

        //find the regular image
        $(".productImage img.mainImage").attr({ src: newimg.replace('/large/', '/regular/') });

        //find the large image
        $(".imageViewer .mainImage img").attr({ src: newimg.replace('/regular/', '/large/') });

        return false;
    });

    //Banner slide show
    $("#homeSSW").cycle({
        fx: 'fade',
        speed: 300,
        timeout: 5000,
        pager: '.nav'
    });
    $(".sswControls").css({ 'background-color': '#fff', 'opacity': '0.9' });

    $(".truncate").truncate({
        max_length: 400,
        more: "read more",
        less: "read less"
    });

    // dialog windows 
    $(".uiModal").dialog({
        autoOpen: false,
        width: "720px",
        bgiframe: true,
        modal: true,
        resizable: false,
        live: false,
        buttons: {
            Close: function() {
                $(this).dialog('close');
            }
        }
    });

    $(".uiDialog").dialog({
        autoOpen: false,
        width: "720px",
        bgiframe: true,
        modal: false,
        resizable: false,
        buttons: {
            Close: function() {
                $(this).dialog('close');
            }
        }
    });

    $(".pageTools .recent").live("click", function() {
        $(".recentDialog").dialog("open");
        return false;
    });

    $(".productImage .btnEnlarge").live("click", function() {
        $(".enlargeView").dialog("open");
        return false;
    });
    // END dialog windows 

    $(".tabModule .tabsRow").tabs();
    $(".cartSupport .supportTabs").tabs();

    // carousels 
    $(".modCarousel4 .scrollable").scrollable({
        size: 4,
        items: ".items",
        clickable: false
    });


    $(".modCarousel5 .scrollable").scrollable({
        size: 5,
        items: ".items",
        clickable: false
    });

    $(".scrollable").each(function() {
        var mcHeight = $(".itemWrapper:first", this).height();
        $(this).css({ 'height': mcHeight });
    });
    // END carousels 

    $(".swatchList a").cluetip({
        cluetipClass: 'swatch',
        width: '178px',
        positionBy: 'fixed',
        topOffset: '-122px',
        leftOffset: '-115px',
        local: true,
        dropShadow: false,
        showTitle: false
    });

    // Item Added to Cart Slider
    $("#item-dialog").mouseover(function() { clearTimeout(itemTimer); });
    $("#item-dialog").mouseout(function() { itemTimer = setTimeout(function() { hideItemSlider(); }, 1500); });
    // END Item Added

});
function showItemSlider() {
    clearTimeout(itemTimer);
    $("#item-dialog").slideDown(300);
    itemTimer = setTimeout(function() { hideItemSlider(); }, 5000);
}
function hideItemSlider() {
    $("#item-dialog").slideUp(150);
}
