//=============================================================================
TFuntasticNovelties = {};

TFuntasticNovelties.MenuMoving = false;

//=============================================================================
TFuntasticNovelties.OnInit = function() {
	$(".Navigation li:last-child").css("background-image", "none"); //IE Fix

	$("#BannersPrevious").bind("click", TBanners.Previous);
	$("#BannersNext").bind("click", TBanners.Next);

	$(".Option").hover(function() {
		$(this).css("background-color", "#eeeeee");
	}, function(){
		$(this).css("background-color", "transparent");
	}).bind("click", function(e) {
		$(this).parent().parent().children(".Chosen").html($(this).html());
		$(this).parent().parent().children(".Chosen").attr("rel", $(this).attr("rel"));
	});

	$(window.document).click(function(e) {
		if(!$(e.target).hasClass("Chosen")) {
			$(".InputSelect").children(".OptionList").slideUp();
		}
	});
	
	$(".InputSelect").click(function(e) {
		var self = $(this).get(0);

		$(".InputSelect").each(function() {
			if(self == $(this).get(0)) return;

			$(this).children(".OptionList").slideUp();
		});

		$(this).children(".OptionList").slideToggle();
		
		e.stopPropagation();
	});

	$("#ProductsLink").data("OnMenu", false);

	$("#ProductsLink").bind("mouseover", function() {
		if(TFuntasticNovelties.MenuMoving) return;

		TFuntasticNovelties.MenuMoving = true;

		$("#Products").slideDown("fast", function() {
			TFuntasticNovelties.MenuMoving = false;
		});

		$("#ProductsLink").data("OnMenu", true);
	}).bind("mouseout", function() {
		if(TFuntasticNovelties.MenuMoving) return;

		$("#ProductsLink").data("OnMenu", false);

		setTimeout(function() {
			if($("#ProductsLink").data("OnMenu")) {
				return;
			}else{
				TFuntasticNovelties.MenuMoving = true;

				$("#Products").slideUp("fast", function() {
					TFuntasticNovelties.MenuMoving = false;
				});
			}
		}, 500);
	});

	$("#Products").bind("mouseover", function() {
		$("#ProductsLink").data("OnMenu", true);
	}).bind("mouseout", function() {
		if(TFuntasticNovelties.MenuMoving) return;

		$("#ProductsLink").data("OnMenu", false);

		setTimeout(function() {
			if($("#ProductsLink").data("OnMenu")) {
				return;
			}else{
				TFuntasticNovelties.MenuMoving = true;

				$("#Products").slideUp("fast", function() {
					TFuntasticNovelties.MenuMoving = false;
				});
			}
		}, 500);
	});
}

//=============================================================================
TFuntasticNovelties.AdvSearch = function() {
	var Parms = {
		"CategoryID"	: $("#Category").attr("rel"),
		"PriceRange"	: $("#PriceRange").attr("rel"),
		"OnSale"		: ($("#OnSale").attr("checked") ? 1 : 0),
		"InStock"		: ($("#InStock").attr("checked") ? 1 : 0)
	};

	document.location.href = "/adv-search.php?CategoryID=" + Parms["CategoryID"] + "&PriceRange=" + Parms["PriceRange"] + "&OnSale=" + Parms["OnSale"] + "&InStock=" + Parms["InStock"];
}

TFuntasticNovelties.SearchGo = function() {
	var Keywords = $('#SidebarSearchContentKeywords').attr('value');

	Keywords = Keywords.replace(/\//g, "-");

	document.location.href = '/search/' + Keywords;
}

//=============================================================================
TFuntasticNovelties.ContactUs = function(StoresID) {
	var Email		= $("#DropLineEmail").attr("value");
	var Comments	= $("#DropLineMessage").attr("value");

	CAJAX.Add("FuntasticNovelties", "Template", "ContactUs", {"StoresID" : StoresID, "Email" : Email, "Comments" : Comments}, function(Code, Content) {
		if(Code == 1) {
			document.location.href = "/thank-you.php";
		}else{
			alert(Content);

			$("#DropLineEmail").focus();
		}
	});
}

//=============================================================================
TFuntasticNovelties.EmailList = function(StoresID) {
	var Email = $("#EmailListInput").attr("value");

	CAJAX.Add("FuntasticNovelties", "Template", "EmailList", {"StoresID" : StoresID, "Email" : Email}, function(Code, Content) {
		if(Code == 1) {
			document.location.href = "/thank-you-email-list.php";
		}else{
			alert(Content);

			$("#EmailListInput").focus();
		}
	});
}

//=============================================================================
TFuntasticNovelties.AddToCart = function(ProductID, NormalID, ProductsShippingMethodsID) {
	var NormalOptionID		= 0;
	var Quantity			= parseInt($("#Quantity").attr("value"));

	if(Quantity <= 0 || isNaN(Quantity)) {
		alert("Please enter a valid Quantity");
		$("#Quantity").focus();
		return;
	}

	var Parms = {
		"ProductsID"			: ProductID,
		"ProductsShippingMethodsID" : ProductsShippingMethodsID,

		"NormalOptionID"		: NormalID,
		"ImprintOptionID"		: 0,
		"NumColors"				: 0,

		"NormalOptionColors"	: JSON.stringify({}),
		"ImprintOptionColors"	: JSON.stringify({}),

		"Quantity"				: Quantity,

		"Artwork"				: ""
	};

	MCarts.AddToCart(Parms, function(Code, Content) {
		if(Code == 1) {
			document.location.href = "/viewcart.php?GoBack=" + encodeURIComponent(CURL.GetBasePage());
		}else{
		//	alert(Content);
		}
	})
}

//=============================================================================
$(TFuntasticNovelties.OnInit);

//=============================================================================

