		var accState="hide";
		var prodState = new Object;
		prodState[catid] = "hide";
		
		sfHover2 = function() 
		{
			if (!document.getElementsByTagName) 
			{
				return false;
			}
			var sfEls = document.getElementById("mainCatNav").getElementsByTagName("li");
			
			for (var i=0; i<sfEls.length; i++) 
			{
				sfEls[i].onmouseover=function() 
				{
					this.className+=" sfhover";
				}
				sfEls[i].onmouseout=function() 
				{
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}	
		}
		
		function toggleProducts(subcatid)
		{
			var d = jQuery("#subcatItems" + subcatid + " li");
			if (prodState[subcatid] == "show")
			{
				// Show the most popular products only
				prodState[subcatid] = "hide";
					
				if (d.length > subcatItemLimit)
				{
					for (var i=0;i<d.length;i++)
					{
						if (i > subcatItemLimit - 1)
						{
							jQuery(d.get(i)).hide();
						}
						else
						{
							//jQuery(d.get(i)).css({"border-bottom-style": "none"});
						}
					}
					jQuery("#toggleProducts" + subcatid).text("Show all products (" + d.length + ")");
					if (jQuery("#toggleProductsIcon" + subcatid).length > 0)
						jQuery("#toggleProductsIcon" + subcatid).get(0).src  = jQuery("#toggleProductsIcon" + subcatid).get(0).src.replace(/up/, "down");
				}
			}
			else
			{
				// Show all the products
				prodState[subcatid] = "show";
				if (d.length > subcatItemLimit)
				{
					for (var i=0;i<d.length;i++)
					{
						jQuery(d.get(i)).show();
						//jQuery(d.get(i)).css({"border-bottom-style": "solid"});
					}
					
					jQuery("#toggleProducts" + subcatid).text("Show most popular products");
					if (jQuery("#toggleProductsIcon" + subcatid).length > 0) jQuery("#toggleProductsIcon" + subcatid).get(0).src = jQuery("#toggleProductsIcon" + subcatid).get(0).src.replace(/down/, "up");
				}			
			}
			return false;
		}
		
		function toggleMP3Players()
		{
			if (prodState[catid] == "hide")
			{
				// Show all the MP3 Players
				prodState[catid] = "show";
				showAllMP3Players()
				jQuery(".toggleProducts").text("Show most popular products");
			}
			else
			{
				// Show only ZEN players
				prodState[catid] = "hide";
				showPopularMP3Players();
				var d = jQuery("#subcatItems214 li");
				jQuery(".toggleProducts").text("Show all products (" + d.length + ")");
			}
		}		

		function toggleWebCameras()
		{
			if (prodState[catid] == "hide")
			{
				// Show all the Webcams
				prodState[catid] = "show";
				showAllWebCameras();
				jQuery(".toggleProducts").text("Show most popular products");
			}
			else
			{
				// Show only the Live! Cam series
				prodState[catid] = "hide";
				showPopularWebCameras();
				var d = jQuery("#subcatItems846 li");
				jQuery(".toggleProducts").text("Show all products (" + d.length + ")");
			}
		}		

		function toggleAccessories()
		{
			if (accState == "hide")
			{
				// Show the accessories
				accState = "show";
				showAccessories()
			}
			else
			{
				// Hide the accessories
				accState = "hide";
				hideAccessories();
			}
			return false;
		}		
	
		function showPopularProducts()
		{
			// Hide all the products except the 1st few (set via the subcatItemLimit variable) E.g. 1st 3 for HPP, 1st 6 for the rest.
			var headers = jQuery(".subcatHeaderNew");
			var items = jQuery(".subcatItems");

			items.each(function(i){
				p = jQuery("#" + this.id + " li");
                a = jQuery("#" + this.id.replace("subcatItems","subcatHeader") + " .toggleAccessories").html();
				if (p.length > subcatItemLimit && a==null)
				{
					p.each(function(j){
						if (j>subcatItemLimit-1)
						{
							jQuery(this).hide();
						}
						else
						{
							// Hide the bottom border
							//jQuery(this).css({"border-bottom-style": "none"});
						}
					});
				}
			});
		}
		
		function showPopularMP3Players()
		{
			// Shows all the MP3 Players
			jQuery("#subcatHeader215").hide();
			jQuery("#subcatItems215").hide();

			var d = jQuery("#subcatItems214 li");

			if (d.length > subcatItemLimit)
			{
				for(var i=0;i<d.length;i++)
				{
					if (i > subcatItemLimit - 1 )
					{
						d[i].style.display = "none";
					}
					else
					{
						//jQuery(d.get(i)).css({"border-bottom-style": "none"});
					}
				}	
			}
		}
		
		function showAllMP3Players()
		{
			// Show all the MP3 Players
			jQuery(".subcatHeaderNew").show();
			jQuery(".subcatItems").show();			
			jQuery(".toggleProducts").text = "Show most popular products";

			var d = jQuery("#subcatItems214 li");
			if (d.length > subcatItemLimit)
			{
				for(var i=subcatItemLimit;i<d.length;i++)
				{
					d[i].style.display = "block";
					//jQuery(d.get(i)).css({"border-bottom-style": "solid"});
				}	
			}			
			
			return false;
		}			

		function showPopularWebCameras()
		{
			// Shows only the Live! Cam series
			jQuery("#subcatHeader847").hide();
			jQuery("#subcatItems847").hide();

			var d = document.getElementById("subcatItems846").getElementsByTagName("li");

			if (d.length > subcatItemLimit)
			{
				for(var i=subcatItemLimit;i<d.length;i++)
				{
					d[i].style.display = "none";
				}	
			}
			jQuery(".toggleProducts").text("Show all products (" + d.length + ")");
		}
		
		function showAllWebCameras()
		{
			// Shows all the Webcams
			jQuery(".subcatHeaderNew").show();
			jQuery(".subcatItems").show();			
			jQuery(".toggleProducts").text("Show most popular products");
			
			var d = jQuery("#subcatItems846 li");
			if (d.length > subcatItemLimit)
			{
				for(var i=subcatItemLimit;i<d.length;i++)
				{
					d[i].style.display = "block";
				}	
			}			
			
			return false;
		}			
		
		function showAccessories()
		{
			// Show all the accessories
			accState = "show";
			jQuery("#accessoryContainer").slideDown(1000, function(){ gotoAccessories() });
			jQuery("#toggleAccessories").text("Hide accessories");
			
			gotoAccessories();

			return false;
		}
		
		function gotoAccessories()
		{
			// Anchor link to the accessories section of the page
			var hashLocation=location.href.indexOf("#");
			var currentURL;
			
			currentURL = hashLocation > 0 ? location.href.substring(0, hashLocation) : location.href;

			location.href = currentURL + "#accessories";
		}
		
		function hideAccessories()
		{
			// Hides the accessories
			accState = "hide";
			jQuery("#accessoryContainer").slideUp(1000);
			jQuery("#toggleAccessories").text("View accessories");
			
			location.href = location.href.replace(/\#accessories/, "");
			return false;		
		}

		// Initialise everything
		jQuery(document).ready(function() {

			// hover fix for IE 6.x
			if (jQuery.browser.msie) {
				if (parseInt(jQuery.browser.version) == 6)
				{
					sfHover2();	
				}
			}

			if (catid == 213)
			{
				showPopularMP3Players();
				
				jQuery("#lnkSubCat215").click(function(){
					showAllMP3Players();
				});
			}
			else
			{
				if (catid == 218)
				{
					showPopularWebCameras();
					
					jQuery("#lnkSubCat847").click(function(){
						showAllWebCameras();
					});					
					
				}
				else
				{
					showPopularProducts();
				}
			}
			
			if (location.href.indexOf("accessories") > 0)
			{
				jQuery("#accessoryContainer").show(function(){
					accState="show";
					jQuery("#toggleAccessories").text("Hide accessories");
					gotoAccessories();
				});
			}
		});
