﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

function removeActiveSwatch() {
    $("a.swatch").each(function() {
        if ($(this).hasClass("active")) {
            $(this).removeClass("active");
        }
    });
}

function setActiveImage(obj) {
    $("#product_image").attr({ "src": $(obj).attr("href") });
}

$(function() {

    //Handle drop down

    $("#" + $("#color_drop_down").val()).click(function() {
        $("#product_image").attr({ "src": $("#swatch_" + $(this).val()).attr("href") });
        removeActiveSwatch();
        $("#swatch_" + $(this).val()).addClass("active");
    });

    //Handle product swatches
    $("a.swatch").each(function() {
        $(this).click(function() {
            removeActiveSwatch();
            setActiveImage($(this));
            $("#" + $("#color_drop_down").val()).val($(this).attr("id").replace("swatch_", ""));
            $(this).addClass("active");
            return false;
        });

        $(this).mouseover(function() {
            setActiveImage($(this));
        });

        $(this).mouseout(function() {
            $("a.swatch").each(function() {
                if ($(this).hasClass("active")) {
                    setActiveImage($(this));
                }
            });
        });

    });


    //Handle tabs
    $("#menutab li").each(function() {
        $(this).click(function() {
            var currentTab = $("#menutab .active");

            // set current tab inactive and hide its contents.
            if (currentTab) {
                $(currentTab).removeClass("active");
                $("#" + currentTab.attr("id") + "content").hide();
            }

            // set selected tab as active and show its contents.           
            $(this).addClass("active");
            $("#" + $(this).attr("id") + "content").show();
        });
    });

    //Print page 
    $(".linkprint").click(function() {
        window.print();
    });

    //Handle Scene 7 pop-ups

    $("#scene_7_links a").each(function() {
        $(this).click(function() {            
            window.open(this.href, "", "width=600,height=550,status=1,menu=0,location=0");
            return false;
        });
    });

});