// Stores the hash
var coolHash = window.location.hash;

// Function that returns code for correct subpage of site
function getDeepLink()
{
	// Create variable to hold the hash
	var hash = window.location.hash,
		sectionId = new Number();		
	// Check if hash exists
	if (hash)
	{
		// Create folder from hash
		var folder = hash.substring(1);

		// check for which folder
		if (folder == '/see-the-wall/')
		{
			return 1;
		}
		else if (folder == '/who-we-are/')
		{
			return 5;	
		}
		else if (folder == '/contact-us/')
		{
			return 6;
		}
		else if (folder == '/site-credits/')
		{
			return 7;	
		}
		else if (folder == '/off-the-wall/')
		{
			return 2;
		}
		else if (folder == '/more-videos/')
		{
			return 8;
		}
		else if (folder == '/contributors/')
		{
			return 9;	
		}
		else if (folder == '/partners/')
		{
			return 10;	
		}
		else
		{
			return 0;	
		}
	}
	else
	{
		return 0;
	}
}

//alert(getDeepLink());

function updateHash(theId)
{
	var hashArray = ['/','/see-the-wall/','/off-the-wall/','','','/who-we-are/','/contact-us/','/site-credits/','/more-videos/','/contributors/','/partners/'];
	window.location.hash = hashArray[theId];
	updateTitle(getDeepLink());
	coolHash = window.location.hash;
}

function watchHash()
{
	//var newHash = window.location.hash;
	if (window.location.hash != coolHash)	
	{
		//alert('hash has changed, should call section: ' + getDeepLink());
		document.getElementById("myAlternativeContent").deepLinkUpdate(getDeepLink());
		
		updateTitle(getDeepLink());
		
		coolHash = window.location.hash;
	}
}

setInterval(watchHash, 100);

// Updates page title depending on ID
function updateTitle(theId)
{
	var titleArray = ['COME JOIN THE WALL','SEE THE WALL','OFF THE WALL','','','WHO WE ARE', 'CONTACT US','CONTRIBUTORS','MORE VIDEOS', 'CONTRIBUTORS', 'PARTNERS'];
	var masterTitle = 'The United Chinese of America | '
	//alert(masterTitle + titleArray[theId]);
	document.title = masterTitle + titleArray[theId];
}

// Popup Manager
function popUp(URL) 
{
	day = new Date();
	
	id = day.getTime();
	
	var winl = (screen.width-935)/2;

	var wint = (screen.height-670)/2;
	
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=935,height=670,left = " + winl +",top = " + wint + "');");
}


var flashvars = {
	
	deepLink: getDeepLink(),
	
	dataUrl: 'jtw-data.xml'

};


var params = {allowScriptAccess: "always", allowFullScreen : true, base:"http://az120505.vo.msecnd.net/flash/"};

var attributes = {};

swfobject.embedSWF("http://az120505.vo.msecnd.net/flash/index.swf", "myAlternativeContent", "100%", "100%", "9.0.0", false, flashvars, params, attributes);
			
swffit.fit("myAlternativeContent", 935, 670);
