	$(document).ready(function(){
		
		function sitemapToggle() { // Function to toggle sitemap visibility
			var currentState = $("#sitemap .sixcol").css("display"); // Is the sitemap visible?
			switch (currentState){
				case "block": // If it is VISIBLE
					$("#sitemap .sixcol").slideUp("slow"); // HIDE it
					$("#sitemapGraphic").css("background-position", "0 -26px");
					$.cookie('sitemapVisible', 'false'); // Change the cookie
					break;
				case "none": // If it is HIDDEN
					$("#sitemap .sixcol").slideDown("slow"); // Show it
					$("#sitemapGraphic").css("background-position", "0 0");
					$.cookie('sitemapVisible', 'true'); // Change the cookie
					break;
					
			}
		}
		
		var sitemapVisible = $.cookie('sitemapVisible');
		
		
		if ($('#home-top').length) { 
			var pageNum = "1";
		}
		
		else {
			var pageNum = "2";
		}
		
		
		$("#sitemapGraphic").live("click", function() { // If sitemap graphic is clicked
			sitemapToggle(); // Toggle the visibility
		});
		
		
		
		if( pageNum == "1" && ( sitemapVisible == null || sitemapVisible == "true" ) ) { // If the page is the homepage and the cookie says visible TRUE or has not been set
			$("#sitemapGraphic").replaceWith('<div id="sitemapGraphic" style="padding: 0; width: 130px; height: 26px; background: url(templates/default/images/sitemap.gif) 0 0 no-repeat; border: none; cursor: pointer;">&nbsp;</div>');
			$("#sitemap .sixcol").show(); // SHOW the sitemap
		}

		else if( pageNum == "1" && sitemapVisible == "false" ) { // If the page IS the homepage and the cookie says visible FALSE
			$("#sitemapGraphic").replaceWith('<div id="sitemapGraphic" style="padding: 0; width: 130px; height: 26px; background: url(templates/default/images/sitemap.gif) 0 -26px no-repeat; border: none; cursor: pointer;">&nbsp;</div>');
			$("#sitemap .sixcol").hide(); // HIDE the sitemap
		}
		
		else if ( pageNum != "1" && ( sitemapVisible == null || sitemapVisible == "false" ) ) { // If the page is NOT the homepage and the cookie says visible FALSE or has not been set
			$("#sitemapGraphic").replaceWith('<div id="sitemapGraphic" style="padding: 0; width: 130px; height: 26px; background: url(templates/default/images/sitemap.gif) 0 -26px no-repeat; border: none; cursor: pointer;">&nbsp;</div>');
			$("#sitemap .sixcol").hide(); // HIDE the sitemap
		}
		
		else if ( pageNum != "1" && sitemapVisible == "true" ) { // If the page is NOT the homepage and the cookie says visible TRUE
			$("#sitemapGraphic").replaceWith('<div id="sitemapGraphic" style="padding: 0; width: 130px; height: 26px; background: url(templates/default/images/sitemap.gif) 0 0 no-repeat; border: none; cursor: pointer;">&nbsp;</div>');
			$("#sitemap .sixcol").show(); // SHOW the sitemap
		}
		
	});