// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function setupExpandingGameModules() {
	headers = $$('.expander');
	for (var i=0; i < headers.length; i++) {
		Event.observe(headers[i], 'click', function() { new Effect.toggle(Element.next(this), 'blind', {duration: 0.6}) });
		headers[i].firstDescendant().onclick = function() { return false; }
	};
}

function setPageTitle(title) {
	$('title-holder').innerHTML = title;
}

function setLiveTab(tab) {
	
	var source = $(tab).src;
	
	//check that the user didn't re-click the section they're in
	liveMatch = source.match("-on.gif");
	if (!liveMatch || $(tab).className == "rollover") {
		
		//unset the rollover
		$(tab).className = '';
		$(tab).onmouseover = function() {	null }
		$(tab).onmouseout = function() { null }
		
		match = source.match("-on.gif");
		if (!match) {
			$(tab).src = source.replace(".gif", "-on.gif");
		}
		
		//clear the old live tab
		clearTabs($(tab).src);
	}
}

function clearTabs(tabSrc) {
	
	images = $$("#tabs img");
	for (i = 0; i < images.length; i++) {
		match = images[i].src.match("-on")
		if (match) {
			if (images[i].src != tabSrc) { //don't clear the tab we just clicked on
				images[i].src = images[i].src.replace("-on", "");
				images[i].className = "rollover";
			}
		}
	}
	domRollover(); //make sure rollovers work properly
}


function showSubmenu(submenu) {
	var delay = 0;
	var submenus = $$("#menu li ul");
	
	for(i = 0; i < submenus.length; i++) {
		if (submenus[i].style.display != "none") {
			new Effect.toggle(submenus[i].id, 'blind', {duration: 0.2});
			delay = 0.4;
		}
	}
	
	new Effect.toggle(submenu, 'blind', {duration: 0.3, delay: delay});
}

function init() {
	setupExpandingGameModules();
}

Event.observe(window, 'load', init);