﻿
$(function () {
    $(".MagicZoomPlus").click(function () {
        window.location.href = $(this).attr("producturl");
    });

    $(".MagicZoomPlus").live('click', function () {
        window.location.href = $(this).attr("producturl");
    });

    $("img[ai='1']").live('click', function () {
        $("img[mi='1']").attr("src", $(this).attr("msrc"));

        $("#magicz").attr("href", $(this).attr("zsrc"));

        MagicZoomPlus.refresh();
    });

    $(".butaddcart").click(function () {

        if ($(this).attr("freegift") == "Y") {

            $("#free_gift_container").dialog({ autoOpen: false, bgiframe: true, width: 650, modal: true, resizable: false });
            var ajaxURL = $(this).attr("href").replace("/shop.axd/AddToCartBP", "/free_gift_selection.aspx");


            $.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;
        }
    });

    $("#divProductQuickview").dialog({ autoOpen: false, bgiframe: true, width: 650, modal: true, resizable: false,
        open: function (event, ui) {
            $('body').css('overflow-x', 'hidden');
        }
    });

    $('.quickview').click(function () {

        var edpNo = $(this).attr('id').split('_')[1];

        $.ajax({
            type: 'GET',
            url: '/shop.axd/ProductQuickview',
            cache: false,
            dataType: 'html',
            data: {
                edpNo: edpNo
            },
            success: function (html) {
                var divProductQuickview = $('#divProductQuickview');                
                divProductQuickview.html(html);
                divProductQuickview.dialog("open");
                if ($("#menutabs").length > 0) {
                    $("#menutabs").tabs({ fx: { opacity: 'toggle' }, selected: 0 });

                    $(".style_select").each(function () {
                        $(this).bind("change", function () {
                            handleStyleDropDownChange($(this));
                        });

                        handleStyleDropDownChange($(this));
                    });
                }
                MagicZoomPlus.refresh();
            }
        });
    });

    $(".swatches a").live('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"));
                        MagicZoomPlus.refresh();
                    }
                    else {
                        $("#magicz").attr("href", currentSwatch.attr("image"));
                    }
                    MagicZoomPlus.refresh();
                }
            }
        });

        return false;
    });
});


