﻿$(document).ready(function() {

    $("#header .navigation a[href='#']").click(function() {
   
        var arr = depCat[$(this).text()]
        $("#categoriesList li").hide();
        var add = "";
        ;
        for (var i = 0; i < arr.length; i++) {
            $("#categoriesList a:contains('" + arr[i] + "')").each(function() {
                $(this).parent().show();
            });
        }


        $("#categoriesList").show();
        window.location.href = $("#categoriesList a:visible").eq(0).attr("href") + "#" + $(this).text();
        return false;

    });
    if (window.location.hash.length > 2) {
        $("#header .navigation a:contains('" + window.location.hash.substring(1) + "')").trigger("click");
    }
    function scrollyDoFrame() {

        if (scrollyDoUD == "U") {
            scrollyDoObj.scrollTop(scrollyDoObj.scrollTop() - 6)
        } else if (scrollyDoUD == "D") {

            scrollyDoObj.scrollTop(scrollyDoObj.scrollTop() + 6)
        }
    }
    function scrollyDoFrame2() {

        if (scrollyDoLR == "L") {
            scrollyDoObj.scrollLeft(scrollyDoObj.scrollLeft() - 6)
        } else if (scrollyDoLR == "R") {

            scrollyDoObj.scrollLeft(scrollyDoObj.scrollLeft() + 6)
        }
    }
    var scrollyDoUD
    var scrollyDoLR
    function scrollydoMM(e) {
        var l = (e.pageX - scrollyDoObj.offset().left)
        var t = (e.pageY - scrollyDoObj.offset().top)
        var ma = 100;
        if (t < ma) {
            scrollyDoUD = "U";
        } else if (t > $(this).height() - ma) {
            scrollyDoUD = "D";
        } else {
            scrollyDoUD = "";
        }
    }
    function scrollydoMM2(e) {
        var l = (e.pageX - scrollyDoObj.offset().left)
        var t = (e.pageY - scrollyDoObj.offset().top)
        var ma = 100;
        if (l < ma) {
            scrollyDoLR = "L";
        } else if (l > $(this).width() - ma) {
            scrollyDoLR = "R";
        } else {
            scrollyDoLR = "";
        }
    }
    var scrollyDoInterval;
    var scrollyDoObj;
    $(".scrollydo").hover(function() {
        scrollyDoObj = $(this)
        scrollyDoObj.bind("mousemove", scrollydoMM);
        scrollyDoInterval = setInterval(scrollyDoFrame, 80);
    }, function() {
        scrollyDoObj = $(this)
        scrollyDoObj.unbind("mousemove", scrollydoMM);
        clearInterval(scrollyDoInterval);

    });
    $(".scrollydo2").hover(function() {
        scrollyDoObj = $(this)
        scrollyDoObj.bind("mousemove", scrollydoMM2);
        scrollyDoInterval = setInterval(scrollyDoFrame2, 80);
    }, function() {
        scrollyDoObj = $(this)
        scrollyDoObj.unbind("mousemove", scrollydoMM2);
        clearInterval(scrollyDoInterval);

    });
    $(".downscrollydo").hover(function() {
        scrollyDoObj = $(".scrollydo");
        scrollyDoUD = "D";
        scrollyDoInterval = setInterval(scrollyDoFrame, 80);
    }, function() {
        scrollyDoObj = $(".scrollydo")
        clearInterval(scrollyDoInterval);

    });
    $(".upscrollydo").hover(function() {
        scrollyDoObj = $(".scrollydo");
        scrollyDoUD = "U";
        scrollyDoInterval = setInterval(scrollyDoFrame, 80);
    }, function() {
        scrollyDoObj = $(".scrollydo")
        clearInterval(scrollyDoInterval);

    });


    /*
    $(".shadowBox").resize(function() {
    $(this).css("backgroundImage", "url('images/shadow.shadow.jpgx?w=" + $(this).innerWidth() + "&h=" + $(this).innerHeight() + "')");
    });
    $(window).load(function() {
    $(".shadowBox").each(function() {
    $(this).css("backgroundImage", "url('images/shadow.shadow.jpgx?w=" + $(this).innerWidth() + "&h=" + $(this).innerHeight() + "')");
    });
    setInterval(function() {
    $(".shadowBox").each(function() {
    var url = "url('images/shadow.shadow.jpgx?w=" + $(this).innerWidth() + "&h=" + $(this).innerHeight() + "')";

                if (url != $(this).data("bURL")) {
    $(this).css("backgroundImage", url);
    $(this).data("bURL", url)
    }
    });

        }, 1500);
    });*/

    $(".listingItems img").hover(function() {
        var i = $(".listingItems img").index($(this))
        $(this).attr("src", hover_images[i]);

    }, function() {
        var i = $(".listingItems img").index($(this))
        $(this).attr("src", images[i]);
    });
});
$(document).ready(function() {

	$("#playicon").css("opacity",0.75);
});
function showQuickSearch() {
    $('#productSearch').hide();
    $('#quickSearch').show();
}
function showProductSearch() {
    $('#productSearch').show();
    $('#quickSearch').hide();
}
function departmentChange() {
    $("#" + LabelCheckBoxListID + " label").hide();
    $("#" + LabelCheckBoxListID + " input").hide();
    //$("#" + LabelCheckBoxListID + " br").hide();
    for (var i = 0; i < paramData.length; i++) {
        if (paramData[i][0] == $('#productSearch select').val()) {
            $("#" + LabelCheckBoxListID + " label:contains('" + paramData[i][1] + "')").show();
            $("#" + LabelCheckBoxListID + " label:contains('" + paramData[i][1] + "')").prev().show();
            //$("#" + LabelCheckBoxListID + " label:contains('" + paramData[i][1] + "')").next().show();
        }
    }
    $("#" + LabelCheckBoxListID + " input:hidden").checked = false;
    $("#" + LabelCheckBoxListID + " input:first").triggerHandler('click');

}

function setupProductSearchParas() {


    $('#productSearch select').change(departmentChange);
    
    $("#" + LabelCheckBoxListID + " input").click(function() {
        $("#" + GroupCheckBoxListID + " input").hide();
        //$("#" + GroupCheckBoxListID + " br").hide();
        $("#" + GroupCheckBoxListID + " label").hide();
        $("#searchGroupsEmpty").show();
        $("#" + LabelCheckBoxListID + " input:checked").each(function() {
            for (var i = 0; i < paramData.length; i++) {
                //alert(paramData[i][0]+" == "+$('#productSearch > select').val());
                if (paramData[i][0] == $('#productSearch select').val()
                    &&
                    paramData[i][1] == $(this).next().text()) {

                    //$("#" + GroupCheckBoxListID + " label:contains('" + paramData[i][2] + "')").next().show(); //show the br
                    $("#" + GroupCheckBoxListID + " label:contains('" + paramData[i][2] + "')").show(); //show the label
                    $("#" + GroupCheckBoxListID + " label:contains('" + paramData[i][2] + "')").prev().show(); //show the checkbox
                    $("#searchGroupsEmpty").hide();
                }
            }
        })
        $("#" + GroupCheckBoxListID + " input:hidden").each(function(i) {
            this.checked = false;
        });
        $("#" + GroupCheckBoxListID + " input:first").triggerHandler('click');

    });
    $("#" + GroupCheckBoxListID + "  input").click(function() {
        $('#sizeLibrariesDiv h3').hide();
        $('#sizeLibrariesDiv h3').each(function(i) {
            $(this).next().hide(); //hide the span
            //$(this).next().next().hide();//hide the space
        });
        $("#searchSizesEmpty").show();
        var dept=$('#productSearch select').val()
        $("#" + GroupCheckBoxListID + " input:checked").each(function() {
            var group = $(this).next().text();
            $("#" + LabelCheckBoxListID + " input:checked").each(function() {
                for (var i = 0; i < paramData.length; i++) {
                    if (paramData[i][0] == dept
                        &&
                        paramData[i][1] == $(this).next().text()
                        &&
                        paramData[i][2] == group) {
                        $("#sizeLibrariesDiv h3:contains('" + paramData[i][3] + "')").show();
                        $("#sizeLibrariesDiv h3:contains('" + paramData[i][3] + "')").next().show();
                        //$("#sizeLibrariesDiv > h3:contains('"+paramData[i][3]+"')").next().next().show();
                        $("#searchSizesEmpty").hide();
                    }

                }
            });
        });
        $('#sizeLibrariesDiv > span:hidden > input').each(function(i) {
            this.checked = false;
        });
    });
    departmentChange();
}




var currentNavLeft;
var curModal;
function openModal(m) {
    if (curModal != null) {
        closeModal(function() {
            doOpenModal(m)
        }, true);
    } else {

        doOpenModal(m)
    }

}

function doOpenModal(m) {
    curModal = m;
    $("#modalBackground").css("display", "block");
    $(document).scrollTop(0);
    $("#modalBackground").animate({ opacity: 0.7 }, 200, "linear", function() {
        curModal.css("display", "block");


        var wW = $("#main").width()
        var mW = curModal.outerWidth()
        var wH = $(window).height()

        var mH = curModal.outerHeight()
        curModal.css("left", Math.max((wW - mW) / 2,0));
        curModal.css("top", Math.max((wH - mH) / 2,0));
        curModal.animate({ opacity: 1 }, 200, "linear", function() {
            curModal.css("opacity", "");
        });
    });
}
function closeModal(f, leaveBack) {
    curModal.animate({ opacity: 0 }, 300, "linear", function() {
        curModal.css("display", "none");
        curModal = null;
        if (leaveBack) {
            if (f != null)
                f();
        } else {
            $("#modalBackground").animate({ opacity: 0.0 }, 300, "linear", function() {
                $("#modalBackground").css("display", "none");

                if (f != null)
                    f();
            });
        }
    });
}
$(document).ready(function() {

    $("a[href*='#Modal']").click(function() {
        openModal($($(this).attr("href").substr($(this).attr("href").indexOf("#"))));
        return false;
    });
    $(".modalBox").css("opacity", 0);
    $("#modalBackground").css("opacity", 0);
    $(".modalBox a.closeModal").click(function() { closeModal() });
    $(".modalBox input.closeModal").click(function() { closeModal() });
    $(window).resize(function() {

        if (curModal == null)
            return;
        var wW = $("#main").width()
        var mW = curModal.outerWidth()
        var wH = $(window).height()
        var mH = curModal.outerHeight()
        curModal.css("left", Math.max((wW - mW) / 2, 0));
        curModal.css("top", Math.max((wH - mH) / 2, 0));
    });
    $(".modalBox").each(function() {
    });
    $(".modalBox").scroll(function() {
    });
});
function fbs_click() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
    return false;
}
function twits_click() {
    u = location.href;
    t = document.title;
    window.open('http://twitter.com/home?status=Check+out+'+encodeURIComponent(t)+'+at+' + encodeURIComponent(u), 'sharer', 'toolbar=0,status=0,width=626,height=436');
    return false;
}



