// JavaScript Document
	var navTimeout = null;
	var navDisplayed = null;
	var navButtonSelected = null;
	

  $(document).ready(function() {
							 

	$("#sagepay_go").click (function ()
	{

		$.ajax({
			url: 'iwa/include/ajax/sagepay_go.php',
			type: "POST",
			cache: false,
		  
			success: function(response)
			{
				if(response == "@@NOT LOCKED@@")
				{
					window.location.href="?itemID=1101";
				}
				else if (response != "")
				{
					alert("Error initializing SagePay transfer: " + response);
				}
				else
				{
					document.VSPForm.submit();
				}
				
			},
			error: function(data)
			{
				alert("Error initializing SagePay transfer: " + data.status);
			}		
		});


	});
							 
	$(".feature_category").click(function ()
	{
		window.location.href=$(this).children("a").attr("href");
	});
	
	
	$('.table_checkout_address input').bind('keydown', function (e)
	{
		var key = e.keyCode || e.which;
		if (key === 13)
		{
			e.preventDefault();
		}
	
	});   
	
	$(".home_worldwide_delivery").click(function ()
	{
		window.location.href="delivery_information.php";
	});
					 
							 
							 
	$(".audio li").hover(
		function ()
		{

			$("#title_media_3").html($(this).find("img").attr("title"));
			//alert("in");
		},
		function ()
		{
			$("#title_media_3").html("");
			//alert("out");
		}
								 
	);
	
	
	$("#panel_checkout_postcode input").keypress( function (event) {
		if (event.which == 13)
		{
			document.form1.doWhat.value='updateQuantities';
		//	alert(document.form1.doWhat.value);
//			submit();
	//		return false;	
		}
	});
	
	
	$("#frmEnquirySubmit").live("click", function ()
	{
		var vars = "Customer Name=" + $("#Question_CustomerName").val() + "&Email_Address=" + $("#Question_CustomerEmail").val()  + "&Phone=" + $("#Question_CustomerPhone").val()  + "&Product=" + $("#Question_Product").val()  + "&Question=" + $("#Question").val();
	
		$.ajax({
			url: 'iwa/include/ajax/enquiry.php',
			data: vars,
			type: "POST",
			cache: false,
		  
			success: function(response)
			{
				//alert(response);
				
				$(".frmQuestionResponse").html(response);
				$(".frmQuestionResponse").css("display", "block");
				$(".frmQuestionEnq").css("display", "none");
				
			},
			error: function(data)
			{
				alert("Error submitting question: " + data.status);
			}		
		});
	});





	
							 
	//If set, unhighlight the previously saelcted tab
/*

$(".topNav li").mouseenter(function () {

	if (navButtonSelected)
		navButtonSelected.css("background-color", "");


	$(this).css("background-color", "#80B796");
	
	if (navTimeout)
		clearTimeout(navTimeout);


	  $("#topNav_expand").clearQueue();
	  $("#topNav_expand").animate({"height": "250px"}, "fast");
	  
	  navButtonSelected = $(this);

});

$(".topNav li").mouseleave(function () {
//	$(this).css("background-color", "");
	navTimeout = setTimeout("hideTopNavExpand()", 100);
});

$("#topNav_expand").mouseleave(function () {
	navTimeout = setTimeout("hideTopNavExpand()", 100);
});

$("#topNav_expand").mouseenter(function () {
	if (navTimeout)
		clearTimeout(navTimeout);
	//									alert("over ex");
//	  $("#topNav_expand").clearQueue();
	//  $("#topNav_expand").animate({"height": "0px"}, "fast");
});


*/

							 });
  
  /*
  function hideTopNavExpand()
  {
	  $("#topNav_expand").clearQueue();
	  $("#topNav_expand").animate({"height": "0px"}, "fast");

	if (navButtonSelected)
		navButtonSelected.css("background-color", "");

  }
  
	function navigationChange(navID)
	{
		var objExpand = document.getElementById("topNav_expand");
		var objLI = document.getElementById("expand_" + navID);
//alert("nav ahnge" + navID);

		if (navDisplayed)
			navDisplayed.style.display = "none";

		objLI.style.display = "block";
		
		
		navDisplayed = objLI;
	}
	

*/

	function buy()
	{
		if (document.getElementById("panel_variants"))
		{
			text = getVariantString();
			human_variant_text = getHumanVariantString();
		}
		else
		{
			text = "";
			human_variant_text = "";
		}
		
		thumbnailFile = "";
		if (document.getElementById("mainImage") != null)
			var thumbnailFile = document.getElementById("mainImage").src;
		
		actionAjaxPost("buy.php", "&basket_mode=&doWhat=add&quantity=1&thumbnailFile=" + thumbnailFile + "&variantID=" + document.form1.selectedVariantID.value + text + human_variant_text + "&thingID=" + document.form1.itemID.value, "buy_response");
			 
		
	}
	
	function buy_response()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			var response = xmlHttp.responseText;
			
			updateMiniBasket();
			if (response != "")
				alert("Error while adding item to basket: '" + response + "'");
			
			$("#pagefade").css("opacity", "0.7");
			$("#pagefade").fadeIn(100);
			$("#popup_added_to_basket").fadeIn(100);
//			var popup = document.getElementById();
			
		}
	}
	
	function buy_close()
	{
		$("#pagefade").fadeOut(100);
		$("#popup_added_to_basket").fadeOut(100);
	}
	
	function updateMiniBasket()
	{
		actionAjax("minibasket.php?ug=1", "updateMiniBasket_response");
	}
	function updateMiniBasket_response()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			var response = xmlHttp.responseText.split(",");
			
			document.getElementById("items").innerHTML = "Items: " + response[0];
			document.getElementById("price").innerHTML = "Total: " + response[1];
			
		//	alert(response);
			
			
			
		}
	}
	
	
	

		function click_checkout(deliveryServiceID)
	{
		var objDeliverySelect = document.form1.delivery_service_id;
//		alert(objDeliverySelect.selectedIndex);
	
		if (checkout_temporary_message != "")
		{
			alert(checkout_temporary_message);	
		}
	
	
		if (objDeliverySelect && objDeliverySelect.value != -1 && objDeliverySelect.selectedIndex != -1)
		{
//			


//		alert("Checkout B...");




			$.ajax({
				url: 'iwa/include/ajax/checkout_lock.php',
				cache: false,
			  
				success: function(response)
				{
					if (response != "ok")
					{
						alert("Error initializing checkout: " + response);
					}
					else
					{
						document.form1.doWhat.value="checkout_address";
						document.form1.submit();
		
					}
					
				},
				error: function(data)
				{
					alert("Error 0 initializing checkout: " + data.status);
				}		
			});


	 
		}
		else
		{
			document.form1.action = "";
			
			alert("Please choose a delivery service before clicking the checkout button.");
			
			return false;

		}
		//	alert(document.form1.doWhat.value);
	
	}	
	

	
	
	
	function showPopupInfoPanel(friendlyID, itemDesc)
	{
		actionAjax("popup_info.php?friendlyID=" + friendlyID + "&itemDesc=" + itemDesc, "showPopupInfoPanel_response");
	}
	function showPopupInfoPanel_response()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			response = xmlHttp.responseText;
			
			
			$("#pagefade").css("opacity", "0.7");
			$("#pagefade").fadeIn(100);
			$("#popup_info_panel_text").attr("innerHTML", response);
			$("#popup_info_panel").fadeIn(100);

		}
	}
	
	
		
	function hidePageTrans()
	{
		$("#pagefade").fadeOut(100);
	//	alert("close");
	}
	function hidePopupInfoPanel()
	{
		//alert("close");
		hidePageTrans();
		$("#popup_info_panel").fadeOut(100);

	}
	
