/*
 * Use this symbol for é:	&eacute;
 * Use this symbol for ó:	&oacute;
 * Use this symbol for í:	&iacute;
 * Use this symbol for ñ:	&ntilde;
 * Use this symbol for ¡:	&iexcl;
 * Use this symbol for ¿:	&iquest;
 * (see http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references for more symbols)
 */
var schoolInfo_header_1 = "Principal/Directora:";
var schoolInfo_principal = "Sara Marquez";
var schoolInfo_header_2 = "Address/Direcci&oacute;n:";
var schoolInfo_address_line1 = "1516 W Forest Home Ave";
var schoolInfo_address_line2 = "Milwaukee, WI";
var schoolInfo_address_line3 = "53204-3294";
var schoolInfo_header_3 = "Phone/Tel&eacute;fono:";
var schoolInfo_phone = "414-902-6200";
var schoolInfo_header_4 = "Fax:";
var schoolInfo_fax = "414-902-6215";
var schoolInfo_header_5 = "E-mail:";
var schoolInfo_email = "173@milwaukee.k12.wi.us";
var schoolInfo_header_6 = "Hours/Horario:";
var schoolInfo_hours = "7:45 AM - 2:25 PM";

var button_nondiscrimination_text = "Click here to view Nondiscrimination Notice";

var copyrightYear = 2009;

var mpsImage_width = 182;
var mpsImage_height = 65;
var mpsImage_src = "images/GUI/MPS.gif";
var mpsImage_url = "http://www.milwaukee.k12.wi.us";

var flagImage_width = 142;
var flagImage_height = 300;
var flagImage_time = 18;
var flagImage_white_url = "images/GUI/animations/flag_ani_white.gif";
var flagImage_fade_url = "images/GUI/animations/flag_ani_fade.gif";
var	flagImage_color_url = "images/GUI/animations/flag_ani_color.gif";

/**
*	BUTTON DATA
*	1) Address of linked page.
*	2) English text for house button.
*	3) Spanish text for house button.
*/
var houseData = [];
houseData[0] = "I'm not used because the link numbers start at 1, but I take up memory by default.";
houseData[1] = ['index.htm', 'Home', ''];
houseData[2] = ['staff.htm', 'Staff', ''];
houseData[3] = ['parents.htm', 'Parents', ''];
houseData[4] = ['academics.htm', 'Academics', ''];
houseData[5] = ['students.htm', 'Students', ''];
houseData[6] = ['safePlace.htm', 'Safe Place', ''];
houseData[7] = ['calendar.htm', 'Calendar', ''];
houseData[8] = ['resources.htm', 'Resources', ''];
houseData[9] = ['gallery.htm', 'Gallery', ''];














// If you need help with anything below this line, give Phil an email - phil@pupco.net
// ---------------------------------------------------------------------------------















/**
 *	Array to store flag images.
 *	@serialData				Create image in memory.
 *	@serialData				This value is set to the SRC below, but is deferred to load images in the proper order.
 *	@serialData				Store time that animation takes to complete.
 */
var flagImages = [];
	flagImages[0] = new Image(flagImage_width, flagImage_height); // Create flag image in memory.
	flagImages[0].imgPath = flagImage_white_url; // Flag path.
	flagImages[1]  = new Image(flagImage_width, flagImage_height);
	flagImages[1].imgPath = flagImage_fade_url;
	flagImages[1].aniTime = flagImage_time; // Used to determine when fade animation is finished, so the third flag animation can begin.
	flagImages[2] = new Image(flagImage_width, flagImage_height);
	flagImages[2].imgPath = flagImage_color_url;

/**
 * Set-up of flag
 */
var counter = 0; // Starts counter for flag animation.
var counterReset = false; // True if counter has been reset.
var currentFlag = null; // The current flag that is loaded and being displayed. Set to null initially.
flagInit(); // Initialize flags.

/** FUNCTION DEFINITIONS *********************************************************/
/**
*	Writes info HTML.
*	@serialData		HTML_string	schoolInfo
*	@serialData		HTML_string	nondiscrimination
*/
function writeInfo() {
	var i = 0;
	var msg = [];
	// **SCHOOL INFO** //
	msg[i++] = "<div class='info'>";
	msg[i++] = "<div id='schoolInfo'>";
	msg[i++] = "<h1>" + schoolInfo_header_1 + "</h1>";
	msg[i++] = schoolInfo_principal;
	msg[i++] = "<h1>" + schoolInfo_header_2 + "</h1>";
	msg[i++] = schoolInfo_address_line1 + "<br/>";
	msg[i++] = schoolInfo_address_line2 + "<br/>";
	msg[i++] = schoolInfo_address_line3;
	msg[i++] = "<h1>" + schoolInfo_header_3 + "</h1>";
	msg[i++] = schoolInfo_phone;
	msg[i++] = "<h1>" + schoolInfo_header_4 + "</h1>";
	msg[i++] = schoolInfo_fax;
	msg[i++] = "<h1>" + schoolInfo_header_5 + "</h1>";
	msg[i++] = schoolInfo_email;
	msg[i++] = "<h1>" + schoolInfo_header_6 + "</h1>";
	msg[i++] = schoolInfo_hours;
	msg[i++] = "</div>";
	// End of schoolInfo.
	// **NONDISCRIMINATION NOTICE** //
	msg[i++] = "<div id='nondiscrimination'>";
	msg[i++] = "<a href='nondiscrimination.htm'>";
	msg[i++] = button_nondiscrimination_text;
	msg[i++] = "</a></div>";
	// End of nondiscrimination. 
	msg[i++] = "</div>";
	// End of info.
	document.write(msg.join(''));
};

/**
*	Writes footer HTML.
*/
function writeFooter() {
	var i = 0;
	var msg = [];
	msg[i++] = "<div id='footer'>";
	msg[i++] = "<a href='" + mpsImage_url + "'>";
msg[i++] = "<img alt='Go to Milwaukee Public Schools' src='" + mpsImage_src + "' width='" + mpsImage_width + "' height='" + mpsImage_height + "' border='0'/>";	msg[i++] = "</a>";
	for (var j=1; j<=(houseData.length-1); j++){ // Loop through links.
		msg[i++] = "<a href='" + getHouseLink(j) + "'>";
		msg[i++] = getHouseText(j,"english") + " ~ " + getHouseText(j,"spanish") + "</a>";
		if (j != (houseData.length-1)) { // Don't put a separator after the last item.
			msg[i++] = " | ";
		}
	}
	// **COPYRIGHT INFO** //
	msg[i++] = "<div id='copyright'>&copy;" + copyrightYear + " Forest Home Avenue Elementary School</div>";
	msg[i++] = "</div>";// End of footer.
	document.write(msg.join(''));
};

/**
*	Gets link address data from array.
*	@param	houseNum		Which house to get link data from.
*/
function getHouseLink(houseNum){
	return houseData[houseNum][0];
};
/**
*	Gets text data from array.
*	@param	houseNum		Which house to get text data from.
*	@param	language		Determines what kind of text you want. Passed in as a string.
*/
function getHouseText(houseNum, language){
	if (language == "english") {
		return houseData[houseNum][1];
	}
	if (language == "spanish") {
		return houseData[houseNum][2];
	}
};
/**
*	Writes all HTML for navigation DIV.
*	@param	current	Passes current page to another function.
*/
function writeNav(current){
	writeCorners();
	
	var i = 0;
	var msg = [];
	msg[i++] = "<div id='nav'>";
	document.write(msg.join('')); // Write HTML before calling functions.

	writeFlag();
	writeLinks(current);
	writeInfo();

	i = 0; // Reset counter.
	msg = []; // Reset array.
	msg[i++] = "</div>"; // Closes links DIV because something is nested inside it.
	msg[i++] = "</div>"; // End of nav.
	document.write(msg.join(''));
};
/**
*	Writes decoration HTML to container element.
*/
function writeCorners() {
	var i = 0;
	var msg = [];
	msg[i++] = "<img class='corner' id='corner_L' alt='' src='images/GUI/corner_L.gif' height='9' width='9' />";
	msg[i++] = "<img class='corner' id='corner_R' alt='' src='images/GUI/corner_R.gif' height='9' width='9' />";
	document.write(msg.join(''));
};
/**
*	Writes flag HTML.
*/
function writeFlag() {
	var i = 0;
	var msg = [];
	msg[i++] = "<div id='flag'>";
	msg[i++] = "</div>";
	document.write(msg.join(''));
};
/**
*	Writes all links (houses) for navigation.
*	@param	current		The current page that's being viewed. The houe button's electricity will be always on for the current page.
*/
function writeLinks(current){
	var i = 0;
	var msg = [];
	msg[i++] = "<div id='links'>";
	for (var j=1; j<=(houseData.length-1); j++){ // Loop through houses.
		msg[i++] = "<a href='" + getHouseLink(j) + "'>";
		msg[i++] = "<div class='realEstate'>";
		msg[i++] = "<div class='house' style='background: url(images/GUI/tabs/tab" + j + ".gif);' >";
		msg[i++] = "<div class='houseText'>" + getHouseText(j,"english") + "<br />" + getHouseText(j,"spanish") + "</div>";
		msg[i++] = "<div class='lawn'></div>";
		if (current != j) { // If not writing house for the current page, use electricity.
			msg[i++] = "<div class='electricity'>";
		}
		msg[i++] = "<div class='lights'></div>";
		if (current != j) { // If not writing house for the current page, close electricity DIV.
			msg[i++] = "</div>";
		}
		msg[i++] = "</div></div></a>";
	}
	document.write(msg.join(''));
};

/**
*	Initialize flag loading.
*/
function flagInit() {
	counterInterval		= setInterval("count()",100); // Start interval to increment counter.
	loadCheckInterval	= setInterval("loadCheck()",100); // Start interval to check flags' progress.
	preCache(0);
};
/**
*	Increment the global counter variable.
*/
function count() {
	counter++;
};
/**
*	Pre-cache or "Re-cache" flag animations.
*	@param	flagNum		Number of flag to precache.
*	@param	reCache		Boolean. If true, flag with be preCached again.
*/
function preCache(flagNum, reCache) {
	var flag = flagImages[flagNum]; // Store flag image reference in local variable.
	if (!flag.src || reCache) { // If this flag image hasn't been precached or 'reCache' is set to 'true'...
		flag.src = flag.imgPath;  // Precache it with previosly defined image path.
	}
};
/**
*	Load a flag animation once it's finished loading.
*	@param	flagNum		Number of flag to load.
*/
function setupFlag(flagNum) {
	if (currentFlag==null || currentFlag<flagNum) { // If this flag hasn't already been setup...
		preCache(flagNum, true); // Re-cache flag so the animation begins on first frame.
		document.getElementById('flag').style.background = "url(" + flagImages[flagNum].imgPath + ") no-repeat"; // Set CSS background to this image.
		currentFlag = flagNum; // Mark this flag as being setup.
	}
};
/**
*	Check to see what flags are loaded and load them in the right order.
*/
function loadCheck() {
	if (flagImages[0].complete) { // If the first flag is done loading...
		setupFlag(0); // Set it up.
		preCache(2); // Precache third flag.
		if (flagImages[2].complete) { // If the third flag is done loading...
			preCache(1);// Precache second flag.
			if (flagImages[1].complete) {// If the second flag is done loading...
				setupFlag(1); // Set it up.
				if (!counterReset) { // If the counter hasn't been reset...
					counter = 0; // Reset counter.
					counterReset = true; // Mark counter as reset so it doesn't get reset again.
				}
				if (counter >= flagImages[1].aniTime) {
					setupFlag(2); // Set it up.
					clearInterval(loadCheckInterval);
					clearInterval(counterInterval);
				}
			}
		}
	}
};
/**
 * Get the current date
 * @return	Date as a string.

	var i = 0;
	var msg = [];
	msg[i++] = "<div id='flag'>";
	msg[i++] = "</div>";

*/
function writeDate() {
	var today = new Date();
	today = today.toLocaleDateString();
	document.write(today);
};
