﻿$(document).ready(function () {

    /* Sidenav */
    $('ul.sidenav li').click(function () { window.location = $(this).find("a:first").attr("href"); return false; });
    $('ul.sidenav li').mouseover(function () { $(this).addClass("over"); }).mouseout(function () { $(this).removeClass("over"); });

    $('.navlist ul').css({ display: "none" }); //Fix Opera
    $('.navlist.firstnav li').hover(function () {
        $(this).addClass('addPosition');
        var w = $(this).width();
        $(this).find('ul:first').css({ visibility: "visible", display: "none", left: w }).show(300);
    }, function () {
        $(this).find('ul:first').css({ visibility: "hidden" }).hide(300);
        $(this).removeClass('addPosition');
    });

    /* Paging */
    $('div.paging .select').mouseover(function () { $(this).find('span:first').show(); }).mouseout(function () { $(this).find('span:first').hide(); });

    /* Category */
    $('div.preview').click(function () { $(this).showLoading(); window.location = $(this).find("a:first").attr("href"); return false; });
    $('#largerview').click(function () { $(this).addClass("hidden"); $('#smallerview').removeClass("hidden"); $('#previewcontainer').addClass("preview_4"); $('#previewcontainer').removeClass("preview_5"); return false; });
    $('#smallerview').click(function () { $(this).addClass("hidden"); $('#largerview').removeClass("hidden"); $('#previewcontainer').addClass("preview_5"); $('#previewcontainer').removeClass("preview_4"); return false; });

    $('.optionhide').click(function () { $(this).addClass("hidden"); $(this).next('div.optionshow').removeClass("hidden"); $(this).next('div.optionshow').next('div.optionwrapper').addClass("hidden"); return false; });
    $('.optionshow').click(function () { $(this).addClass("hidden"); $(this).prev('div.optionhide').removeClass("hidden"); $(this).next('div.optionwrapper').removeClass("hidden"); return false; });

    //$('#minicartlinks a').mouseover(function () { $('#minicartwrap').stop().slideDown(250, function () { $(this).show(); }); });
    //$('#addcartlinks a').mouseover(function () { $('#minicartwrap').stop().slideDown(250, function () { $(this).show(); }); });
    $('.miniclose').click(function () { $('#minicartwrap').stop().slideUp(250, function () { $(this).hide(); }); });
    $('.minicartitem').click(function () { window.location = $(this).find("a:first").attr("href"); return false; });
    $('.minicartitem').mouseover(function () { $(this).css("cursor", "pointer"); $(this).addClass("over"); }).mouseout(function () { $(this).removeClass("over"); });

    /* Forms */
    $('input[type="text"]').focus(function () { $(this).addClass("focus"); });
    $('input[type="text"]').blur(function () { $(this).removeClass("focus"); });
    $('input[type="password"]').focus(function () { $(this).addClass("focus"); });
    $('input[type="password"]').blur(function () { $(this).removeClass("focus"); });
    $('select').focus(function () { $(this).addClass("focus"); });
    $('select').blur(function () { $(this).removeClass("focus"); });
    $('textarea').focus(function () { $(this).addClass("focus"); });
    $('textarea').blur(function () { $(this).removeClass("focus"); });

    $('#Order_ShipAddress_Phone').mask("(999)999-9999");
    $('#Order_BillAddress_Phone').mask("(999)999-9999");
    $('#Order_Credit_CCNumber').mask("999999999999?9999");
    $('#Order_Credit_CCExp').mask("9999");
    $('#Order_Credit_CVV2').mask("999?9");

    $('#Order_ShipAddress_Country').change(function () {
        var country = $(this).val().toLowerCase();

        if (country == 'ca') {
            $('label[for=Order_ShipAddress_State]').html('Province:');
            $('#Order_ShipAddress_State').children().remove().end();
        } else {
            $('label[for=Order_ShipAddress_State]').html('State:');
            $('#Order_ShipAddress_State').children().remove().end();
        }

        $.getJSON("/cart/getstates", { c: country },
            function (data) {
                var output = [];
                $.each(data, function (index, list) { output.push('<option value="' + list.sKey + '">' + list.sValue + '</option>'); });
                $('#Order_ShipAddress_State').append(output.join(''));
            });
        });

    $('#Order_BillAddress_Country').change(function () {
        var country = $(this).val().toLowerCase();

        if (country == 'ca') {
            $('label[for=Order_BillAddress_State]').html('Province:');
            $('#Order_BillAddress_State').children().remove().end();
        } else {
            $('label[for=Order_BillAddress_State]').html('State:');
            $('#Order_BillAddress_State').children().remove().end();
        }

        $.getJSON("/cart/getstates", { c: country },
        function (data) {
            var output = [];
            $.each(data, function (index, list) { output.push('<option value="' + list.sKey + '">' + list.sValue + '</option>'); });
            $('#Order_BillAddress_State').append(output.join(''));
        });
    });

    $('#Order_ShipAddress_PostalCode').change(function () { getshipping(); });

    function getshipping() {
        var adddress = $('#Order_ShipAddress_Address').val();
        var adddress2 = $('#Order_ShipAddress_Address2').val();
        var scity = $('#Order_ShipAddress_City').val();
        var state = $('#Order_ShipAddress_State').val();
        var zipcode = $('#Order_ShipAddress_PostalCode').val();
        var country = $('#Order_ShipAddress_Country').val();
        if (scity != '' && scity != null && zipcode != '' && zipcode != null && country != '' && country != null) {
            $('#shippingmethods').empty().showLoading();
            $.getJSON("/cart/getshippingoptions", { a1: adddress, a2: adddress2, city: scity, st: state, zip: zipcode, c: country },
                function (data) {
                    var output = [];
                    var start = '<div class="form radio"><input class="required" data-val="true" data-val-required="Please select a shipping method." id="Order_ShipMethod" name="Order.ShipMethod" type="radio" value="';
                    $.each(data, function (index, itemData) {
                        var cost = (itemData.ShipCost).toFixed(2); //display cost
                        output.push(start + itemData.ShipCode + ":" + itemData.ShipText + ":" + cost + '" /> ' + itemData.ShipText + ' ($' + cost + ')</div>');
                    });
                    $('#shippingmethods').html(output.join(''));
                    $('#shippingmethods').hideLoading();
                });
        }
    };

    /* UI MouseOvers */
    $('#ftsubscribe').mouseover(function () { $(this).addClass('ui-btn-subscribe-on').removeClass('ui-btn-subscribe'); });
    $('#ftsubscribe').mouseout(function () { $(this).addClass('ui-btn-subscribe').removeClass('ui-btn-subscribe-on'); });
    $('#ftsubscribealt').mouseover(function () { $(this).addClass('ui-btn-subscribe-on').removeClass('ui-btn-subscribe-alt'); });
    $('#ftsubscribealt').mouseout(function () { $(this).addClass('ui-btn-subscribe-alt').removeClass('ui-btn-subscribe-on'); });
    $('.btnsignin').mouseover(function () { $(this).addClass('ui-btn-signin-on').removeClass('ui-btn-signin'); });
    $('.btnsignin').mouseout(function () { $(this).addClass('ui-btn-signin').removeClass('ui-btn-signin-on'); });
    $('.btncreateacct').mouseover(function () { $(this).addClass('ui-btn-createacct-on').removeClass('ui-btn-createacct'); });
    $('.btncreateacct').mouseout(function () { $(this).addClass('ui-btn-createacct').removeClass('ui-btn-createacct-on'); });
    $('.btnguest').mouseover(function () { $(this).addClass('ui-btn-guest-on').removeClass('ui-btn-guest'); });
    $('.btnguest').mouseout(function () { $(this).addClass('ui-btn-guest').removeClass('ui-btn-guest-on'); });
    $('.btncart').mouseover(function () { $(this).addClass('ui-btn-addtocart-on').removeClass('ui-btn-addtocart'); });
    $('.btncart').mouseout(function () { $(this).addClass('ui-btn-addtocart').removeClass('ui-btn-addtocart-on'); });
    $('.btnviewcart').mouseover(function () { $(this).addClass('ui-btn-viewcart-on').removeClass('ui-btn-viewcart'); });
    $('.btnviewcart').mouseout(function () { $(this).addClass('ui-btn-viewcart').removeClass('ui-btn-viewcart-on'); });
    $('#minicartbtn').mouseover(function () { $(this).addClass('ui-bg-cart-on').removeClass('ui-bg-cart'); });
    $('#minicartbtn').mouseout(function () { $(this).addClass('ui-bg-cart').removeClass('ui-bg-cart-on'); });
    $('.btncheckoutlg').mouseover(function () { $(this).addClass('ui-btn-checkoutlg-on').removeClass('ui-btn-checkoutlg'); });
    $('.btncheckoutlg').mouseout(function () { $(this).addClass('ui-btn-checkoutlg').removeClass('ui-btn-checkoutlg-on'); });
    $('.btnbilling').mouseover(function () { $(this).addClass('ui-btn-billing-on').removeClass('ui-btn-billing'); });
    $('.btnbilling').mouseout(function () { $(this).addClass('ui-btn-billing').removeClass('ui-btn-billing-on'); });
    $('.btnreview').mouseover(function () { $(this).addClass('ui-btn-review-on').removeClass('ui-btn-review'); });
    $('.btnreview').mouseout(function () { $(this).addClass('ui-btn-review').removeClass('ui-btn-review-on'); });
    $('.btnsubmitorder').mouseover(function () { $(this).addClass('ui-btn-submitorder-on').removeClass('ui-btn-submitorder'); });
    $('.btnsubmitorder').mouseout(function () { $(this).addClass('ui-btn-submitorder').removeClass('ui-btn-submitorder-on'); });
    $('.btncontinue').mouseover(function () { $(this).addClass('ui-btn-continue-on').removeClass('ui-btn-continue'); });
    $('.btncontinue').mouseout(function () { $(this).addClass('ui-btn-continue').removeClass('ui-btn-continue-on'); });
    $('.btnupdate').mouseover(function () { $(this).addClass('ui-btn-update-on').removeClass('ui-btn-update-alt'); });
    $('.btnupdate').mouseout(function () { $(this).addClass('ui-btn-update-alt').removeClass('ui-btn-update-on'); });
    $('.btnsignreg').mouseover(function () { $(this).addClass('ui-btn-signreg-on').removeClass('ui-btn-signreg'); });
    $('.btnsignreg').mouseout(function () { $(this).addClass('ui-btn-signreg').removeClass('ui-btn-signreg-on'); });

    $('.tooltip').mouseover(function () { tooltip.show($(this).attr('data-tip')); });
    $('.tooltip').mouseout(function () { tooltip.hide(); });
    $('.hotspot').mouseover(function () { tooltip.show($(this).attr('data-tip')); });
    $('.hotspot').mouseout(function () { tooltip.hide(); });

});

var tooltip = function () { var a = "tt"; var b = 3; var c = 3; var d = 520; var e = 10; var f = 20; var g = 95; var h = 0; var i, j, k, l, m; var n = document.all ? true : false; return { show: function (c, e) { if (i == null) { i = document.createElement("div"); i.setAttribute("id", a); j = document.createElement("div"); j.setAttribute("id", a + "top"); k = document.createElement("div"); k.setAttribute("id", a + "cont"); l = document.createElement("div"); l.setAttribute("id", a + "bot"); i.appendChild(j); i.appendChild(k); i.appendChild(l); document.body.appendChild(i); i.style.opacity = 0; i.style.filter = "alpha(opacity=0)"; document.onmousemove = this.pos } i.style.display = "block"; k.innerHTML = c; i.style.width = e ? e + "px" : "auto"; if (!e && n) { j.style.display = "none"; l.style.display = "none"; i.style.width = i.offsetWidth; j.style.display = "block"; l.style.display = "block" } if (i.offsetWidth > d) { i.style.width = d + "px" } m = parseInt(i.offsetHeight) + b; clearInterval(i.timer); i.timer = setInterval(function () { tooltip.fade(1) }, f) }, pos: function (a) { var b = n ? event.clientY + document.documentElement.scrollTop : a.pageY; var d = n ? event.clientX + document.documentElement.scrollLeft : a.pageX; i.style.top = b - m + "px"; i.style.left = d + c + "px" }, fade: function (a) { var b = h; if (b != g && a == 1 || b != 0 && a == -1) { var c = e; if (g - b < e && a == 1) { c = g - b } else if (h < e && a == -1) { c = b } h = b + c * a; i.style.opacity = h * .01; i.style.filter = "alpha(opacity=" + h + ")" } else { clearInterval(i.timer); if (a == -1) { i.style.display = "none" } } }, hide: function () { clearInterval(i.timer); i.timer = setInterval(function () { tooltip.fade(-1) }, f) } } } ();

/*
Masked Input plugin for jQuery
Copyright (c) 2007-2011 Josh Bush (digitalbush.com)
Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) 
Version: 1.3
*/
(function (a) { var b = (a.browser.msie ? "paste" : "input") + ".mask", c = window.orientation != undefined; a.mask = { definitions: { 9: "[0-9]", a: "[A-Za-z]", "*": "[A-Za-z0-9]" }, dataName: "rawMaskFn" }, a.fn.extend({ caret: function (a, b) { if (this.length != 0) { if (typeof a == "number") { b = typeof b == "number" ? b : a; return this.each(function () { if (this.setSelectionRange) this.setSelectionRange(a, b); else if (this.createTextRange) { var c = this.createTextRange(); c.collapse(!0), c.moveEnd("character", b), c.moveStart("character", a), c.select() } }) } if (this[0].setSelectionRange) a = this[0].selectionStart, b = this[0].selectionEnd; else if (document.selection && document.selection.createRange) { var c = document.selection.createRange(); a = 0 - c.duplicate().moveStart("character", -1e5), b = a + c.text.length } return { begin: a, end: b} } }, unmask: function () { return this.trigger("unmask") }, mask: function (d, e) { if (!d && this.length > 0) { var f = a(this[0]); return f.data(a.mask.dataName)() } e = a.extend({ placeholder: "_", completed: null }, e); var g = a.mask.definitions, h = [], i = d.length, j = null, k = d.length; a.each(d.split(""), function (a, b) { b == "?" ? (k--, i = a) : g[b] ? (h.push(new RegExp(g[b])), j == null && (j = h.length - 1)) : h.push(null) }); return this.trigger("unmask").each(function () { function v(a) { var b = f.val(), c = -1; for (var d = 0, g = 0; d < k; d++) if (h[d]) { l[d] = e.placeholder; while (g++ < b.length) { var m = b.charAt(g - 1); if (h[d].test(m)) { l[d] = m, c = d; break } } if (g > b.length) break } else l[d] == b.charAt(g) && d != i && (g++, c = d); if (!a && c + 1 < i) f.val(""), t(0, k); else if (a || c + 1 >= i) u(), a || f.val(f.val().substring(0, c + 1)); return i ? d : j } function u() { return f.val(l.join("")).val() } function t(a, b) { for (var c = a; c < b && c < k; c++) h[c] && (l[c] = e.placeholder) } function s(a) { var b = a.which, c = f.caret(); if (a.ctrlKey || a.altKey || a.metaKey || b < 32) return !0; if (b) { c.end - c.begin != 0 && (t(c.begin, c.end), p(c.begin, c.end - 1)); var d = n(c.begin - 1); if (d < k) { var g = String.fromCharCode(b); if (h[d].test(g)) { q(d), l[d] = g, u(); var i = n(d); f.caret(i), e.completed && i >= k && e.completed.call(f) } } return !1 } } function r(a) { var b = a.which; if (b == 8 || b == 46 || c && b == 127) { var d = f.caret(), e = d.begin, g = d.end; g - e == 0 && (e = b != 46 ? o(e) : g = n(e - 1), g = b == 46 ? n(g) : g), t(e, g), p(e, g - 1); return !1 } if (b == 27) { f.val(m), f.caret(0, v()); return !1 } } function q(a) { for (var b = a, c = e.placeholder; b < k; b++) if (h[b]) { var d = n(b), f = l[b]; l[b] = c; if (d < k && h[d].test(f)) c = f; else break } } function p(a, b) { if (!(a < 0)) { for (var c = a, d = n(b); c < k; c++) if (h[c]) { if (d < k && h[c].test(l[d])) l[c] = l[d], l[d] = e.placeholder; else break; d = n(d) } u(), f.caret(Math.max(j, a)) } } function o(a) { while (--a >= 0 && !h[a]); return a } function n(a) { while (++a <= k && !h[a]); return a } var f = a(this), l = a.map(d.split(""), function (a, b) { if (a != "?") return g[a] ? e.placeholder : a }), m = f.val(); f.data(a.mask.dataName, function () { return a.map(l, function (a, b) { return h[b] && a != e.placeholder ? a : null }).join("") }), f.attr("readonly") || f.one("unmask", function () { f.unbind(".mask").removeData(a.mask.dataName) }).bind("focus.mask", function () { m = f.val(); var b = v(); u(); var c = function () { b == d.length ? f.caret(0, b) : f.caret(b) }; (a.browser.msie ? c : function () { setTimeout(c, 0) })() }).bind("blur.mask", function () { v(), f.val() != m && f.change() }).bind("keydown.mask", r).bind("keypress.mask", s).bind(b, function () { setTimeout(function () { f.caret(v(!0)) }, 0) }), v() }) } }) })(jQuery);

/* Format Currency 1.4.0 */
(function (a) { function d(a) { if (a.symbol === "") { return new RegExp("[^\\d" + a.decimalSymbol + "-]", "g") } else { var b = a.symbol.replace("$", "\\$").replace(".", "\\."); return new RegExp(b + "|[^\\d" + a.decimalSymbol + "-]", "g") } } function c(a) { switch (a.toLowerCase()) { case "int": return "Int"; case "float": return "Float"; default: throw "invalid parseType" } } function b(b) { var c = a.formatCurrency.regions[b]; if (c) { return c } else { if (/(\w+)-(\w+)/g.test(b)) { var d = b.replace(/(\w+)-(\w+)/g, "$1"); return a.formatCurrency.regions[d] } } return null } a.formatCurrency = {}; a.formatCurrency.regions = []; a.formatCurrency.regions[""] = { symbol: "$", positiveFormat: "%s%n", negativeFormat: "(%s%n)", decimalSymbol: ".", digitGroupSymbol: ",", groupDigits: true }; a.fn.formatCurrency = function (c, e) { if (arguments.length == 1 && typeof c !== "string") { e = c; c = false } var f = { name: "formatCurrency", colorize: false, region: "", global: true, roundToDecimalPlace: 2, eventOnDecimalsEntered: false }; f = a.extend(f, a.formatCurrency.regions[""]); e = a.extend(f, e); if (e.region.length > 0) { e = a.extend(e, b(e.region)) } e.regex = d(e); return this.each(function () { $this = a(this); var b = "0"; b = $this[$this.is("input, select, textarea") ? "val" : "html"](); if (b.search("\\(") >= 0) { b = "-" + b } if (b === "" || b === "-" && e.roundToDecimalPlace === -1) { return } if (isNaN(b)) { b = b.replace(e.regex, ""); if (b === "" || b === "-" && e.roundToDecimalPlace === -1) { return } if (e.decimalSymbol != ".") { b = b.replace(e.decimalSymbol, ".") } if (isNaN(b)) { b = "0" } } var d = String(b).split("."); var f = b == Math.abs(b); var g = d.length > 1; var h = g ? d[1].toString() : "0"; var i = h; b = Math.abs(d[0]); b = isNaN(b) ? 0 : b; if (e.roundToDecimalPlace >= 0) { h = parseFloat("1." + h); h = h.toFixed(e.roundToDecimalPlace); if (h.substring(0, 1) == "2") { b = Number(b) + 1 } h = h.substring(2) } b = String(b); if (e.groupDigits) { for (var j = 0; j < Math.floor((b.length - (1 + j)) / 3); j++) { b = b.substring(0, b.length - (4 * j + 3)) + e.digitGroupSymbol + b.substring(b.length - (4 * j + 3)) } } if (g && e.roundToDecimalPlace == -1 || e.roundToDecimalPlace > 0) { b += e.decimalSymbol + h } var k = f ? e.positiveFormat : e.negativeFormat; var l = k.replace(/%s/g, e.symbol); l = l.replace(/%n/g, b); var m = a([]); if (!c) { m = $this } else { m = a(c) } m[m.is("input, select, textarea") ? "val" : "html"](l); if (g && e.eventOnDecimalsEntered && i.length > e.roundToDecimalPlace) { m.trigger("decimalsEntered", i) } if (e.colorize) { m.css("color", f ? "black" : "red") } }) }; a.fn.toNumber = function (c) { var e = a.extend({ name: "toNumber", region: "", global: true }, a.formatCurrency.regions[""]); c = jQuery.extend(e, c); if (c.region.length > 0) { c = a.extend(c, b(c.region)) } c.regex = d(c); return this.each(function () { var b = a(this).is("input, select, textarea") ? "val" : "html"; a(this)[b](a(this)[b]().replace("(", "(-").replace(c.regex, "")) }) }; a.fn.asNumber = function (e) { var f = a.extend({ name: "asNumber", region: "", parse: true, parseType: "Float", global: true }, a.formatCurrency.regions[""]); e = jQuery.extend(f, e); if (e.region.length > 0) { e = a.extend(e, b(e.region)) } e.regex = d(e); e.parseType = c(e.parseType); var g = a(this).is("input, select, textarea") ? "val" : "html"; var h = a(this)[g](); h = h ? h : ""; h = h.replace("(", "(-"); h = h.replace(e.regex, ""); if (!e.parse) { return h } if (h.length == 0) { h = "0" } if (e.decimalSymbol != ".") { h = h.replace(e.decimalSymbol, ".") } return window["parse" + e.parseType](h) } })(jQuery);
