	/***
	general.js - GENERAL JAVASCRIPT FUNCTIONS
	v0.1 - 2008-09-18
		- Initial version after trashing my original code :(
		- Now using Adobe Spry framework for the tab nav, in order to make nice with Dreamweaver
		   and Contribute (Spry code is just better anyways)
	***/
	
	/*** UTIL - Flash Helper Functions ***/
	// Clean up input for the text headers so it can handle funky characters
	function cleanForSWF(myString) {
		// Replace HTML
		myString = myString.replace(/<[^<>]+>/g,"");
		// Replace leading and trailing space
		myString = myString.replace(/^\s+/g,"");
		myString = myString.replace(/$\s+/g,"");
		myString = myString.replace(/$\n+/g,"");
		myString = myString.replace(/$\r+/g,"");
		
		myString = myString.replace(/&nbsp;/g, " ");
		myString = myString.replace(/%/g, "%25");
		myString = myString.replace(/\+/g, "%2B");
		myString = myString.replace(/\&/g, "%26");
		myString = myString.replace(/#/g, "%23");
		return myString;
	}
	
	function stripDW(myString) {
		// Replace HTML
		myString = myString.replace(/<[^<>]+>/g,"");
		return myString;
	}
	
	
	/*** UTIL - ezy pzy delicious Cookie functions  ***/
	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 nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function eraseCookie(name) {
		createCookie(name,"",-1);
	}
	
	
	/*** TAB FUNCTIONS ***/
	function tabCleaner(tabTitle) {
		tabTitle = tabTitle.replace(/<!-- [^-]+-->/g, "");
		tabTitle = tabTitle.replace(/ /g, "_");
		return tabTitle.toLowerCase();
	}
	
	/*** ONLOAD FUNCTIONS ***/
	Event.observe(window, 'load', function() {

		// Add ids to each of the tabs, so we can give them images 
		$$("#tab_nav .TabbedPanelsTab").each( function(listItem) {
			// Hide the em text
			listItem.getElementsByTagName('em')[0].style.display = "none";
			listItem.id = "tab_" + tabCleaner(listItem.getElementsByTagName('em')[0].innerHTML);
			//alert(listItem.id);
		});
		
		// Check the location hash, and activate the corresponding tab, if it exists
		if (document.location.hash != "") {
			var myHash = document.location.hash.substring(1,document.location.hash.length);
			myHash = myHash.toLowerCase();
			if ($("tab_" + myHash)) {
				// Check that Spry object exists
				if (spry_tab_nav) {
					// Tell Spry object to show the corresponding tab content
					spry_tab_nav.showPanel($('tab_'+myHash));
				}
			}
		}
		
		/*** GALLERY ARMING ***/
		// Hide all lightbox lists
		$$(".lightboxMe ul").each( function(list) {
			list.style.display = "none";
		});
		var boxCntr = 0;
		// Add in lightbox rel's and give ids to those who don't have 'em
		// Find all classes...
		$$(".lightboxMe").each( function(boxMe) {
			// Check item id...
			if (boxMe.id == "") {
				// Doesn't have one, give it one...
				boxMe.id = "lightbox_" + boxCntr;
				boxCntr++;
			}
			// ...then add the rel to all anchors, using the original spans id as a distinguisher
			$$("#" + boxMe.id + ".lightboxMe a").each( function(anch) {
				anch.rel = "lightbox[" + boxMe.id + "]";
			});
		});
		
		// Finally, initialize the lightbox...
		initLightbox();
		
		/*** VIDEO ARMING ***/
		boxCntr = 0;
		// Add in lightbox rel's and give ids to those who don't have 'em
		// Find all classes...
		$$(".videoboxMe").each( function(boxMe) {
			// Check item id...
			if (boxMe.id == "") {
				// Doesn't have one, give it one...
				boxMe.id = "videobox_" + boxCntr;
				boxCntr++;
			}
			// ...then add the rel to all anchors, using the original spans id as a distinguisher
			$$("#" + boxMe.id + ".videoboxMe a").each( function(anch) {
				anch.rel = "videobox[" + boxMe.id + "]";
			});
		});
		
		// Finally, initialize the flashbox...
		if (typeof(FlashVideoBox) == "function") {
			initFlashVideoBox();
		}
		
		/*** MAIN NAV HIGHLIGHT ***/
		// Look at the directory structure and activate the main nav button that matches
		//alert(document.location.pathname);
		var dirs = ['about_us/','productions/','box_office/','plan_your_visit/','our_venues/','video/','calendar/','cart/','tickets/'];
		dirs.each( function(dir) {
			var loc = document.location.pathname.toLowerCase();
			if (loc.indexOf(dir.toLowerCase())>-1) {
				if (dir == 'calendar/' || dir == 'cart/' || dir == 'tickets/') {
					$("main_nav_productions").addClassName("on");
					//alert("Got it: " + dir);
				} else {
					$("main_nav_" + dir.substring(0,dir.length-1)).addClassName("on");
				}
			} /* else {
					$("main_nav_" + dir.substring(0,dir.length-1)).removeClassName("on");
			} */
		});

	});
