// JavaScript Document

function showContent(){

	if (jQuery(this).children("#nav_cart").length > 0) 
	{
		jQuery("#ssi_nav .nav-content").hide();
		return false;
	}
		
	jQuery(this).addClass("selected");
	//jQuery(this).animate({ backgroundColor: "magenta" }, 1000);
	
	if(jQuery("#ssi_nav .nav-content:visible").length)
	{
		
		jQuery("#ssi_nav .nav-content").hide();
		jQuery(this).children(".nav-content").show();
				//.animate({ backgroundColor: "silver" }, 1000);
	}
	else
	{
		jQuery(this).children(".nav-content").slideDown();
		//jQuery(this).children(".nav-content").show();
	}
	
}

function hideContent()
{
	jQuery(this).removeClass("selected");
	if (jQuery(this).children("#nav_contact").length == 0) { // don't do this for contact tab
		
		//jQuery(this).animate({ backgroundColor: "silver" }, 1000);
		
		if (jQuery("#ssi_nav .selected").length == 0) {
			//jQuery(".nav-content").slideUp();
			jQuery(".nav-content").hide();
		}
	}
}

function closeMenu()
{
	jQuery("#ssi_nav .selected").removeClass("selected"); //.animate({ backgroundColor: "silver" }, 1000).
	jQuery(".nav-content").slideUp();
}

function toggleCart()
{
	if (jQuery("#ssi-header-cart-wrapper:visible").length) {
		jQuery("#ssi-header-cart-wrapper").slideUp(function() { jQuery(this).remove() });
	}
	else {
		jQuery("#ssi_header").before('<div id="ssi-header-cart-wrapper" class="hide"><div id="ssi-header-cart" class="container_16 "><span class="cart_loading">Loading Your Cart...</span></div></div>');
		jQuery("#ssi-header-cart-wrapper").slideDown();
		jQuery.get("/store/ajax-cart/", function(e){
			jQuery("#ssi-header-cart").html(e);
			jQuery("#ssi-cart-bar").fadeIn();
			iniCartBarNav();
		});
	}
}

function moveCart(dir)
{
	if (jQuery("#cart-bar-products LI").length > 1)
	{
		if (dir == "up" && jQuery(".cart_bar_products LI:first").css("margin-top") != "0px")
		{
			jQuery(".cart_bar_products LI:first").animate({marginTop: "+=45px"},
														  	function (){ if (jQuery(".cart_bar_products LI:first").css("margin-top") == "0px") { jQuery("#cart-bar-nav .btn_up").addClass("disabled");  } });
			jQuery("#cart-bar-nav .btn_down").removeClass("disabled");
		}
		else if (dir == "down" && jQuery(".cart_bar_products LI:first").css("margin-top") != "-" + ((jQuery("#cart-bar-products LI").length - 1)*45) + "px")
		{
			jQuery(".cart_bar_products LI:first").animate({marginTop: "-=45px"},
														  	function (){ if (jQuery(".cart_bar_products LI:first").css("margin-top") == "-" + ((jQuery("#cart-bar-products LI").length - 1)*45) + "px") { jQuery("#cart-bar-nav .btn_down").addClass("disabled");  } });
			jQuery("#cart-bar-nav .btn_up").removeClass("disabled");
		}
	}
}

function iniCartBarNav()
{
	if (jQuery("#cart-bar-products LI").length == 1) 
	{
		jQuery("#cart-bar-nav .btn_down").addClass("disabled");
	}
}