/********************************************************************
 * Filename: informationBar.js                                      *
 * Language: JavaScript DOM (Document Object Model)                 *
 *                                                                  *
 * Author: Jason Liu                                                *
 *                                                                  *
 * Copyright (c) 2005-2006 Jason Liu. All rights reserved.          *
 * Copyright (c) 2005-2006 The University of Minnesota Department   *
 *                         of Electrical and Computer Engineering.  *
 * Copyright (c) 2005-2006 The University of Minnesota Institute of *
 *                         Technology.                              *
 * Copyright (c) 2005-2006 The Regents of the University of         *
 *                         Minnesota.                               *
 *                                                                  *
 * Legal Disclaimer:                                                *
 *                                                                  *
 *     [Originally taken from                                       *
 *         http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q3.5.html]  *
 *                                                                  *
 *     [In the following, "licensee" refers to the University of    *
 *      Minnesota Electrical and Computer Engineering Department,   *
 *      the University of Minnesota Institute of Technology, and    *
 *      the Regents of the University of Minnesota.]                *
 *                                                                  *
 *     This is UNPUBLISHED PROPRIETARY SOURCE CODE of Jason Liu;    *
 *     the contents of this file may not be disclosed to third      *
 *     parties, copied or duplicated in any form, in whole or in    *
 *     part, without the prior written permission of Jason Liu.     *
 *                                                                  *
 *     Permission is hereby granted solely to the licensee for use  *
 *     of this source code in its unaltered state. This source code *
 *     may not be modified by licensee except under direction of    *
 *     Jason Liu. Neither may this source code be given under any   *
 *     circumstances to non-licensees in any form, including source *
 *     or binary. Modification of this source constitutes breach of *
 *     contract, which voids any potential pending support          *
 *     responsibilities by Jason Liu. Divulging the exact or        *
 *     paraphrased contents of this source code to unlicensed       *
 *     parties either directly or indirectly constitutes violation  *
 *     of federal and international copyright and trade secret      *
 *     laws, and will be duly prosecuted to the fullest extent      *
 *     permitted under law.                                         *
 *                                                                  *
 *     This software is provided by Jason Liu "as is" and any       *
 *     express or implied warranties, including, but not limited    *
 *     to, the implied warranties of merchantability and fitness    *
 *     for a particular purpose are disclaimed. In no event shall   *
 *     the regents or contributors be liable for any direct,        *
 *     indirect, incidental, special, exemplary, or consequential   *
 *     damages (including, but not limited to, procurement of       *
 *     substitute goods or services; loss of use, data, or profits; *
 *     or business interruption) however caused and on any theory   *
 *     of liability, whether in contract, strict liability, or tort *
 *     (including negligence or otherwise) arising in any way out   *
 *     of the use of this software, even if advised of the          *
 *     possibility of such damage.                                  *
 *                                                                  *
 * Description:                                                     *
 *                                                                  *
 ********************************************************************/

/***** Function that creates the array of "one-liners" that will be
       displayed in the JavaScript Information Bar. *****/
function JSInfoBarText_array() {
	this.historicalFootnote_anchor
	     = JSInfoBar_titleArea_link("Historical Footnote",
	                                "/about/history/",
	                                "Click here to learn more " +
	                                "interesting facts about the " +
	                                "department and its history");
	this.didYouKnow_string
	     = JSInfoBar_titleArea_link("Did You Know?", "", "");
	this.footnotes_array = new Array();

	/*** Create an <acronym> element for "B.E.E." To use this node
	     multiple times, use the this.BEE_acronym.cloneNode(Boolean)
	     object method. ***/
	this.BEE_acronym = document.createElement("acronym");
	this.BEE_acronym.setAttribute("title", "Bachelor of Electrical Engineering");
	this.BEE_acronymTextNode = document.createTextNode("B.E.E.");
	this.BEE_acronym.appendChild(this.BEE_acronymTextNode);
	
	/*** Simple "one-liners". ***/
	this.textArea_element = document.createTextNode(
		"The very first electrical engineering course was " +
		"offered at the University of Minnesota in 1888, the " +
		"same year that Heinrich Hertz demonstrated the " +
		"existence of radio waves.");
	this.footnote_subarray = new Array(this.historicalFootnote_anchor);
	this.footnote_subarray.push(this.textArea_element);
	this.footnotes_array.push(this.footnote_subarray);

	this.textArea_element = document.createTextNode(
		"The Electrical Engineering Department was formally " +
		"established at the University of Minnesota in 1891.");
	this.footnote_subarray = new Array(this.historicalFootnote_anchor);
	this.footnote_subarray.push(this.textArea_element);
	this.footnotes_array.push(this.footnote_subarray);

	this.textArea_element = document.createTextNode(
		"In 1898, a course of study in electrical engineering "+
		"at the University of Minnesota had no tuition charge "+
		"to any student over fourteen years of age, but an " +
		"incidental fee of $5.00 per term was charged; the " +
		"\"average\" expenses per student for one school-year "+
		"typically totalled approximately $305.00, which " +
		"included $160.00 for room and board and $30.00 for books.");
	this.footnote_subarray = new Array(this.historicalFootnote_anchor);
	this.footnote_subarray.push(this.textArea_element);
	this.footnotes_array.push(this.footnote_subarray);

	this.textArea_element = document.createTextNode(
		"In 1924, the Electrical Engineering Department was " +
		"moved to a state-of-the-art building which would " +
		"serve as its home for the next 64 years.");
	this.footnote_subarray = new Array(this.historicalFootnote_anchor);
	this.footnote_subarray.push(this.textArea_element);
	this.footnotes_array.push(this.footnote_subarray);

	this.textArea_element = document.createElement("p");
	this.textArea_textNode = document.createTextNode(
		"Seymour Cray, the inventor of the supercomputer, " +
		"graduated from the University of Minnesota " +
		"Electrical Engineering Department with his ");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.textArea_element.appendChild(this.BEE_acronym.cloneNode(true));
	this.textArea_textNode = document.createTextNode(" in 1949.");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.footnote_subarray = new Array(this.historicalFootnote_anchor);
	this.footnote_subarray.push(this.textArea_element);
	this.footnotes_array.push(this.footnote_subarray);

	/*** Create the text area "one-liner" for ADC. ***/
	this.textArea_element = document.createElement("p");
	this.textArea_textNode = document.createTextNode(
		"In 1935 " + String.fromCharCode(8212) +
		" the height of the Great Depression " +
		String.fromCharCode(8212) + " a young graduate of the "+
		"Electrical Engineering Department by the name of " +
		"Ralph Allison (1930) founds ");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.textArea_anchor = document.createElement("a");
	this.textArea_anchor.setAttribute("href",
	                                  "http://www.ADC.com/");
	this.textArea_anchorTextNode = document.createTextNode("ADC");
	this.textArea_anchor.appendChild(this.textArea_anchorTextNode);
	if (!WinMSIE())
		with (this.textArea_anchor.style) {
			color = "#660000";
			backgroundColor = "inherit";
			fontWeight = "bolder";
		}
	this.textArea_element.appendChild(this.textArea_anchor);
	this.textArea_textNode = document.createTextNode(
		" in the basement of his south Minneapolis home, a " +
		"company which today is a world leader in providing " +
		"global network infrastructure and " +
		"telecommunications products and services.");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.footnote_subarray = new Array(this.historicalFootnote_anchor);
	this.footnote_subarray.push(this.textArea_element);
	this.footnotes_array.push(this.footnote_subarray);

	/*** Create the text area "one-liner" for Medtronic. ***/
	this.textArea_element = document.createElement("p");
	this.textArea_textNode = document.createTextNode(
		"In 1949, University of Minnesota Department of " +
		"Electrical Engineering alumnus Earl Bakken (");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.textArea_element.appendChild(this.BEE_acronym.cloneNode(true));
	this.textArea_textNode = document.createTextNode(
		" 1948) co-founds ");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.textArea_anchor = document.createElement("a");
	this.textArea_anchor.setAttribute("href",
	                                  "http://www.medtronic.com/");
	this.textArea_anchorTextNode = document.createTextNode("Medtronic, Inc.");
	this.textArea_anchor.appendChild(this.textArea_anchorTextNode);
	if (!WinMSIE())
		with (this.textArea_anchor.style) {
			color = "#660000";
			backgroundColor = "inherit";
			fontWeight = "bolder";
		}
	this.textArea_element.appendChild(this.textArea_anchor);
	this.textArea_textNode = document.createTextNode(
		" with his brother-in-law Palmer Hermundslie, a " +
		"company which today is a world leader in " +
		"medical technology.");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.footnote_subarray = new Array(this.historicalFootnote_anchor);
	this.footnote_subarray.push(this.textArea_element);
	this.footnotes_array.push(this.footnote_subarray);

	/*** Create the text area "one-liner" for pacemaker. ***/
	this.textArea_element = document.createElement("p");
	this.textArea_textNode = document.createTextNode(
		"In 1957, Electrical Engineering Department graduate " +
		"Earl Bakken (");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.textArea_element.appendChild(this.BEE_acronym.cloneNode(true));
	this.textArea_textNode = document.createTextNode(
		" 1948), co-founder of ");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.textArea_anchor = document.createElement("a");
	this.textArea_anchor.setAttribute("href",
	                                  "http://www.medtronic.com/");
	this.textArea_anchorTextNode = document.createTextNode("Medtronic, Inc.");
	this.textArea_anchor.appendChild(this.textArea_anchorTextNode);
	if (!WinMSIE())
		with (this.textArea_anchor.style) {
			color = "#660000";
			backgroundColor = "inherit";
			fontWeight = "bolder";
		}
	this.textArea_element.appendChild(this.textArea_anchor);
	this.textArea_textNode = document.createTextNode(
		", invents the first battery-powered cardiac pacemaker.");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.footnote_subarray = new Array(this.historicalFootnote_anchor);
	this.footnote_subarray.push(this.textArea_element);
	this.footnotes_array.push(this.footnote_subarray);

	/*** Create the text area "one-liner" for NSF study. ***/
	this.textArea_element = document.createElement("p");
	this.textArea_textNode = document.createTextNode(
		"In a December 2005 online article, the ");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.textArea_anchor = document.createElement("a");
	this.textArea_anchor.setAttribute("href",
	                                  "http://www.NSF.gov/");
	this.textArea_anchorTextNode = document.createTextNode("National Science Foundation");
	this.textArea_anchor.appendChild(this.textArea_anchorTextNode);
	if (!WinMSIE())
		with (this.textArea_anchor.style) {
			color = "#660000";
			backgroundColor = "inherit";
			fontWeight = "bolder";
		}
	this.textArea_element.appendChild(this.textArea_anchor);
	this.textArea_textNode = document.createTextNode(
		" announced that ");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.textArea_anchor = document.createElement("a");
	this.textArea_anchor.setAttribute("href",
	                                  "http://www.NSF.gov/statistics/infbrief/nsf06303/");
	this.textArea_anchorTextNode = document.createTextNode(
		"recent Electrical Engineering and Computer Science " +
		"graduates continue to earn the highest salaries");
	this.textArea_anchor.appendChild(this.textArea_anchorTextNode);
	if (!WinMSIE())
		with (this.textArea_anchor.style) {
			color = "#660000";
			backgroundColor = "inherit";
			fontWeight = "bolder";
		}
	this.textArea_element.appendChild(this.textArea_anchor);
	this.textArea_textNode = document.createTextNode(".");
	this.textArea_element.appendChild(this.textArea_textNode);
	this.footnote_subarray = new Array(this.didYouKnow_string);
	this.footnote_subarray.push(this.textArea_element);
	this.footnotes_array.push(this.footnote_subarray);

	return this.footnotes_array;
}; // End of JSInfoBarText_array() function

/***** The JavaScript Information Bar object definition. *****/
function JSInfoBar() {
	/*** Create the "top-level" 'div' element. ***/
	this.div = document.createElement("div");
	this.div.setAttribute("id", "JavaScript_information_bar");

	/*** Create the inner 'div' elements that will hold the text.
	     We will use CSS styles to make the widths line up with
	     the main navigation menu and content areas. ***/
	this.textArea = document.createElement("div");
	this.textAreaOuterDiv = this.textArea;
	this.textAreaInnerDiv = document.createElement("div");
	this.textAreaOuterDiv.appendChild(this.textAreaInnerDiv);
	this.textAreaOuterDiv.setAttribute("id", "JSInfoBar_textArea");
	this.div.appendChild(this.textAreaOuterDiv);
	this.titleArea = document.createElement("div");
	this.div.appendChild(this.titleArea);

	/*** Populate the inner 'div' elements (i.e., the title area and
	     the main text area) with text. ***/
	this.textElement = getRandomArrayElement(JSInfoBarText_array());
	this.titleArea.appendChild(this.textElement[0]);
	this.textAreaInnerDiv.appendChild(this.textElement[1]);

	/*** Apply CSS styles ***/
	with (this.div.style) {
		padding = "0";
		color = "#660000";
		backgroundColor = "#FFCC33";
		clear = "both";
	}
	with (this.textAreaOuterDiv.style) {
		width = "100%";
		marginLeft = "-17em";
		cssFloat = "right";
	}
	with (this.textAreaInnerDiv.style) {
		padding = "0.5em";
		if (WinMSIE())
			borderLeft = "16em solid #FFCC33";
		else
			borderLeft = "17em solid #FFCC33";
		color = "#660000";
		backgroundColor = "#FFCC33";
		textAlign = "justify";
	}
	with (this.titleArea.style) {
		width = "15.5em";
		padding = "0.5em";
		cssFloat = "left";
		textAlign = "center";
		verticalAlign = "middle";
	}

	/*** Add the JavaScript information bar just above the
	     footer 'div'. ***/
	if (document.getElementById) {
		var footerDiv = document.getElementById("footer");
		footerDiv.parentNode.insertBefore(this.div, footerDiv);
		return true;
	}
	return false;
} // End of JSInfoBar() function

function JSInfoBar_titleArea_link(anchorText, anchorHref,
                                  anchorTitleText) {
	if (anchorHref) {
		var titleArea_anchor = document.createElement("a");
		titleArea_anchor.setAttribute("href", anchorHref);
		if (anchorTitleText)
			titleArea_anchor.setAttribute("title",
			                              anchorTitleText);
		var mouseOverAction = function() {
			titleArea_anchor.style.textDecoration = "underline";
		}
		var mouseOutAction  = function() {
			titleArea_anchor.style.textDecoration = "none";
		}
		var useCapture = false;
		if (titleArea_anchor.addEventListener) {
			titleArea_anchor.addEventListener("mouseover",
			                                  mouseOverAction,
			                                  useCapture);
			titleArea_anchor.addEventListener("mouseout",
			                                  mouseOutAction,
			                                  useCapture);
		} else if (titleArea_anchor.attachEvent) {
			titleArea_anchor.attachEvent("onmouseover",
			                             mouseOverAction);
			titleArea_anchor.attachEvent("onmouseout",
			                             mouseOutAction);
		}
	} else {
		var titleArea_anchor = document.createElement("p");
	}
	with (titleArea_anchor.style) {
		color = "#660000";
		fontWeight = "bolder";
		textDecoration = "none";
	}
	var titleArea_anchorTextNode
	    = document.createTextNode(anchorText);
	titleArea_anchor.appendChild(titleArea_anchorTextNode);
	return titleArea_anchor;
} // End of JSInfoBar_titleArea_link() function

function getRandomArrayElement(choicesArray) {
	return choicesArray[Math.floor(Math.random() *
	                    (choicesArray.length - 0.5))];
} // End of getRandomArrayElement() function

function WinMSIE() {
	if (navigator.platform == "Win32" &&
	    navigator.appName  == "Microsoft Internet Explorer")
		return true;
	return false;
} // End of WinMSIE() function

/***** Add a push() Array class method if it doesn't exist. *****/
if (Array.prototype.push == null) {
	Array.prototype.push = function(newItem) {
		this[this.length] = newItem;
		return this.length;
	};
}

var eventType = "load";
var eventAction = JSInfoBar;
var useCapture = false;
if (window.addEventListener) {
	window.addEventListener(eventType, eventAction, useCapture);
} else if (window.attachEvent) {
	window.attachEvent("on" + eventType, eventAction);
}
