		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 = $("#subcatItems" + subcatid + " li");
			if (subcatid==865 )
			{subcatItemLimit=6;}
			if (subcatid==861 || subcatid==862 || subcatid==863 || subcatid==866 || subcatid==439 || subcatid==438  )
			{subcatItemLimit=3;}
			
			//alert(prodState[subcatid]);
			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)
						{
							$(d.get(i)).hide();
						}
						else
						{
							//$(d.get(i)).css({"border-bottom-style": "none"});
						}
					}
					
					$("#toggleProducts" + subcatid).text(glueText["showAllProducts"] + " (" + d.length + ")");
					if ($("#toggleProductsIcon" + subcatid).length > 0)
						$("#toggleProductsIcon" + subcatid).get(0).src  = $("#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++)
					{
						$(d.get(i)).show();
						//$(d.get(i)).css({"border-bottom-style": "solid"});
					}
					
					$("#toggleProducts" + subcatid).text(glueText["showMostPopularProducts"]);
					
					if ($("#toggleProductsIcon" + subcatid).length > 0) $("#toggleProductsIcon" + subcatid).get(0).src = $("#toggleProductsIcon" + subcatid).get(0).src.replace(/down/, "up");
					//alert($("#toggleProductsIcon" + subcatid).get(0).style.background);// = $("#toggleProductsIcon" + subcatid).get(0).src.replace(/down/, "up");
				}			
			}
			return false;
		}
		
		function toggleMP3Players()
		{
			if (prodState[catid] == "hide")
			{
				// Show all the MP3 Players
				showAllMP3Players()
				prodState[catid] = "show";					
				$(".toggleProducts").text(glueText["showMostPopularProducts"]);
			}
			else
			{
				// Show only ZEN players
				showPopularMP3Players();
				prodState[catid] = "hide";				
				var d = $("#subcatItems214 li");
				$(".toggleProducts").text(glueText["showAllProducts"] + " (" + d.length + ")");
			}
		}		

		function toggleWebCameras()
		{
			if (prodState[catid] == "hide")
			{
				// Show all the Webcams
				prodState[catid] = "show";
				showAllWebCameras();
				$(".toggleProducts").text(glueText["showMostPopularProducts"]);
			}
			else
			{
				// Show only the Live! Cam series
				prodState[catid] = "hide";
				showPopularWebCameras();
				var d = $("#subcatItems846 li");
				$(".toggleProducts").text(glueText["showAllProducts"] + " (" + 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 = $(".subcatHeaderNew");
			var items = $(".subcatItems");
            
			items.each(function(i){
				p = $("#" + this.id + " li");
                 if (this.id=='subcatItems865' )
			    {subcatItemLimit=6;}
			    if (this.id=='subcatItems861'  || this.id=='subcatItems862' || this.id=='subcatItems863' || this.id=='subcatItems866' || this.id=='subcatItems439' || this.id=='subcatItems438')
			    {subcatItemLimit=3;}
				if (p.length > subcatItemLimit)
				{
					p.each(function(j){
						if (j>subcatItemLimit-1)
						{
							$(this).hide();
						}
						else
						{
							// Hide the bottom border
							//$(this).css({"border-bottom-style": "none"});
						}
					});
					$("#link" + (this.id).replace('subcatItems','')).show();
					$("#arw" + (this.id).replace('subcatItems','')).show();
				}
				else
				{$("#link" + (this.id).replace('subcatItems','')).hide();
					$("#arw" + (this.id).replace('subcatItems','')).hide();}
			});
		}
		
		function showPopularMP3Players()
		{
		    if (subcateid==215)
			{
			    showMuVo()
			}
			else
			{
			    $("#subcatHeader215").hide();
			    $("#subcatItems215").hide();
			    prodState[213]="hide";

			    var d = $("#subcatItems214 li");

			    if (d.length > subcatItemLimit)
			    {
				    for(var i=0;i<d.length;i++)
				    {
					    if (i > subcatItemLimit - 1 )
					    {
						    d[i].style.display = "none";
					    }
					    else
					    {
						    //$(d.get(i)).css({"border-bottom-style": "none"});
					    }
				    }	
			    }
			}
		}
		
		function showAllMP3Players()
		{
			//alert('aaa');
			// Show all the MP3 Players
			$(".subcatHeaderNew").show();
			$(".subcatItems").show();			
			$(".toggleProducts").text = glueText["showMostPopularProducts"];

			prodState[213]="show";
			
			var d = $("#subcatItems214 li");
			if (d.length > subcatItemLimit)
			{
				for(var i=subcatItemLimit;i<d.length;i++)
				{
					d[i].style.display = "block";
					//$(d.get(i)).css({"border-bottom-style": "solid"});
				}	
			}			
			
			return false;
		}			

		function showPopularWebCameras()
		{
			// Shows only the Live! Cam series
			if (subcateid==847)
			{
			    showWebCamSeries();
		    }
			else
			{
			    $("#subcatHeader847").hide();
			    $("#subcatItems847").hide();
    //            $(".subcatHeaderNew").show();
    //			$(".subcatItems").show();		
			    prodState[218]="hide";
    //			prodState[218]="show";	
			    var d = document.getElementById("subcatItems846").getElementsByTagName("li");

			    if (d.length > subcatItemLimit)
			    {
				    for(var i=subcatItemLimit;i<d.length;i++)
				    {
					    d[i].style.display = "none";
				    }	
			    }
			    $(".toggleProducts").text(glueText["showAllProducts"] + " (" + d.length + ")");
			}
			
		}
		
		function showAllWebCameras()
		{
			// Shows all the Webcams
			$(".subcatHeaderNew").show();
			$(".subcatItems").show();			
			$(".toggleProducts").text(glueText["showMostPopularProducts"]);
			prodState[218]="show";
			
			var d = $("#subcatItems846 li");
			if (d.length > subcatItemLimit)
			{
				for(var i=subcatItemLimit;i<d.length;i++)
				{
					d[i].style.display = "block";
				}	
			}			
			
			return false;
		}			

		function showWebCamSeries()
		{
			// Shows all the Webcam Series
			$(".subcatHeaderNew").show();
			$("#subcatItems847").show();
			prodState[847]="show";
			return false;
		}	
		
		function showMuVo()
		{
			// Shows all the MuVo MP3 Players
			$(".subcatHeaderNew").show();
			$("#subcatItems215").show();
			prodState[215]="show";
			return false;
		}		
		
		function showAccessories()
		{
			// Show all the accessories
			accState = "show";
			$("#accessoryContainer").slideDown(1000, function(){ 
				$("#accessoryContainer li").show();
				gotoAccessories();
			});
			$("#toggleAccessories").text(glueText["hideAccessories"]);

			return false;
		}

		function hideAccessories()
		{
			// Hides the accessories
			accState = "hide";
			$("#accessoryContainer").slideUp(1000);
			$("#toggleAccessories").text(glueText["viewAccessories"]);
			
			location.href = location.href.replace(/\#accessories/, "");
			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;
			if (accState == "show")
			{
				location.href = "#accessories";
			}
		}
		
		// Initialise everything
		$(document).ready(function() {

			// hover fix for IE 6.x
			if ($.browser.msie) {
				if (parseInt($.browser.version) == 6)
				{
					sfHover2();	
				}
			}

			if (catid == 213)
			{
				showPopularMP3Players();

				$("#lnkSubCat214").click(function(){
					showAllMP3Players();
					prodState[catid] = "show";
					$(".toggleProducts").text(glueText["showMostPopularProducts"]);
				});
				
				$("#lnkSubCat215").click(function(){
					//showAllMP3Players();
					//prodState[catid] == "show";
					//$(".toggleProducts").text(glueText["showMostPopularProducts"]);
					showMuVo();
				});
			}
			else
			{
				if (catid == 218)
				{
					if (ncountryid != 86)
					{
						showPopularWebCameras();
					
						$("#lnkSubCat847").click(function(){
							showWebCamSeries();
						});					
					}
					
				}
				else
				{
					showPopularProducts();
				}
			}
			
			if (location.href.indexOf("#accessories") > 0)
			{
				$("#accessoryContainer").show(function(){
					$("#accessoryContainer li").show();
					accState="show";
					$("#toggleAccessories").text(glueText["hideAccessories"]);
					gotoAccessories();
				});
			}
			
			if (location.href.indexOf("#subcat") > 0)
			{
				var hashPos = location.href.indexOf("#subcat");
				var subcatID = location.href.substring(hashPos).replace("#subcat", "");
				if (catid == 213)
				{
					prodState[catid] = "show";
					//showAllMP3Players();
					showMuVo();
					//$(".toggleProducts").text(glueText["showMostPopularProducts"]);

				}
				else 
				{
					if (catid == 218)
					{
						prodState[catid] = "show";
						showWebCamSeries();
						//$(".toggleProducts").text(glueText["showMostPopularProducts"]);
					}
				}
			}

			if (location.href.indexOf("#") > 0)
			{
				var hashPos = location.href.indexOf("#");
				window.location.hash= location.href.substring(hashPos).replace("#", "");
			}
		});
