$(function(){
	$("#catalog ul:not(:has(li))").remove();

	$("#featured-category ul:not(:has(li))").remove();
	$("#featured-category ul ul").each(function(){
		if($(this).find("li").length < 8)
			$(this).width(parseInt($(this).css("width"), 10) / 2);
	});
	if($("#item-count").val() == "0")
	{
		$(".small-cart-load").append('<div class="small-cart-empty background text-color-medium">There are no items in your Cart.</div>');
		$(".small-cart-load").removeClass('loading');
	}
	$("#link-sign-out").click(function(){
		$.get("Ajax.aspx?CN=674F3FAADE3B&MLOGIN=SIGNOUT"+ UrlNoCache(), function() {
			window.location = 'Portal.aspx';
		});
	});
	if($("#text-shop-on-behalf-of").length > 0)
		InitShopBehalf();
	$("#site-search a").click(function(){
		SearchSite();
	});
	$("#site-search-box").keydown(function(e){
		if(e.keyCode == '13')
		{
			SearchSite();
			return false;
		}
	});
	$("#site-search-box").focus(function(){
		if($(this).val() == $(this).attr("data-message"))
		{
			$(this).addClass("dark");
			$(this).val("");
		}
	});
	$("#site-search-box").blur(function(){
		if($(this).val() == "")
		{
			$(this).removeClass("dark");
			$(this).val($(this).attr("data-message"));
		}
	});
	if($("#session-bar-chat").length > 0)
	{
		var click = "window.open('Portal.aspx?CN=26A0F3F34A0E','Chat','width=900,height=500,resizable=yes,scrollbars=no,toolbar=no,location=no,titlebar=no,directories=no,status=no,menubar=no,copyhistory=no')";
		$("#chat").html('<a onclick="'+ click +'" class="num-'+ $("#session-bar-chat").val() +' link-C">Chat <span>('+ $("#session-bar-chat").val() +')</span></a>');
	}
	$("#cart").mouseenter(function(){
		if($("#cart-details").html() == "")
		{
			$("#cart-details").html('<div class="empty-loading"></div>');
			$("#cart-details").AjaxCall({
				loading: false,
				url: "Ajax.aspx?CN=87124824C5F9",
				complete: function(){
					$("#small-shopping-cart").css("background-image","none");
				}
			});
		}
	});
});
function UpdateCartTotals(Count, Subtotal)
{
	if(Count == undefined)
		Count = "";
	if(Subtotal == undefined)
		Subtotal = "";
	$("#cart-details").empty();
	$("#shopping-cart-item-count").html(Count);
	//$("#shopping-cart-subtotal").html(Subtotal);
}
function SearchSite()
{
	if($("#site-search-box").val() == $("#site-search-box").attr("data-message"))
		$("#site-search-box").val("");

	window.location = "Portal.aspx?CN=9CE97316BE98&SEARCH="+ encodeURIComponent($("#site-search-box").val());
}
function InitShopBehalf()
{
	var text = $("#text-shop-on-behalf-of").val();
	$("#shop-on-behalf-of").html('Customer: <a href="Portal.aspx?CN=F329203E00C3&ACCOUNTID='+ $("#text-shop-on-behalf-of").attr("data-id") +'" class="link-C user">'+ $("#text-shop-on-behalf-of").val() +'</a><a data-remove="remove" class="link-D">Remove</a>');
	$("#shop-on-behalf-of a[data-remove]").click(function(){
		if(confirm("Click OK to continue to remove customer from session"))
		{
			$().AjaxCall({
				url: "Ajax.aspx?CN=F1284669751D&ACTION1=EX",
				complete: function(){
					window.location.reload(true);
				}
			});
		}
	});
}
function SessionBarSignIn()
{
	PostPanel("Ajax.aspx?CN=674F3FAADE3B", "#sign-in");
}
