window.onresize = reDo;

var debugString = "";

//Define global variables
var timerID = null;
var timerOn = false;
var timecount = 5000;
// Change this to the time delay that you desire
var what = null;
var newbrowser = true;
var check = false; 
var layerRef = null;
var lRefS = null; //layerRefStart
var lRefE = null; //layerRefEnd

var noPx = null;

var menuLength = 5;
var subMenuLength = 5;

var menuExpanded = new Array(menuLength);

var menus = MultiDimensionalArray(menuLength,subMenuLength);
menus[0][0] = 'MainPage';
menus[0][1] = 'Info';
menus[0][2] = 'TheStory';
menus[0][3] = 'Blog';

menus[1][0] = 'AboutUs';
menus[1][1] = 'WhoAreWe';
menus[1][2] = 'History';
menus[1][3] = 'ContactUs';

menus[2][0] = 'NewThisYear';
menus[2][1] = 'Pirates';

menus[3][0] = 'TheHouse';
menus[3][1] = 'HowThingsWork';
menus[3][2] = 'TheCharacters';
menus[3][3] = 'Gallery';

menus[4][0] = 'ParentsCorner';
menus[4][1] = 'Philosophy';

function Menu(menuName) {
	this.name = menuName;
	this.index = null;
	this.setExpanded = Menu_setExpanded;
	this.isExpanded = Menu_isExpanded;
	this.toggleExpanded = Menu_toggleExpanded;
	this.isMain = Menu_isMain;
	this.getSubs = Menu_getSubs;
	this.getIndex = Menu_getIndex;
	this.getName = Menu_getName;
}

function Menu_isMain() {
	return (this.getIndex() != -1);
}

function Menu_getIndex() {
	if (this.index == null) {
		this.index = findIndex(this.name);
	}
	return this.index;
}

function Menu_getName() {
	return this.name;
}

function Menu_toggleExpanded() {
	var newState = !menuExpanded[this.getIndex()];
	this.setExpanded(newState);
}

function Menu_setExpanded(expanded) {
	menuExpanded[this.getIndex()] = expanded;
	if (this.isMain()) {
		var subs = this.getSubs();
		for (var i=1; i < subs.length; i++) {
			var subName = subs[i];
			if (subName != null) {
				m = new Menu(subName);
				m.setExpanded(expanded);
			}
		}
	} else {
		if (expanded == true) {
			eval(lRefS + this.getName() + lRefE + styleSwitch + '.display="inline"');
//			startTime();
		} else {
			eval(lRefS + this.getName() + lRefE + styleSwitch + '.display="none"');
		}
	}
	return;
}

function Menu_isExpanded() {
	return menuExpanded[this.getIndex];
}

function Menu_getSubs() {
	if (this.isMain()) {
		var subs = new Array(subMenuLength);
		var thisIndex = this.getIndex();
		for (var i=1; i < subMenuLength; i++) {
			var thisMenu = menus[thisIndex][i];
			if ((thisMenu != null) && (thisMenu != "")) {
				subs[i] = thisMenu;
			} else {
				subs.length = i;
				break;
			}
		}
		return subs;
	} else {
		return false;
	}
}




function MultiDimensionalArray(iRows,iCols)
{
var i;
var j;
   var a = new Array(iRows);
   for (i=0; i < iRows; i++)
   {
       a[i] = new Array(iCols);
       for (j=0; j < iCols; j++)
       {
           a[i][j] = "";
       }
   }
   return(a);
} 

// Gets the look and feel for the applet
function getLookAndFeel() {
//	return 'motif.MotifLookAndFeel';
//	return 'metal.MetalLookAndFeel';
	return 'windows.WindowsLookAndFeel';
//	return 'organic.OrganicLookAndFeel';
}

function getBackgroundImage() {
	return 'StudioHazed.jpg';
}


// Horrible code designed to test values by throwing an eval error
function testValue(stringToTest) {
	alert(stringToTest);
}

// Very simple - play the mp3 and let the browser figure it out use the
// replace function so that the browser back doesn't load up on samples
function playSong(song) {
	window.parent.MusicFrame.location.replace(song);
}

// this gets fired when the user resizes the window
function reDo() {
	window.location.reload(); 
} 

// this allows us to find each menu based on the name
function findIndex(menuName) {
	for (i=0; i< menus.length; i++) {
		if (menuName == menus[i][0]) {
			return i;
			break;
		}
	}
	return -1;
}
 

// this initializes all the components and sets our browser up
function init() { 
	noPx = document.childNodes ? 'px' : 0;
	if (document.layers) { 
		layerRef="document.layers"; 
		lRefS = 'document.layers';
		lRefE = '';
		styleSwitch=""; 
		visibleVar="show"; 
		screenSize = window.innerWidth; 
		what ="ns4"; 
	} else if(document.all) { 
		layerRef="document.all"; 
		lRefS = 'document.all["';
		lRefE = '"]';
		styleSwitch=".style"; 
		visibleVar="visible"; 
		screenSize = document.body.clientWidth + 18; 
		what ="ie4"; 
	} else if(document.getElementById) { 
		layerRef="document.getElementById"; 
		lRefS = 'document.getElementById("';
		lRefE = '")';
		styleSwitch=".style"; 
		visibleVar="visible"; 
		what="dom1"; 
	} else { 
		what="none"; 
		newbrowser = false; 
	} 
	for (var i=0; i<menuLength; i++) {
		menuExpanded[i] = false;
	}
	check = true; 
} 

// Toggles the layer visibility on 
function showLayer(layerName) { 
	if(check) { 
		m = new Menu(layerName);
		m.setExpanded(true);
	} 
} 

// Toggles the layer visibility off 
function toggleLayer(layerName) { 
	hideAll();
	if(check) { 
		m = new Menu(layerName);
		m.toggleExpanded();
	} 
} 

// Toggles the layer visibility off 
function hideLayer(layerName) { 
	if(check) { 
		m = new Menu(layerName);
		m.setExpanded(false);
	} 
} 

// Hides all the menus
function hideAll() { 
	for (var i=0; i < menuLength; i++) {
		layerToHide = menus[i][0];
		hideLayer(layerToHide);
	}
	stopTime();
} 

// Kicks off the timer for hiding the menu
function startTime() { 
	if (timerOn == false) { 
		timerID=setTimeout( "hideAll()" , timecount); 
		timerOn = true; 
	} 
}

// Shuts off the timer
function stopTime() { 
	if (timerOn) { 
		clearTimeout(timerID); 
		timerID = null; 
		timerOn = false; 
	} 
} 

// When the page loads, we initialize everything
function onLoad() { 
	init(); 
} 