var ttGames = {

	/* Initialise page state */
	init: function() {
		ttGames.flashLogo();
		ttGames.installJumpMenu();
		ttGames.addLinkTargets();
	},

	/* Replace logo with Flash version using SWFObject */
	flashLogo: function() {
		var logo = new SWFObject("/themes/tt/images/logoanim.swf", "mainlogo", "196", "175", "6", "");
		logo.addParam("wmode", "transparent");
		logo.write("logo");
	},

	/* Add jump menu action */
	installJumpMenu: function() {
		if (!document.getElementById) return;
		if (document.getElementById('jumpSelect')) {
			var jumpSelect = document.getElementById('jumpSelect');
			jumpSelect.onchange = function() {
				var selOption = jumpSelect.selectedIndex;
				if (jumpSelect.options[selOption].value) {
					var url = '/' + jumpSelect.options[selOption].value;
					window.location.href = url;
				}
			};
		}
	},
	
	/* Locate external links and set them to open in a new window */
	addLinkTargets: function() {
		if (!document.getElementsByTagName) return;
		var thisHost = window.location.hostname;
		var links = document.getElementsByTagName("a");
		for (var i = 0;i < links.length;i++) {
			if (links[i].href.indexOf(thisHost)==-1 && links[i].href.indexOf("mailto:")==-1 && links[i].href.indexOf("javascript:")==-1) {
				links[i].onclick = function() {
					window.open(this.href);
					return false;
				};
				links[i].title = "This link will open in a new window";
			}
		}
	}
};

window.onload = ttGames.init;