$(document).ready(function () {
    showMiniCart();
    $('.cart').hover(
		function () {
		    $('.myCart').stop(true, true).fadeIn(400);
		},
		function () {
		    $('.myCart').stop(true, true).fadeOut(400);
		}
	);
	render_cart_header("CartItemsLBGet", "CartTotalLBGet");
});  //document ready function

var topdomain = document.domain;
function render_cart_header(items, total) {
    if (getElementByID_Master(total) == null || getElementByID_Master(items) == null)
    	return;

    $.ajax({
    	url: '/store/os/shoppingcartcost.aspx',
    	cache: false,
    	success: function (html) {
    		var ary = html.split("|");
    		if (ary.length > 1) {
    			getElementByID_Master(total).innerHTML = ary[0];
    			getElementByID_Master(items).innerHTML = ary[1];
    		}
    	},
    	error: function (err) {
    	}
    });

    try {
        getElementByID_Master("CartLiteralSgl").style.display = "none";
        getElementByID_Master("CartLiteralPlural").style.display = "none";
        (getElementByID_Master("CartItemsLBGet").innerHTML == "1") ? getElementByID_Master("CartLiteralSgl").style.display = "inline" : getElementByID_Master("CartLiteralPlural").style.display = "inline";
    }
    catch (e) { }
}

function isSecure() {
    return location.protocol == 'https:';
}

function getElementByID_Master(e) {
    var ret = null;
    ret = MM_findObj(e);
    if (ret)
        return ret;
    ret = MM_findObj("ContentPlaceHolder1_" + e);
    if (ret)
        return ret;
    ret = MM_findObj("ContentPlaceHolder1$" + e);
    if (ret)
        return ret;
    ret = MM_findObj("ctl00_ContentPlaceHolder1_" + e);
    if (ret)
        return ret;
    ret = MM_findObj("ctl00$ContentPlaceHolder1$" + e);
    if (ret)
        return ret;
    return ret;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function showMiniCart() {
    $.ajax({
        url: '/store/minicart.aspx',
        cache: false,
        success: function (html) {
            $('.myCart').html(html);
        },
        error: function (err) {
        }
    });
}

function RemoveItem(recid, qty) {
    var url = '/store/removeminicartitem.aspx?recid=' + recid;
    $('.cartList').animate({ opacity: 0.40 }, 500);
    $.ajax({
        url: url,
        cache: false,
        success: function (data) {
            $('.cartList').animate({ opacity: 0.50 }, 500);
            setTimeout(function () { showMiniCart(); }, 500);
            render_cart_header("CartItemsLBGet", "CartTotalLBGet");
            $(".cartList").animate({ opacity: 1 }, 500);
        },
        error: function (err) {
            return false;
        }
    });
}

function MM_goToURL() { //v3.0
    var i, args = MM_goToURL.arguments; document.MM_returnValue = false;
    for (i = 0; i < (args.length - 1); i += 2) eval(args[i] + ".location='" + args[i + 1] + "'");
}

function DefaultButton(btnID, event) {
    btn = getElementByID_Master(btnID);

    if (document.all) {
        if (event.keyCode == 13) {
            event.returnValue = false;
            event.cancelBubble = true;
            btn.focus();
            btn.click();
        }
    }
    else if (document.getElementById) {
        if (event.which == 13) {
            event.returnValue = false;
            event.cancelBubble = true;
            btn.click();
            btn.focus();
        }
    }
    else if (document.layers) {
        if (event.which == 13) {
            event.returnValue = false;
            event.cancelBubble = true;
            btn.focus();
            btn.click();
        }
    }
}

function getElementsByClass(className) {
    var all = document.all ? document.all : document.getElementsByTagName('*');
    var elements = new Array();
    for (var e = 0; e < all.length; e++)
        if (all[e].className == className)
            elements[elements.length] = all[e];
    return elements;
}

function toggleAnswer(id) {
    el = document.getElementById(id);
    els = getElementsByClass('answer');
    for (x in els) {
        if (els[x] != el) {
            els[x].style.display = 'none';
        }
    }
    if (el.style.display == 'block') {
        el.style.display = 'none';
    } else {
        el.style.display = 'block';
    }
}
