//
// scouts.js - Global JavaScript functions for Pack 736 Web pages
//
// Michael Urban
// Pack 736, Wichita, Kansas
//

// 
// Global variables/constants
//
var browser = new Object();			// Create global browser object for determining 
							// navigator platform, version, etc.
var imageBase = "images/";				// Directory containing web page images
var strWinProp;					// global string containing window properties for popup windows.

// Define HTML Node object constants for browsers that are not fully DOM conformant...i.e., IE,
// Netscape 4.x
//
if (!window.Node) {
	var Node = {
		ELEMENT_NODE: 1,
		ATTRIBUTE_NODE: 2,
		TEXT_NODE: 3,
		COMMENT_NODE: 8,
		DOCUMENT_NODE: 9,
		DOCUMENT_FRAGMENT_NODE: 11
	}
}

// Create an image array containing the mouse over images for the left hand side navigation bar.
// Each item in the associative array will contain an array of two values...the "off" image, 
// and the "on" image.  The associative array key should match the name attribute within its 
// associated <a> and/or <img> tag.
//
var imageArray = new Array();
imageArray["about"] = ["pack736_nav_about_off.gif", "pack736_nav_about_on.gif"];
imageArray["news"] = ["pack736_nav_news_off.gif", "pack736_nav_news_on.gif"];
imageArray["fun"] = ["pack736_nav_fun_off.gif", "pack736_nav_fun_on.gif"];
imageArray["leadership"] = ["pack736_nav_leadership_off.gif", "pack736_nav_leadership_on.gif"];
imageArray["resources"] = ["pack736_nav_resources_off.gif", "pack736_nav_resources_on.gif"];
imageArray["camping"] = ["pack736_nav_camping_off.gif", "pack736_nav_camping_on.gif"];
imageArray["calendar"] = ["pack736_nav_calendar_off.gif", "pack736_nav_calendar_on.gif"];

// Define statusArray to hold status message for mouseover events. Have to do this to be
// compatible with old browsers that don't like to read the tag attributes
//
var statusArray = new Array();
statusArray["about"] = "About Pack 736";
statusArray["news"] = "Pack News";
statusArray["fun"] = "Pack Fun Page";
statusArray["leadership"] = "Pack Leadership";
statusArray["resources"] = "Pack Resources";
statusArray["camping"] = "Pack Camping";
statusArray["calendar"] = "Pack Calendar";
//
// End variable/constant declaration

// Begin Functions
//

// getBrowserInfo
// Extract various browser information.  Use the global browser Object (declared above) to 
// hold the values. 
//
function getBrowserInfo() {

	// Determine the major version of the browser
	//
	browser.majorVersion = parseInt(navigator.appVersion);
	browser.minorVersion = parseFloat(navigator.appVersion);

	// Determine browser type
	//
	browser.type = navigator.userAgent;
	var agent = browser.type.toLowerCase();

	browser.isBeonex = false;
	browser.isChimera = false;
	browser.isFirefox = false;
	browser.isMicrosoft = false;
	browser.isMozilla = false;
	browser.isNetPositive = false;
	browser.isNetscape = false;
	browser.isOpera = false;
	browser.isPhoenix = false;
	browser.isSafari = false;
	browser.isSkipStone = false;
	browser.isStarOffice = false;

	if (agent.indexOf("beonix") != -1) browser.isBeonix = true;
	if (agent.indexOf("chimera") != -1) browser.isChimera = true; 
	if (agent.indexOf("firefox") != -1) browser.isFirefox = true;
	if (agent.indexOf("msie") != -1) browser.isMicrosoft = true;
	if (agent.indexOf("mozilla") != -1) browser.isNetscape = true;
	if (agent.indexOf("mozilla/5.0") != -1) browser.isMozilla = true;
	if (agent.indexOf("netpositive") != -1) browser.isNetPositive = true;
	if (agent.indexOf("netscape") != -1) browser.isNetscape = true;
	if (agent.indexOf("opera") != -1) browser.isOpera = true;
	if (agent.indexOf("phoenix") != -1) browser.isPhoenix = true;
	if (agent.indexOf("safari") != -1) browser.isSafari = true;
	if (agent.indexOf("skipstone") != -1) browser.isSkipStone = true;
	if (agent.indexOf("staroffice") != -1) browser.isStarOffice = true;

	// Determine the platform type
	//
	browser.platform = navigator.platform;
}

// imageOver
// Update the navigation bar (left side) images when the mouseover/mouseout events occur.  Each 
// navigation bar element should consist of an <a> tag (pointing to the document to load) and an 
// <img> tag, which contains the default image for the appropriate page.  Each <a> and <img> 
// tag must contain a matching "name" attribute, which corresponds to a key within the 
// imageArray associative array.
//
// objName:	Name of the object invoking the function.  Specified by the name attribute of the 
//           <a> tag (corresponding <img> tag must have the same name).
// flag:	Flag to determine which image to load from imageArray array.  
//		0 = off image (mouseover), 1 = on image (mouseout), -1 = don't update image
//
// To invoke, ensure the following events are present within the <a> tag:
//	onmouseover="imageOver('name', 1); return true;"
//	onmouseout="imageOver('name', 0); return true;"
//
// Notes: 
//	1) Ensure function call is followed by "return true;" in order for the browser status 
//	   bar to be updated (not really necessary in IE, but it won't hurt to be there).
//
function imageOver(objName, flag) {

//	// Extract the name attribute from the passed <a> object.  There should be an image 
//	// with the same name.  Will reference the <img> element in order to modify the "src" 
//	// attribute.
//	var imageName = objName.name;

	// Extract the "title" text from the <img> tag to use as the browser status text, if supported.  
	// If not, use array value
	//
	if (document[objName].title)
		var statusText = document[objName].title;
	else
		var statusText = "-- " + statusArray[objName] + " --";

//	if (browser.isNetscape && (browser.majorVersion <= 4)) {
//		var statusText = statusArray[objName];
//	} else {
//		var statusText = document[objName].title;
//	}

	// Extract the desired image from the imageArray given the passed object name (objName) and the flag
	// value (0 = off, 1 = on, -1 = don't update the image...use default).  Concatentate extracted array
	// element with the imageBase value.
	//
	if (flag > -1) {
		document[objName].src = imageBase + imageArray[objName][flag];
	}

	// Update the status line with text defined above
	//
	if ((flag == 0) || (statusText == undefined))
		window.status = "";
	else {
		window.status = statusText;
	}

	return true; 
}

// initializeImages
// Pre-load the images into the browser cache for faster loading
//
function initializeImages() {
	for (var item in imageArray) {
		(new Image(135, 35)).src = imageArray[item][0];
		(new Image(135, 35)).src = imageArray[item][1];
	}

	// Instantiate the browser info object
	//
	getBrowserInfo();
}

// initPopup
// Initialize the popup window with default parameters.  Make modifications to default values here.  
// Could be a bit more robust, but will suffice for now....
//
// winWidth:		Width of the window in pixels (optional)
// winHeight:	Height of the window in pixels (optional)
// winTop:		Offset of window's top edge from screen, in pixels (optional)
// winLeft: 		Offset of window's left edge from screen, in pixels (optional)
//
function initPopup(winWidth, winHeight, winTop, winLeft) {

	// Internal width and height.  Adjust intWidth for the end of the screen, and intHeight for the icon bar
	//  at the bottom of the window.  Should only need to use these parameters if creating full screen window
	//
	var intWidth = screen.width - 10;
	var intHeight = screen.height - 80;

	// Set width and height to default values, or values specified in function call
	//
	var width = 500;
	if (winWidth) width = winWidth;

	var height = 400;
	if (winHeight) height = winHeight;

	// Set offset values to default, or to value specified in function call
	//
	var topOffset = 0;
	if (winTop) topOffset = winTop;

	var leftOffset = 0;
	if (winLeft) leftOffset = winLeft;

	// Set the properties of the popup window
	// 
	strWinProp = "width=" + width		// Width.  Set to intWidth for entire screen.
			+ ",height=" + height 	// Height. Set to intHeight for entire screen.
			+ ",resizable=yes"		// Resizable attribute
			+ ",scrollbars=yes"		// Displays scrollbars if document is larger than window.
			+ ",menubar=yes"		// Menubar at top of window.
			+ ",toolbar=yes"		// Browser toolbar, Back; Forward, etc...
			+ ",directories=yes"		// "What's New".  Netscape only (??).
			+ ",location=yes"		// URL field.
			+ ",status=yes"		// Status Bar at bottom of window.
			+ ",titlebar=yes"		// Enable/Disable titlebar resize capability.
			+ ",top=" + topOffset	// Offset of window's top edge from screen.
			+ ",left=" + leftOffset	// Offset of window's left edge from screen.
			+ "";  
}

// showPopup
// Display a popup window.  Must call the initPopup() function, passing necessary parameters.
//
// targetURL: 	URL displayed in window
//
function showPopup(targetURL) {

	// Initialize the popup window.  Make any sizing attribute changes here.
	//
	initPopup(500, 400, 30, 30);

	// Create new window containing "targetURL" document.  Name the target window so all subsequent calls will place
	//  their content here.
	//
	window.open(targetURL, "newwin", strWinProp);
}
