var ie = (/MSIE/.test(navigator.userAgent)), deprecated = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32"), cH = 0, dH = 0;

function detectSafari() {
    var myBrowser = ($.browser.name);
    var myBrowserVersion = ($.browser.versionX);
    if (myBrowser == 'safari' && myBrowserVersion == 3) {
        //alert(myBrowserVersion);
        $('.totalPrice').css({ fontSize: '11px' });
        $('.mostPopularContainer li a').addClass('safari');
        return false;
    }
}

$(document).ready(function () {
    configMenus();
    detectSafari();
    showMiniCart();
    render_cart_header("CartItemsLBGet", "CartTotalLBGet");
    //Search input dissapearing & re-appearing script
    $(".input").focus(function () {
        if ($(this).attr("value") == "Enter your keyword or search for product")
        { $(this).attr("value", ""); } 
    }); $(".input").click(function () {
        if ($(this).attr("value") == "Enter your keyword or search for product")
        { $(this).attr("value", ""); } 
    }); $(".input").blur(function () {
        if ($(this).attr("value") == "")
        { $(this).attr("value", "Enter your keyword or search for product"); } 
    });

    //Search input dissapearing & re-appearing script
    $(".signup_input").focus(function () {
        if ($(this).attr("value") == "Sign up for our Newsletters and get 10% off")
        { $(this).attr("value", ""); } 
    }); $(".signup_input").click(function () {
        if ($(this).attr("value") == "Sign up for our Newsletters and get 10% off")
        { $(this).attr("value", ""); } 
    }); $(".signup_input").blur(function () {
        if ($(this).attr("value") == "")
        { $(this).attr("value", "Sign up for our Newsletters and get 10% off"); } 
    });

    $(".shopBag").hover(function () {
        $('.myBag').slideToggle('fast');
        //		$('.myBag').stop().show();
    }, function () {
        //		$('.myBag').stop().slideUp('fast');
        $('.myBag').hide();
    });
});  //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 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 showMiniCart() {
	$.ajax({
		url: '/store/minicart.aspx',
		cache: false,
		success: function (html) {
			$('.myBag').html(html);
		},
		error: function (err) {
		}
	});
}

function RemoveItem(recid, qty) {
	var url = '/store/removeminicartitem.aspx?recid=' + recid;
	$('.bagList').animate({ opacity: 0.40 }, 500);
	$.ajax({
		url: url,
		cache: false,
		success: function (data) {
			$('.bagList').animate({ opacity: 0.50 }, 500);
			setTimeout(function () { showMiniCart(); }, 500);
			render_cart_header("CartItemsLBGet", "CartTotalLBGet");
			$(".bagList").animate({ opacity: 1 }, 500);
		},
		error: function (err) {
			return false;
		}
	});
}

configMenus = function (ul) {
	$('.tab_content li').hover(function () {
		ul = $(this).children('ul.subNavMenu');
		ul.showContent('slow');
	}, function () {
		ul = $(this).children('ul.subNavMenu');
		ul.hideContent('fast');
	});
}

$.fn.showContent = function (s, cb) {
	ie ? $(this).stop(true, true).show(0, cb) : $(this).stop(true, true).fadeIn(s, cb);
}

$.fn.hideContent = function (s) {
	ie ? $(this).stop(true, true).hide() : $(this).stop(true, true).fadeOut(s);
}

configSlideshow = function () {
    var $slidePaging = $('#foo2_prev, #foo2_next', '.slider');

    $slidePaging.hide();

    $('.slider').filter(function () {
        return !$(this).hasClass('single');
    }).on({
        mouseenter: function () {
            $slidePaging.show();
        },
        mouseleave: function () {
            $slidePaging.hide();
        }
    });

    $('.toolTip').on({
        mouseenter: function () {
            $(this).next('.toolTipMsg').show();
        },
        mouseleave: function () {
            $(this).next('.toolTipMsg').hide();
        }
    });
};
