//fix for IE hover issue
	sfh = function(){var sfE = document.getElementById("nav").getElementsByTagName("LI"); for (var i=sfE.length-1; i >= 0; i--) {sfE[i].onmouseover=function() { this.className+=" sfh"; }; sfE[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfh\\b"), ""); }; }}; if (window.attachEvent) window.attachEvent("onload", sfh);

	$(document).ready(function(){
		$("#tabs").tabs();
		if(readCookie("VATBTN")=='EX')
			{
			$("#toggleVatBtn").attr("value","Show Inc VAT prices");
			$(".vatInclusive").hide();
			}
		else
			{
			$(".vatExclusive").hide();
			$("#toggleVatBtn").attr("value","Show Ex VAT prices");
			}
	});


	function createCookie(name, value, days)
		{
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires=" + date.toGMTString();
			}
		else 
			var expires = "";
		document.cookie = name + "=" + value + expires + "; path=/";
		}


	function readCookie(name)
		{
		var ca = document.cookie.split(';');
		var nameEQ = name + "=";
		for(var i=0; i < ca.length; i++) 
			{
			var c = ca[i];
			while (c.charAt(0)==' ') 
				c = c.substring(1, c.length); //delete spaces
			if (c.indexOf(nameEQ) == 0) 
				return c.substring(nameEQ.length, c.length);
			}
		return null;
		}

	function AddToCart(obj,uri)
		{
		var now = new Date();
		uri=uri+'&dt='+now.getTime().toString();
		$("#pCart").load(uri,function(){
			$("#pCart").effect("highlight", {}, 1500);
			});
		$(obj).effect("highlight", {color: '#588e90'} , 1500);

		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: 0}, 500 );
		}

	function DeleteFromCart(uri,carturi)
		{
		var now = new Date();
		uri=uri+'&dt='+now.getTime().toString();
		$("#pCheckout").load(uri,function(){
			uri='AdjustCart.aspx?action=refresh';
			uri=uri+'&dt='+now.getTime().toString();
			$("#pCart").load(uri);
			$("#pCheckout").effect("highlight", {}, 1500);
			});
		}

	function ToggleVAT()
		{
		$("#toggleVatBtn").effect("highlight", {color: '#588e90'} , 1500);
		var buttonText = $("#toggleVatBtn").attr("value");
		if(buttonText=="Show Ex VAT prices")
			{
			$("#toggleVatBtn").attr("value","Show Inc VAT prices");
			$(".vatInclusive").hide();
			$(".vatExclusive").show();
			$(".vatExclusive").effect("highlight", {color: '#ddddee'}, 1300);
			createCookie('VATBTN', 'EX', 90);
			}
		else
			{
			$("#toggleVatBtn").attr("value","Show Ex VAT prices");
			$(".vatExclusive").hide();
			$(".vatInclusive").show();
			$(".vatInclusive").effect("highlight", {color: '#ddddee'}, 1300);
			createCookie('VATBTN', 'INC',90);
			}
		}
		
		function fTog(pHref,pULRef){
			if($(pHref).html().substr(0,1)=='+')
				{
				$(pULRef).show("fast");
				$(pHref).html('-'+$(pHref).html().substr(1))
				}
			else
				{
				$(pULRef).hide("slow");
				$(pHref).html('+'+$(pHref).html().substr(1))
				}
		}
		
		function goManf()
			{
			var selected=document.getElementById('list_manf').selectedIndex;
			var url=document.getElementById('list_manf').options[selected].value;
			location.href=url;
			}

		function goManfd()
			{
			var selected=document.getElementById('list_manfd').selectedIndex;
			var url=document.getElementById('list_manfd').options[selected].value;
			location.href=url;
			}

		function goType()
			{
			var selected=document.getElementById('list_type').selectedIndex;
			var url=document.getElementById('list_type').options[selected].value;
			location.href=url;
			}


		function goWSpares()
			{
			var selected=document.getElementById('list_wspares').selectedIndex;
			var url=document.getElementById('list_wspares').options[selected].value;
			location.href=url;
			}

		function goCSpares()
			{
			var selected=document.getElementById('list_cspares').selectedIndex;
			var url=document.getElementById('list_cspares').options[selected].value;
			location.href=url;
			}

function dosearch()
	{
	var url;
	var query;
	url='search.html?offset=0&';
	query=document.getElementById("q").value;
	if(query=='')
		alert("you must enter a search word or phrase");
	else
		document.location.href=url+'q='+query;
	}
	
function keyboardSearch(e)
	{
	if(window.event) // IE
		{				
		keynum = e.keyCode;
		if(keynum==13)
			{
			event.returnValue=false;
			event.cancel=true;
			dosearch();
			}
		else
			return true;
		}
	else if(e.which) // Netscape/Firefox/Opera
		{
		keynum = e.which;
		if(keynum==13)
			{
			dosearch();
			return false;
			}
		}
	}	


	function rotateUnits(id)
		{
		$("div.rotation" + id++).hide();
		if(id>3)id=1;
		$("div.rotation" + id).fadeIn('slow');
		setTimeout('rotateUnits(' + id + ');',10000);
		}
