﻿/// <reference path="jquery-1.3.2-vsdoc.js" />


$(function () {
    $("#magicz").live('hover', function () { $("#viewlargermessage").show(); }, function () { $("#viewlargermessage").hide(); });

    $("img[ai='1']").live('click', function () {
        $("img[mi='1']").attr("src", $(this).attr("msrc"));
        var magicz = $('#magicz');
        $("#magicz").attr("href", $(this).attr("zsrc"));        
        MagicZoomPlus.refresh();        
    });

    $("[vli='1']").click(function () {
        var liw = window.open($("img[mi='1']").attr("src").replace(/b/, "c"), "liw", "height=520,width=500");
    });

    $(".swatches a").click(function () {

        var currentSwatch = $(this).find("img");

        $(".style_select").each(function () {

            if (currentSwatch.attr("level") == "" || currentSwatch.attr("level") == $("#" + this.id).attr("level")) {
                if ($("#" + this.id).containsOption(currentSwatch.attr("styleselection"))) {
                    $("#" + this.id).val(currentSwatch.attr("styleselection"));
                    if (currentSwatch.attr("image") != "") {
                        $("img[mi='1']").attr("src", currentSwatch.attr("image"));
                    }
                    if (currentSwatch.attr("largeimage").indexOf("noimage") < 0) {
                        $("#magicz").attr("href", currentSwatch.attr("largeimage"));
                    }
                    else {
                        $("#magicz").attr("href", currentSwatch.attr("image"));
                    }
                }
            }
            MagicZoomPlus.refresh();
        });

        return false;
    });

    $("#backorder_policy_container").dialog({
        autoOpen: false,
        width: 600,
        buttons: {
            "Ok": function () {
                $(this).dialog("close");
            }
        }
    });

    $("#backorder_policy_link").click(function () {
        $("#backorder_policy_container").dialog("open");
        return false;
    });

    $("a[read_more='read_more']").click(function () {

        $(this).removeClass("display");
        $(this).addClass("displaynone");

        $(this).parent().children("span").removeClass("displaynone");

    });

    $("a[link_id='set_helpful']").click(function () {
        $.get("/shop.axd/ProductReviewSetFoundHelpful?helpful=" + $(this).attr("helpful") + "&review_id=" + $(this).attr("review_id"));
        $(this).parent().html("<strong>Thank you for your input!</strong>");
        return false;
    });


    $("#free_gift_container").dialog({ autoOpen: false, bgiframe: true, width: 650, modal: true, resizable: false });
    $("#add_to_cart_button").click(function () {
        if ($("#has_free_gift").val() == "Y") {

            var ajaxURL = "/free_gift_selection.aspx?edp_no=" + $("#edp_no").val() + "&qty=" + $("#txtqty").val();

            $.ajax({
                type: "GET",
                url: ajaxURL,
                dataType: "html",
                success: function (html) {
                    $("#free_gift_container").html(html);
                    $(".style_select").each(function () {
                        $("#" + this.id).bind("change", function () {
                            handleStyleDropDownChange($(this));
                        });
                    });
                    $("#free_gift_add_to_cart").bind("click", function () {
                        freeGiftAddToCart();
                    });
                    $("#free_gift_container").dialog("open");
                }
            });

            return false;
        }
    });


    $(".style_select").change(function () {
        handleStyleDropDownChange($(this));
        MagicZoomPlus.refresh();
    });

    if ($("#menutabs").length > 0) {
        $("#menutabs").tabs({ fx: { opacity: 'toggle'} });
    }
});





