jQuery(document).ready(function($) {



	// On some pages (especially single-SWF ones), the Grownup Bar will need special removal within a single DOM.
	// Call this function to on-demand-remove the Grownup Bar.
	function removeGrownupBar() {
		if($(".grownupBar").length != 0) {
			if($(".grownupBar").is(":visible")) {
				$(".grownupBar").hide();
				$("body").addClass("restoreDefaults");
			}
		}
	}

	function showGrownupBar() {
		if($(".grownupBar").length != 0) {
			if(!$(".grownupBar").is(":visible")) {
				$(".grownupBar").show();
				if($("body").hasClass("restoreDefaults")) {
					$("body").removeClass("restoreDefaults");					
				}
			}
		}
	}



	// Testing trigger.
	if($("#testRemoval").length != 0) {
		$("#testRemoval").click(function(){
			removeGrownupBar();
		});
	}



	// Instantiating events. (Hash changes)



	// IMPLEMENTATION #1: SESAME STREET
	if($(".grownupBar").length != 0) {
		if($(".grownupBar").hasClass("grownupBar-sesame")) {


				// On first page load, check to see if we're the home "page" or a sub "page".
				// If anything but the home "page," immediately hide the grownupBar.
				var initiallyLoadedLocation = location.hash;
				if(initiallyLoadedLocation == "" || initiallyLoadedLocation == "#/home") {
					// do nothing; we're on the home page
				} else {
					$(".grownupBar").hide();
					if(!$("body").hasClass("restoreDefaults")) {
						$("body").addClass("restoreDefaults");
					}
				}

				
				// Now do regular state-change checks.
				var oldLocation = location.hash;
				setInterval(function() {
					if(location.hash != oldLocation && location.hash != "#/home" && location.hash != "") {
						oldLocation = location.hash; 
						removeGrownupBar();
					} else { 
						if(location.hash != oldLocation && location.hash == "#/home"  ) {
							oldLocation = location.hash;
							showGrownupBar();
						} else {
							if(location.hash != oldLocation && location.hash == ""  ) {
								oldLocation = location.hash; 
								showGrownupBar();
							}
						}
					}
				}, 100);


		}
	}




});
