//
// DocumentGallery JavaScript functions
// Version 09.11.19
// Copyright (C) 2009 Steven Bigelow. All Rights Reserved.
//

var xmlObj;

// Default settings for global properties
var documentGallery = {};
documentGallery.browserVersion = 'UNKNOWN';
documentGallery.contactEMail = "support@tkcsb.com";
documentGallery.debug = false;
documentGallery.defaultDocument = "";
documentGallery.displayDiv = "descriptionHTML";
documentGallery.errorPage = "PageNotFound.html";
documentGallery.hideUnselectedMenuOptions = true ;
documentGallery.idSeparator = "";
documentGallery.lastModified = todayDate('YYYY-MM-DD');
documentGallery.menuItemID = 0; // Counter for menu items
documentGallery.menuHandler = "expandMenu";
documentGallery.menuIDs = [];
documentGallery.menuPrefix = "menu";
documentGallery.online = true;
documentGallery.photoAlbumURL = "";
documentGallery.rootDocument = "index.html";
documentGallery.rssEnabled = false;
documentGallery.rssTemplate = "<p>Title: $FEEDRESULT_TITLE<br />Published: $FEEDRESULT_PUBLISHEDDATE<br />Link: $FEEDRESULT_LINK<br />Author: $FEEDRESULT_AUTHOR<br />Content Snippet: $FEEDRESULT_CONTENTSNIPPET<br />Content: $FEEDRESULT_CONTENT<br />Categories: $FEEDRESULT_CATEGORIES</p>";
documentGallery.shortcut = [];
documentGallery.showEmptyDescription = false;
documentGallery.showLastModified = false;
documentGallery.showMouseOver = false;
documentGallery.singleScroll = false;
documentGallery.siteFooter = "<a href='http://documentGallery.tkcsb.com' target='_blank'>documentGallery Software</a>Copyright &copy; 2009 Steven Bigelow.All Rights Reserved.";
documentGallery.siteFooterDiv = "pageFooter";
documentGallery.siteHeader = "";
documentGallery.siteHeaderDiv = "pageHeader";
documentGallery.siteLogo = "";
documentGallery.siteLogoDiv = "pageLogo";
documentGallery.siteSubTitle = "";
documentGallery.siteSubTitleDiv = "pageSubTitle";
documentGallery.siteTitle = "";
documentGallery.siteTitleDiv = "pageTitle";
documentGallery.webSiteName = "documentGallery";
documentGallery.windowTitle = "documentGallery";


try
	{
		//Load Google Ajax Feed API (version 1);
		google.load("feeds", "1");
		documentGallery.rssEnabled = true;
	}
catch(e)
	{
		documentGallery.rssEnabled = false;
		documentGallery.online = false;
	}

function setPage(xmlDocument)
	{
		//
		// This is the main function that calls all the other functions to
		// populate the page with data from the specified XML document
		//

		// Bust out of any confining frames...
		if (parent.frames.length > 0)
			{
				top.location.replace(document.location);
			}

		// Ensure index.html is in the URL
		if (document.URL.indexOf(documentGallery.rootDocument) == -1)
			{
				window.location = window.location.protocol
					+ "//"
					+ window.location.hostname
					+ window.location.pathname
					+ documentGallery.rootDocument
					+ window.location.hash;
			}

		try
			{
				if (xmlDocument === undefined)
					{
						var xmlDocument = "xml/documentGallery.xml";
					}

				XMLObj = loadXMLData(xmlDocument);

				setPageAttributes(XMLObj);

				var resetLocation = window.location.hash;

				// Set up initial display of page
				var panelObj = xmlObj.getElementsByTagName("panel");
				for (var panelLoop=0; panelLoop < panelObj.length; panelLoop++)
					{
						if ((panelObj[panelLoop].attributes.getNamedItem("type")) && (panelObj[panelLoop].attributes.getNamedItem("name")))
							{
								switch (panelObj[panelLoop].attributes.getNamedItem("type").value.toUpperCase())
									{
									case "CONTENT":
										{
											if (panelObj[panelLoop].text)
												{
													var action = panelObj[panelLoop].text;
												}
											else if (panelObj[panelLoop].textContent)
												{
													var action = panelObj[panelLoop].textContent;
												}
											else
												{
													action = "";
												}

											loadRemoteURL(action, "INTERNAL", panelObj[panelLoop].attributes.getNamedItem("name").value);
											break;
										}
									case "MENU":
										{
											setShortcuts(xmlObj); // Are shortcuts always part of a menu?
											setMenu(xmlObj);
											break;
										}
									default:
										{
											break;
										}
								}
							}
					}

				if (resetLocation != "")
					{
						setCurrentPage(resetLocation);
					}

			}
		catch(setPage_Error)
			{
				displayAltPage("", "", setPage_Error);
			}

	}

function loadXMLData(xmlFile)
	{
		try
			{
				if ((window.XMLHttpRequest) && (document.URL.indexOf("file:") < 0))
					{
						xmlDoc = new window.XMLHttpRequest();
						xmlDoc.open("GET",xmlFile,false);
						xmlDoc.send("");
						xmlObj = xmlDoc.responseXML;

					}
				else if (document.implementation && document.implementation.createDocument)
					{
						// Mozilla, Firefox, Opera, etc.
						xmlDoc = document.implementation.createDocument("", "", null);
						xmlDoc.async = false;
						xmlDoc.validateOnParse = true;
						xmlDoc.resolveExternals = true;
						xmlDoc.load(xmlFile);
						xmlObj = xmlDoc;
					}
				else if (window.ActiveXObject)
					{
						// MS IE
						try
							{
								xmlObj = new ActiveXObject("Microsoft.XMLDOM");
								xmlObj.async = false;
								xmlObj.validateOnParse = true;
								xmlObj.resolveExternals = true;
								xmlObj.load(xmlFile);
							}
						catch(e)
							{
								displayAltPage("", xmlFile, "Error loading XML document '" + xmlFile + "': " + e.description);
							}
					}
				else
					{
						// no good browser found
						if (!xmlDoc.load(xmlFile))
						{
							displayAltPage("", xmlFile, "Failed to load XML data source '" + xmlFile + "'!");
						}
					}
			}
		catch(loadXMLData_Error)
			{
				alert("documentGallery FATAL ERROR"
					+ "\n"
					+ "\n" + "Unable to load XML configuration document '" + xmlFile + "'."
					+ "\n"
					+ "\n" + "Error: " + loadXMLData_Error.description
					+ "\n"
					+ "\n" + "Application unable to continue."
					);
				return false;
			}

		return xmlObj;
	}

function setShortcuts(documentObj)
	{
		if (documentObj)
			{

				shortcutObj = documentObj.getElementsByTagName('shortcut');

				if (shortcutObj.length > 0)
					{
						var shortcutString = "";

						for (x=0; x < shortcutObj.length; x++)
							{
								try
									{
										shortcutString = shortcutObj[x].childNodes[0].nodeValue;

										shortcutName = shortcutString.substring(0, shortcutString.indexOf("=")).replace(/\s+/g, "");
										shortcutObjString = shortcutString.substring(shortcutString.indexOf("=")+1);

										documentGallery.shortcut[shortcutName] = eval(shortcutString);

										documentGallery.shortcut[shortcutName].name = shortcutName;
										documentGallery.shortcut[shortcutName].title = documentGallery.shortcut[shortcutName].title.replace(/_/gi," ");
									}
								catch(e)
									{
										debugAlert("Can't set shortcut object: " + e + "\n" + e.description);
									}
							}
					}
			}
	}

function setMenu(documentObj)
	{

		menuObj = documentObj.getElementsByTagName("menu");

		for (x=0; x < menuObj.length; x++)
			{

				// Set menu global configuration
				if (menuObj[x].attributes.getNamedItem("id"))
					{
						documentGallery.menuIDs[documentGallery.menuIDs.length] = menuObj[x].attributes.getNamedItem("id").value.replace(/\s+/g, "");
					}

				if (menuObj[x].attributes.getNamedItem("hideUnselectedMenuOptions"))
					{
						menuHideUnselectedMenuOptions = (menuObj[x].attributes.getNamedItem("hideUnselectedMenuOptions").value.replace(/\s+/g, "").toUpperCase() == "TRUE");
					}

				if (menuObj[x].attributes.getNamedItem("showOnMouseOver"))
					{
						menuShowOnMouseOver = (menuObj[x].attributes.getNamedItem("showOnMouseOver").value.replace(/\s+/g, "").toUpperCase() == "TRUE");
					}

				if (menuObj[x].attributes.getNamedItem("showEmptyDescription"))
					{
						menuShowEmptyDescription = (menuObj[x].attributes.getNamedItem("showEmptyDescription").value.replace(/\s+/g, "").toUpperCase() == "TRUE");
					}

				// Set menu items and collapsible blocks
				if (menuObj[x].hasChildNodes() == true)
					{
						var menuHTML = "";
						documentGallery.menuItemID = 0;

						try
							{
								//document.write(setMenuItems(menuObj[x], menuHTML));
								document.getElementById(documentGallery.menuIDs[documentGallery.menuIDs.length -1]).innerHTML = setMenuItems(menuObj[x], menuHTML);
							}
						catch(e)
							{
								alert(e.description);
							}
					}
			}
	}


function setMenuItems(menuXML, menuHTML)
	{
		var nodeName = "";

		var menuChildCount = menuXML.childNodes.length;

		for (var x=0; x < menuChildCount; x++)
			{
				nodeName = menuXML.childNodes[x].nodeName.toUpperCase();

				switch (nodeName)
					{
						case "MENU_ITEM":
							{
								var menuItemEnabled = true;
								if (menuXML.childNodes[x].attributes.getNamedItem("enabled"))
									{
										menuItemEnabled = (menuXML.childNodes[x].attributes.getNamedItem("enabled").value.replace(/\s+/g, "").toUpperCase() == "TRUE");
									}

								var isDefaultDocument = menuXML.childNodes[x].attributes.getNamedItem("defaultdocument");

								if (menuItemEnabled)
									{
										menuHTML += "<li";

										var menuStyleDisplay = "block";
										menuHTML += " style='display:" + menuStyleDisplay + ";'";

										if (menuXML.childNodes[x].attributes.getNamedItem("id"))
											{
												menuHTML += " id='" + menuXML.childNodes[x].attributes.getNamedItem("id").value.replace(/\s+/g, "") + "'";
											}
										else
											{
												menuHTML += " id='" + documentGallery.menuItemID + "'";
											}

										// Add opening link
										if (hasNode(menuXML.childNodes[x], "content"))
											{

												var contentNode = menuXML.childNodes[x].getElementsByTagName("content")[0];

												if (contentNode.text)
													{
														var action = contentNode.text;
													}
												else if (contentNode.textContent)
													{
														var action = contentNode.textContent;
													}
												else
													{
														action = "";
													}

												try
													{
														var contentType = contentNode.attributes.getNamedItem("type").value.replace(/\s+/g, "").toUpperCase();
													}
												catch(e)
													{
														var contentType = "";
													}

												switch (contentType)
													{
														case "LOCALURL":
															{
//																if (isDefaultDocument)
//																	{
//																		setWindowLocationHash("#url=" + action);
//																	}

																action = "loadRemoteURL('" + action + "', 'INTERNAL')";
																break;
															}
														case "LOCALXML":
															{
//																if (isDefaultDocument)
//																	{
//																		setWindowLocationHash("#xml=" + action);
//																	}

																action = "loadRemoteURL('" + action + "', 'XML')";
																break;
															}
														case "SHORTCUT":
															{
//																if (isDefaultDocument)
//																	{
//																		setWindowLocationHash("#feed=" + action);
//																	}

																action = "loadShortcut('" + action + "')";
																break;
															}
														case "INNERHTML":
															{
																if (isDefaultDocument)
																	{
																		// Needs lotsa work...
																		//setWindowLocationHash("#html=" + action);
																	}

																action = action.replace(/\n|\t/gi,"");
																action = action.replace(/'/gi,"\\'");
																action = action.replace(/"/gi,'\\"');
																action = escape(action);
																action = "loadRemoteURL('" + action + "', 'INNERHTML')"
																break;
															}
														case "REMOTEURL":
															{
//																if (isDefaultDocument)
//																	{
//																		setWindowLocationHash("#frame=" + action);
//																	}

																action = "loadRemoteURL('" + action + "', 'IFRAME')"
																break;
															}
														default:
															{
																break;
															}
													}
											}
										else
											{
												var action = "";
											}


										// Add onclick "expandMenu" attribute
										if ((menuXML.childNodes[x].getElementsByTagName("menu_items").length > 0) || (action != ""))
											{
												menuHTML += " onclick=\""

												if (menuXML.childNodes[x].getElementsByTagName("menu_items").length > 0)
													{
														menuHTML += "expandMenu('"
															+ (documentGallery.menuItemID + 1)
															+ "', event)";
													}

												if ((menuXML.childNodes[x].getElementsByTagName("menu_items").length > 0) && (action != ""))
													{
														menuHTML += " &amp;&amp; "
													}

												if (action != "")
													{
														menuHTML += action
													}

												menuHTML += ";\"";
											}

										// Close out opening part of tag
										menuHTML += ">"

										if (action != "")
											{
												menuHTML += "<a href=\"javascript:"
													+ action
													+ "\" >";
											}

										if (isDefaultDocument)
											{
												debugAlert("Setting site's default document to: " + action);
												documentGallery.defaultDocument = action;
											}

										// Add menu item label & link
										if ((menuXML.childNodes[x].getElementsByTagName("title")) && (menuXML.childNodes[x].getElementsByTagName("title").text != "undefined"))
											{
												if (menuXML.childNodes[x].getElementsByTagName("title")[0].text)
													{
														menuHTML += menuXML.childNodes[x].getElementsByTagName("title")[0].text;
													}
												else if (menuXML.childNodes[x].getElementsByTagName("title")[0].textContent)
													{
														menuHTML += menuXML.childNodes[x].getElementsByTagName("title")[0].textContent;
													}
												else
													{
														menuHTML += "Menu Item " + documentGallery.menuItemID;
													}
											}

										// Close link
										//if ((menuXML.childNodes[x].getElementsByTagName("content")) && (menuXML.childNodes[x].getElementsByTagName("content").text != "undefined"))
										if (hasNode(menuXML.childNodes[x], "content"))
											{
												menuHTML += "</a>";
											}

										documentGallery.menuItemID ++;

										// Drill down to see if there are child options
										menuHTML = setMenuItems(menuXML.childNodes[x], menuHTML);

										// Close out the tag
										menuHTML += "</li>";
									}

								break;

							}
						case "MENU_ITEMS":
							{
								var menuItemEnabled = true;
								if (menuXML.childNodes[x].attributes.getNamedItem("enabled"))
									{
										menuItemEnabled = (menuXML.childNodes[x].attributes.getNamedItem("enabled").value.replace(/\s+/g, "").toUpperCase() == "TRUE");
									}

								if (menuItemEnabled)
									{
										menuHTML += "<ul";

										if(menuHideUnselectedMenuOptions)
											{
												var menuStyleDisplay = "none";
											}
										else
											{
												var menuStyleDisplay = "block";
											}

										try
											{
												if (menuXML.childNodes[x].attributes.getNamedItem("initialdisplay").value.replace(/\s+/g, "").toUpperCase() == "TRUE");
													{
														menuStyleDisplay = "block";
													}
											}
										catch(e)
											{
											}
										finally
											{
												menuHTML += " style='display:" + menuStyleDisplay + ";'";
											}

										//if (documentGallery.menuItemID == 0)
										//	{
										//		menuHTML += " id='" + menuId + "'";
										//	}
										//else
										if (menuXML.childNodes[x].attributes.getNamedItem("id"))
											{
												menuHTML += " id='" + menuXML.childNodes[x].attributes.getNamedItem("id").value.replace(/\s+/g, "") + "'";
											}
										else
											{
												menuHTML += " id='" + documentGallery.menuItemID + "'";
											}

										// Add onclick "expand menu" attribute
										//TODO: Verify no onclick for ULs
										//menuHTML += " onclick=''";

										// Close out opening part of tag
										menuHTML += ">"

										documentGallery.menuItemID ++;

										// Drill down to see if there are child options
										menuHTML = setMenuItems(menuXML.childNodes[x], menuHTML);

										// Close out the tag
										menuHTML += "</ul>";
									}

								break;
							}
					}
			}

		return menuHTML;
	}


function expandMenu(menuSectionID, eventHandle)
	{
		var childElement = document.getElementById(menuSectionID);

		try
			{
				var parentElements = "/" + childElement.id + "/";

				while(childElement.parentNode)
					{
						childElement = childElement.parentNode;
						parentElements += "/" + childElement.id + "/";
					}
			}
		catch(e)
			{
				alert("Couldn't populate parentElements: " + e.description);
				var parentElements = menuSectionID;
			}

			// pop the event bubble...
			if (!eventHandle)
				{
					var eventHandle = window.event;
				}

			if (eventHandle)
				{
					eventHandle.cancelBubble = true;
				}

			if (eventHandle.stopPropagation)
				{
					eventHandle.stopPropagation();
				}

			for( var i = 0; i < documentGallery.menuIDs.length; i++)
				{
					//var menuBlocks = document.getElementById(documentGallery.defaultDocumentID).getElementsByTagName("ul");
					var menuBlocks = document.getElementById(documentGallery.menuIDs[i]).getElementsByTagName("ul");

					for (menuBlock = 0; menuBlock < menuBlocks.length; menuBlock++)
						{

							if (parentElements.indexOf("/" + menuBlocks[menuBlock].id + "/") < 0)
								{
									menuBlocks[menuBlock].style.display="none";
								}
						}
				}

		document.getElementById(menuSectionID).style.display = "block";

		return true;
	}


function setShowEmptyDescription()
	{
		if (xmlObj.getElementsByTagName("showEmptyDescription"))
			{
				documentGallery.showEmptyDescription = xmlObj.getElementsByTagName("showEmptyDescription")[0].text
 			}

		return true;
	}



//
// Set page attributes from config options
//
function setPageAttributes(pageObj)
	{

		var maxLoopCount = 0;

		// Set configuration options from pageConfig 'JSON' section of XML
		setConfigOptions(pageObj);

		try
			{
				if (documentGallery.singleScroll)
					{
						document.body.style.overflow = "hidden";
					}
				else
					{
						document.body.style.overflow = "none";
					}
			}
		catch(e)
			{
				document.body.style.overflow = "auto";
			}

		// set window title
		try
			{
				document.title = documentGallery.windowTitle;
			}
		catch(e)
			{
 				debugAlert("Can't set window title: " + e.description);
			}


		// set browser version
		documentGallery.browserVersion = setBrowserVersion();

//		// Set online mode
//		try
//			{
//				if (documentGallery.online == true)
//					{
//						documentGallery.online = (pageObj.getElementsByTagName("page")[0].attributes.getNamedItem("online").value.replace(/\s+/g, "").toUpperCase() == "TRUE");
//					}
//			}
//		catch(e)
//			{
//			}
	}

function loadRemoteURL(windowURL, windowStyle, displayDiv, xsltFile)
	{

		if (windowStyle == undefined)
			{
				windowStyle="IFRAME";
			}

		if (displayDiv == undefined)
			{
				displayDiv = documentGallery.displayDiv;
			}

		var lastModified = "[Unknown Modification Date]"

		switch (windowStyle.toUpperCase())
			{
				case "INNERHTML":
					{
						if ((documentGallery.singleScroll) && (documentGallery.singleScroll === true))
							{
								var windowSize = getWindowSize("HEIGHT", "", getWindowSize("HEIGHT", "headerPanel"));
								document.getElementById(displayDiv).style.height = windowSize;
								document.getElementById(displayDiv).style.overflow = "auto";
							}

						document.getElementById(displayDiv).innerHTML = unescape(windowURL);
						break;
					}
				case "INTERNAL":
					{

						try
							{
								if ((documentGallery.singleScroll) && (documentGallery.singleScroll === true))
									{
										var windowSize = getWindowSize("HEIGHT", "", getWindowSize("HEIGHT", "headerPanel"));
										document.getElementById(displayDiv).style.height = windowSize;
										document.getElementById(displayDiv).style.overflow = "auto";
									}

								var xmlhttp = createXMLRequest();

								if (xmlhttp!=null)
									{
										xmlhttp.displaydiv = displayDiv;
										xmlhttp.onreadystatechange = function(){loadRemoteURL_InternalStateChange(xmlhttp);};
										if (window.ActiveXObject)
											{
												xmlhttp.open("GET", windowURL, false);
												xmlhttp.send(null);
											}
										else
											{
												xmlhttp.open("GET", windowURL, true);
												xmlhttp.send(null);
											}
									}
							}
						catch(e)
							{
								alert("documentGallery FATAL ERROR"
											+ "\n"
											+ "\n" + "Unable to load internal HTML document '" + windowURL + "'."
											+ "\n"
											+ "\n" + "Error: " + e.description
											+ "\n"
											+ "\n" + "Application unable to continue."
											);

								return false;
							}
						finally
							{
								var fuggit = "Documents/PanelHeader.html|Documents/PanelNews.html|Documents/PanelFooter.html";
								if (fuggit.indexOf(windowURL) === -1)
									{
										setWindowLocationHash("#url=" + windowURL);
									}
							}

						break;
					}

				case "FEED":
					{
						if ((documentGallery.singleScroll) && (documentGallery.singleScroll === true))
							{
								var windowSize = getWindowSize("HEIGHT", "", getWindowSize("HEIGHT", "headerPanel"));
								document.getElementById(displayDiv).style.height = windowSize;
								document.getElementById(displayDiv).style.overflow = "auto";
							}

						windowURL = windowURL.replace(/{/g,'{"').replace(/}/g,'"};').replace(/ : /g,'" : "').replace(/ , /g,'" , "');
						displayRSSFeed(eval('rssFeedObj = ' + windowURL))
						break;
					}
				case "XML":
					{

						if ((documentGallery.singleScroll) && (documentGallery.singleScroll === true))
							{
								var windowSize = getWindowSize("HEIGHT", "", getWindowSize("HEIGHT", "headerPanel"));
								document.getElementById(displayDiv).style.height = windowSize;
								document.getElementById(displayDiv).style.overflow = "auto";
							}

						setFooter("today");

						// Other data types to maybe check for...
						// Undefined "undefined"
						// Null "object"
						// Boolean "boolean"
						// Number "number"
						// String "string"
						// Host object (provided by the JS environment) Implementation-dependent
						// Function object (implements [[Call]] in ECMA-262 terms) "function"
						// E4X XML object "xml"
						// E4X XMLList object "xml"
						// Any other object "object"
						switch (typeof windowURL)
							{
								case "object":
									{
										xml = windowURL;
										break;
									}
								case "xml":
									{
										xml = windowURL;
										break;
									}
								default:
									{
										xml = loadXMLData(windowURL);
										break;
									}
							}

						if (xsltFile != undefined)
							{
								xsl = loadXMLData(xsltFile);
							}
						else
							{
								xsl = loadXMLData(windowURL.replace(/.xml/gi,".xslt"));
							}

						// code for IE
						if (window.ActiveXObject)
							{
								try
									{
										resultDocument = xml.transformNode(xsl);
										document.getElementById(displayDiv).innerHTML = resultDocument;
									}
								catch(e)
									{
										alert(e.description);
									}
							}
						// code for Mozilla, Firefox, Opera, etc.
						else if (document.implementation && document.implementation.createDocument)
							{
								xsltProcessor=new XSLTProcessor();

								xsltProcessor.importStylesheet(xsl);

								resultDocument = xsltProcessor.transformToFragment(xml,document);

								while (document.getElementById(displayDiv).hasChildNodes())
									{
										document.getElementById(displayDiv).removeChild(document.getElementById(displayDiv).lastChild);
									}

								document.getElementById(displayDiv).appendChild(resultDocument);
							}
						break;
					}
				default:
					{
						//
						// IFrame
						//

						var heightOffset = 0;
						var widthOffset = 0;

						if ((documentGallery.singleScroll) && (documentGallery.singleScroll === true))
							{

								if (document.getElementById(displayDiv).currentStyle.marginTop)
									{
										heightOffset = parseInt(document.getElementById(displayDiv).currentStyle.marginTop.replace(/[a-z][A-Z]/gi,""))
											+ parseInt(document.getElementById(displayDiv).currentStyle.marginBottom.replace(/[a-z][A-Z]/gi,""))
											+ parseInt(document.getElementById(displayDiv).currentStyle.paddingTop.replace(/[a-z][A-Z]/gi,""))
											+ parseInt(document.getElementById(displayDiv).currentStyle.paddingBottom.replace(/[a-z][A-Z]/gi,""));

										heightOffset = heightOffset * 2;

										widthOffset = parseInt(document.getElementById(displayDiv).currentStyle.marginLeft.replace(/[a-z][A-Z]/gi,""))
											+ parseInt(document.getElementById(displayDiv).currentStyle.marginRight.replace(/[a-z][A-Z]/gi,""))
											+ parseInt(document.getElementById(displayDiv).currentStyle.paddingLeft.replace(/[a-z][A-Z]/gi,""))
											+ parseInt(document.getElementById(displayDiv).currentStyle.paddingRight.replace(/[a-z][A-Z]/gi,""));

										widthOffset -= 20;
									}
								else
									{
										heightOffset = document.getElementById(displayDiv).style.marginTop + document.getElementById(displayDiv).style.marginBottom;

										widthOffset = document.getElementById(displayDiv).style.paddingTop + document.getElementById(displayDiv).style.paddingBottom;
									}

								var windowHeight = getWindowSize("HEIGHT", "", getWindowSize("HEIGHT", "headerPanel")) - heightOffset;
								var windowWidth = getWindowSize("WIDTH", "", getWindowSize("WIDTH", "main")) - widthOffset;

								document.getElementById(displayDiv).style.overflow = "auto";
							}

						document.getElementById(displayDiv).innerHTML = "<iframe id='remoteIFrame' "
							+ "name='remoteIFrame' "
							+ "frameborder='0' "
							+ "onload='loadRemoteURL_IFrameLoaded(this);' />"

						if (document.getElementById('remoteIFrame'))
							{
								with (document.getElementById('remoteIFrame'))
									{
										align = 'left';
										className = 'contentPanelIFrame';
										display = 'hidden';
										marginHeight = '0';
										marginWidth = '0';
										scrolling = 'auto';
									}

								if( typeof( window.innerWidth ) == 'number' )
									{
										//Non-IE
											document.getElementById('remoteIFrame').width = (window.innerWidth - widthOffset);
											document.getElementById('remoteIFrame').height = (window.innerHeight - heightOffset);
									}
								else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
									{
										//IE 6+ in 'standards compliant mode'
											document.getElementById('remoteIFrame').width = (document.documentElement.clientWidth - widthOffset);
											document.getElementById('remoteIFrame').height = (document.documentElement.clientHeight - heightOffset);
									}
								else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
									{
										//IE 4 compatible
											document.getElementById('remoteIFrame').width = (document.body.clientWidth - widthOffset);
											document.getElementById('remoteIFrame').height = (document.body.clientHeight - heightOffset);
									}
								else
									{
											document.getElementById('remoteIFrame').height = "500px";
									}

								document.getElementById('remoteIFrame').src = windowURL;

								setWindowLocationHash("#frame=" + windowURL);

							}
						else
							{
								return false
							}
					}
			}

	}

function createXMLRequest()
	{
		var xmlRequest = null;

		try
			{
				var xmlRequest = new XMLHttpRequest();
			}
		catch (error)
			{
				try
					{
						var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
						var xmlRequest = function()
							{
								try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {};
								try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {};
								try { return new ActiveXObject("Msxml2.XMLHTTP"); }     catch(e) {};
								try { return new ActiveXObject("Microsoft.XMLHTTP"); }  catch(e) {};
								throw new Error("This browser does not support XMLHttpRequest or XMLHTTP.");
							};

					}
				catch (error)
					{
						alert("Error creating XML Request object: " + error.description);
						xmlRequest = null;
					}
			}
		return xmlRequest;
	}

function loadRemoteURL_InternalLoadHTML()
	{

		if (xmlhttp.readyState==4)
			{

				document.getElementById(xmlhttp.displaydiv).innerHTML = xmlhttp.responseText;

				setFooter(xmlhttp.getResponseHeader("Last-Modified"));

				try
					{
						if (document.getElementById("execOnLoad"))
							{
								var tempFunc = new Function(document.getElementById("execOnLoad").innerHTML);
								tempFunc();
							}
					}
				catch(e)
					{
						try
							{
								var scriptObjs = document.getElementById(xmlhttp.displaydiv).getElementsByTagName("script");

								for (j = 0; j < scriptObjs.length; j++)
									{
										if (scriptObjs[j].id = "execOnLoad")
											{
												var tempFunc = new Function(scriptObjs[j].innerHTML);
												tempFunc();
											}
									}
							}
						catch(e)
							{
							}
					}
			}
	}

function loadRemoteURL_InternalStateChange(http_request)
	{

		if (http_request.readyState == 4)
		  {
			switch (http_request.status)
				{
					case 200:
						// HTTP Status 200 = "OK"
 						{
							document.getElementById(http_request.displaydiv).innerHTML = http_request.responseText;

							//setFooter(http_request.getResponseHeader("Last-Modified"));

							try
								{
									if (document.getElementById("execOnLoad"))
										{
											var tempFunc = new Function(document.getElementById("execOnLoad").innerHTML);
											tempFunc();
										}
								}
							catch(e)
								{
									try
										{
											var scriptObjs = document.getElementById(http_request.displaydiv).getElementsByTagName("script");

											for (j = 0; j < scriptObjs.length; j++)
												{
													if (scriptObjs[j].id = "execOnLoad")
														{
															var tempFunc = new Function(scriptObjs[j].innerHTML);
															tempFunc();
														}
												}
										}
									catch(e)
										{
										}
								}
							break;
					    }
					default:
						{
							// includes 404 errors...
							displayAltPage("", window.location.hash, http_request.statusText)
							break;
						}
				}

				http_request = null;
			}
		else
			{
			}
	}

function loadRemoteURL_IFrameLoaded(frameObj)
	{
		//
		// Check for empty document
		//

		if (document.getElementById("remoteIFrame").src != documentGallery.errorPage)
			{

				try
					{

						if (document.getElementById("remoteIFrame").contentDocument)
							{
								// Most browsers...

								if (document.getElementById("remoteIFrame").contentDocument.title == "The page cannot be found")
									{
										setWindowLocationHash("#url=" + documentGallery.errorPage);
										document.getElementById("remoteIFrame").src = documentGallery.errorPage;
										document.getElementById("remoteIFrame").onload = "";
									}
								else
									{
								setFooter(document.getElementById('remoteIFrame').contentDocument.lastModified);
									}

							}
						else if (document.getElementById('remoteIFrame').contentWindow.window)
							{
								// IE
								try
									{
										setFooter(document.getElementById('remoteIFrame').document.lastModified)
									}
								catch(e)
									{
										setWindowLocationHash("#url=" + documentGallery.errorPage);
										document.getElementById("remoteIFrame").src = documentGallery.errorPage;
										document.getElementById("remoteIFrame").onload = "";
									}
							}
						else
							{
							}
					}
				catch(e)
					{
					}
			}

		return true;
	}


function setFooter(lastModified)
	{
		var siteName = "";

		if (document.domain)
			{
				siteName = document.domain
			}
		else
			{
				siteName = window.location.toString();
				siteName = siteName.substring(0,siteName.indexOf("index."));
				siteNameArray = siteName.split("/");

				for (i=0; i < siteNameArray.length; i++)
					{
						if ((siteNameArray[i] != undefined)
							&& (siteNameArray[i].indexOf("http") < 0)
							&& (siteNameArray[i] != ""))
							{
								siteName += siteNameArray[i] + "/"
							}
					}

				siteName = siteName.substring(0, siteName.lastIndexOf("/"));
			}

		if (documentGallery.showLastModified == true)
			{
				if ((parent.document)
					&& (parent.document.getElementById('lastModified')))
					{
						lastModifiedObj = parent.document.getElementById('lastModified')
					}
				else if ((document.parentWindow)
					&& (document.parentWindow.parent.document.getElementById('lastModified')))
					{
						lastModifiedObj = document.parentWindow.parent.document.getElementById('lastModified')
					}

				var footerString = "";

				if (lastModifiedObj)
					{
						lastModifiedObj.innerHTML = footerString;
					}
			}


		return true;

	}

function scanObject(obj, searchFor, openNewWindow)
	{

		if (searchFor == null)
			{
				searchFor = ""
			}

		if (openNewWindow == null)
			{
				openNewWindow = true;
			}

		if (obj)
			{

				if (obj.nodeName)
					{
						var objName = obj.id;
					}
				else
					{
						var objName = '[Undefined]'
					}

				alert("Scanning: " + objName + " node " + obj.length);

				var objProperties = "<h3>Properties for " + obj.nodeName + "</h3>";

				for (i in obj)
					{
						try
							{
								objProperties += i + ": " + obj[i] + "<br />"
							}
						catch(e)
							{
								alert(e.description)
							}
					}

				if (objProperties.indexOf(searchFor) > -1)
					{
						if (searchFor != "")
							{
								alert("Found pattern: " + searchFor)
							}

						if (openNewWindow == true)
							{
								var newWindow = window.open('', '_blank');
								newWindow.document.write(objProperties);
							}
					}
				else
					{
						alert("Couldn't find pattern: " + searchFor)
					}
			}
		else
			{
				alert("scanObject error: Unknown object")
			}
	}


function setBrowserVersion()
	{
		//
		// Determine which browser we're using
		// Currently supported: IE or Firefox
		//

		var returnValue = 'UNKNOWN';

		if (navigator.userAgent.indexOf("MSIE") >= 0)
			{
				returnValue = "MSIE";
			}
		else if (navigator.userAgent.toUpperCase().indexOf("FIREFOX") >= 0)
			{
				returnValue = "FIREFOX";
			}

		return returnValue;
	}


function todayDate(dateFormat)
	{

		if (dateFormat == undefined)
			{
				dateFormat = "YYYY-MM-DD"
			}

		var currentDate = new Date();
		var fullYear = currentDate.getFullYear();
		var fullMonth = ("0" + (currentDate.getMonth() + 1).toString());
		var fullDate = ("0" + currentDate.getDate().toString());

		if (fullMonth.length > 2)
			{
				fullMonth = fullMonth.substring(1)
			}

		if (fullDate.length > 2)
			{
				fullDate = fullDate.substring(1)
			}

		switch (dateFormat)
			{
				case "YYYY-MM-DD":
					returnString = fullYear + "-" + fullMonth + "-" + fullDate
					break;
				default:
					returnString = fullYear + "-" + fullMonth + "-" + fullDate
					break;
			}

			return returnString;
	}

function displayRSSFeed(rssFeedObj)
	{
		//
		// Generate HTML from an RSS/Atom/XML feed
		// Requires that the GoogleScript jsapi be loaded
		//

		try
			{

				var feedAltPage = documentGallery.errorPage;
				var feedDivID = documentGallery.displayDiv;
				var feedLimit = 1;
				var feedShowContent = true;
				var feedShowLink = false;
				var feedShowNoInfoMessage = true;
				var feedTitle = "";
				var feedURL = rssFeedObj.url;
				var feedTemplate = documentGallery.rssTemplate;
				var feedsetWindowLocation = true;

				if (rssFeedObj.maxItems != undefined)
					{
						feedLimit = rssFeedObj.maxItems;
					}

				if (rssFeedObj.title != undefined)
					{
						feedTitle = rssFeedObj.title.replace(/_/g," ");
					}

				if (rssFeedObj.showNoInfoMessage != undefined)
					{
						feedShowNoInfoMessage = rssFeedObj.showNoInfoMessage;
					}

				if (rssFeedObj.divID != undefined)
					{
						feedDivID = rssFeedObj.divID;
					}

				if (rssFeedObj.showLink != undefined)
					{
						feedShowLink = rssFeedObj.showLink;
					}

				if (rssFeedObj.showContent != undefined)
					{
						feedShowContent = rssFeedObj.showContent;
					}

				if (rssFeedObj.altPage != undefined)
					{
						feedAltPage = rssFeedObj.altPage;
					}

				if (rssFeedObj.rssFeedTemplate != undefined)
					{
						feedTemplate = rssFeedObj.rssFeedTemplate;
					}

				if (rssFeedObj.rssSetWindowLocation != undefined)
					{
						feedsetWindowLocation = rssFeedObj.rssSetWindowLocation;
					}

				if (feedsetWindowLocation == true)
					{
						setWindowLocationHash("#feed=" + rssFeedObj.name);
					}

				if (rssFeedObj.rssResultFormat != undefined)
					{
						// Valid options are: JSON_FORMAT (default), XML_FORMAT, MIXED_FORMAT

						switch (rssFeedObj.rssResultFormat.toUpperCase())
							{
								case "XML_FORMAT":
									{
										feedsetResultFormat = google.feeds.Feed.XML_FORMAT;
										break;
									}
								case "MIXED_FORMAT":
									{
										feedsetResultFormat = google.feeds.Feed.MIXED_FORMAT;
										break;
									}
								default:
									{
										feedsetResultFormat = google.feeds.Feed.JSON_FORMAT;
										break;
									}
							}
					}
				else
					{
						feedsetResultFormat = google.feeds.Feed.JSON_FORMAT;
					}

				var lastModifiedDate = todayDate('YYYY-MM-DD');

				if (documentGallery.online == true)
					{
						var feedpointer = new google.feeds.Feed(feedURL);

						feedpointer.setResultFormat(feedsetResultFormat);

						feedpointer.setNumEntries(feedLimit);

						feedpointer.load(displayRSSFeedCallBack);
					}
				else
					{
						if (feedAltPage !== documentGallery.errorPage)
							{
								displayAltPage(feedAltPage, feedURL, "");
							}
						else
							{
								parent.document.getElementById(documentGallery.displayDiv).innerHTML = "<h1>"
									+ feedTitle
									+ "</h1>"
									+ displayNotConnectedPage();
							}
					}
			}
		catch(e)
			{
alert("Going to displayAltPage");
				displayAltPage(feedAltPage, feedURL, e.description);
			}


		function displayRSSFeedCallBack(result)
			{
				if (!result.error)
					{
						var contentHTML = "";
						var templateContentHTML = "";

						if ((result.feed) && (result.feed.entries))
							{
								// Result object contains JSON formatted data
								var feedResult = result.feed.entries;
							}
						else
							{
								// Result object is only XML_FORMAT data
								// Parse to get named entities

								var feedResultXML = result.xmlDocument;

								var entries = feedResultXML.getElementsByTagName("entry");

								var feedResult = [];

								for (i=0; i < entries.length; i++)
									{
										feedResult[i] = new Object();
										feedResult[i].title = entries[i].getElementsByTagName("title").item(0).firstChild.nodeValue;
										feedResult[i].author = entries[i].getElementsByTagName("name").item(0).firstChild.nodeValue;
										feedResult[i].publishedDate = entries[i].getElementsByTagName("published").item(0).firstChild.nodeValue;

										if (entries[i].getElementsByTagName("gphoto:id")[0])
											{
												feedResult[i].link = entries[i].getElementsByTagName("gphoto:id")[0].firstChild.nodeValue;
											}
										else
											{
												feedResult[i].link = "";
											}

										if (entries[i].getElementsByTagName("summary")[0])
											{
												feedResult[i].content = entries[i].getElementsByTagName("summary").item(0).firstChild.nodeValue;
											}
										else
											{
												feedResult[i].content = "";
											}

										feedResult[i].contentSnippet = "Photo " + (i + 1);

									}
							}

						if (((feedTitle) && (feedResult.length > 0)) || (feedShowNoInfoMessage))
							{
								contentHTML = "<h1>" + feedTitle + "</h1>";
							}

						if ((feedResult.length == 0) && (feedShowNoInfoMessage))
							{
								contentHTML += "<blockquote>No additional information available.</blockquote>"
							}
						else if ((feedResult.length > 1) || (feedLimit > 1))
							{

								for (var i=0; i < feedResult.length; i++)
									{
										templateContentHTML = "";

										if (feedTitle == feedResult[i].title)
											{
												feedResult[i].title = "";
											}

												templateContentHTML = feedTemplate;

												templateContentHTML = templateContentHTML.replace("$FEEDCONFIG_TITLE", feedTitle);
												templateContentHTML = templateContentHTML.replace("$FEEDCONFIG_URL", feedURL);
												templateContentHTML = templateContentHTML.replace("$FEEDCONFIG_INDEX", (i+1));

												templateContentHTML = templateContentHTML.replace("$FEEDRESULT_TITLE", feedResult[i].title);
												templateContentHTML = templateContentHTML.replace("$FEEDRESULT_LINK", feedResult[i].link);
												templateContentHTML = templateContentHTML.replace("$FEEDRESULT_AUTHOR", feedResult[i].author);
												templateContentHTML = templateContentHTML.replace("$FEEDRESULT_PUBLISHEDDATE", feedResult[i].publishedDate);
												templateContentHTML = templateContentHTML.replace("$FEEDRESULT_CONTENTSNIPPET", feedResult[i].contentSnippet);

												var contentSegments = feedResult[i].content.split("<");
												var originalURL = "";
												var modifiedURL = "";

												for (x=0; x < contentSegments.length; x++)
													{
														if ((contentSegments[x].indexOf(">") > -1)
																&& (contentSegments[x].indexOf("href") > -1)
																&& (contentSegments[x].indexOf("\"http:") > -1))
															{
																originalURL = contentSegments[x].substring(0, contentSegments[x].indexOf(">"));
																modifiedURL = originalURL.replace(/a href=/gi,"");
																modifiedURL = "a href='javascript:{}' onclick='loadRemoteURL(" + modifiedURL  + ", \"IFRAME\")'";

																contentSegments[x] = contentSegments[x].replace(originalURL, modifiedURL);

															}
													}

													feedResult[i].content = contentSegments[0];

													for (x=1; x < contentSegments.length; x++)
														{
															feedResult[i].content += "<" + contentSegments[x];
														}


												templateContentHTML = templateContentHTML.replace("$FEEDRESULT_CONTENT", feedResult[i].content);
												templateContentHTML = templateContentHTML.replace("$FEEDRESULT_CATEGORIES", feedResult[i].categories);


												contentHTML += templateContentHTML;

												lastModifiedDate = feedResult[0].publishedDate;
										}
							}
						else
							{

								lastModifiedDate = feedResult[0].publishedDate;

								contentHTML += feedResult[0].content
							}

						setFooter(lastModifiedDate);

						try
							{
								parent.document.getElementById(feedDivID).innerHTML = contentHTML;
							}
						catch(e)
							{
								alert(e.description);
							}

					}
				else
					{
						displayAltPage(feedAltPage, feedURL, result.error.code + ": '" + result.error.message + "'")
					}
			}
	}

function itemModeEnabled(obj)
	{
		var execOnlineOnly = false;
		var execOfflineOnly = false;
		var showMenuItem = true;

		try
			{

					if (obj.getElementsByTagName("execOnlineOnly").length > 0)
						{
							execOnlineOnly = (obj.getElementsByTagName("execOnlineOnly").item(0).firstChild.nodeValue.replace(/\s+/g, "").toUpperCase() == "TRUE");
						}

					if (obj.getElementsByTagName("execOfflineOnly").length > 0)
						{
							execOfflineOnly = (obj.getElementsByTagName("execOfflineOnly").item(0).firstChild.nodeValue.replace(/\s+/g, "").toUpperCase() == "TRUE");
						}

					showMenuItem = ((execOnlineOnly == false) && (execOfflineOnly == false));

					if (execOnlineOnly)
						{
							showMenuItem = (documentGallery.online && execOnlineOnly);
						}

					if (execOfflineOnly)
						{
							showMenuItem = ((!documentGallery.online) && execOfflineOnly);
						}

			}
		catch(e)
			{
			}
		return showMenuItem;
	}

function displayAltPage(pageURL, pageToLoad, msgText)
	{
		switch (pageURL)
			{
				case "OFFLINE":
					{
						loadRemoteURL(displayNotConnectedPage(msgText), "INNERHTML");
						break;
					}
				case "":
					{
						loadRemoteURL(documentGallery.errorPage, "INTERNAL");
						break;
					}
				default:
					{
						if (msgText != "")
							{
								alert("documentGallery Error: "
									+"\n\nUnable to load page " + pageToLoad
									+"\n\nError " + msgText);
							}
						loadRemoteURL(pageURL, "INTERNAL");
						break;
					}
			}
	}

function setWindowLocationHash(hashString)
	{
			window.location.searchstring = "";
			window.location.hash = hashString.replace("#locator","#").replace("?","");
	}

function displayNotConnectedPage(pageDescription)
	{

		var pageMarkup = ""

		if ((pageDescription != "") && (pageDescription != undefined))
			{
				pageMarkup += "<p>" + pageDescription + "</p>";
			}

		pageMarkup += "<p>"
					+ "To display current information, this page requires a connection to the Internet."
					+ "</p>"
					+ "<p>"
					+ "The page is currently unavailable; this may be due to one of the following reasons:"
					+ "<ul>"
					+ "<li>"
					+ "You aren't currently connected to the Internet"
					+ "</li>"
					+ "<li>"
					+ "The web site hosting this page is temporarily unavailable"
					+ "</li>"
					+ "<li>"
					+ "There's an error in the " + documentGallery.webSiteName + " web site"
					+ "</li>"
					+ "</ul>"
					+ "</p>"
					+ "<p>"
					+ "If you are connected to the Internet, please try this page at a later time."
					+ "</p>"
					+ "<p>"
					+ "If you are not connected to the Internet but would like to view this page, "
					+ "please connect to the Internet and then try to view this page again."
					+ "</p>"
					+ "<p>"
					+ "If this problem persists, please let us know at "
					+ "<a href='mailto:" + documentGallery.contactEMail + "'>"
					+ documentGallery.contactEMail
					+ "</a>"
					+ "</p>"
		return pageMarkup

	}


function dynamicFeedObject(sourceURL, startIndex, pageTitle)
	{
		documentGallery.shortcut["DynamicFeed"].url = sourceURL + "?start-index=" + startIndex + "&max-results=1";
		documentGallery.shortcut["DynamicFeed"].title = pageTitle;

		return (documentGallery.shortcut["DynamicFeed"])
	}


function displayBlogCalendarPage(pageName, displayDivName)
	{
		if ((displayDivName == "") || (displayDivName == undefined))
			{
				displayDivName = documentGallery.displayDiv;
			}

		var contentHTML = "";

		if (documentGallery.shortcut[pageName].title != "")
			{
				contentHTML = "<h1>" + documentGallery.shortcut[pageName].title + "</h1>"
			}

		if (documentGallery.online == true)
			{
				if (documentGallery.shortcut[pageName].blogShortcut != "")
					{
						contentHTML += "<p><div id='blogFeedContent'></div></p>";
						displayRSSFeed(documentGallery.shortcut[documentGallery.shortcut[pageName].blogShortcut]);
					}

				if (documentGallery.shortcut[pageName].calendarShortcut != "")
					{
						contentHTML += "<p><div id='calendarFeedContent'></div></p>";
						displayRSSFeed(documentGallery.shortcut[documentGallery.shortcut[pageName].calendarShortcut]);
					}

				document.getElementById(displayDivName).innerHTML = contentHTML;
			}
		else
			{
				contentHTML += displayNotConnectedPage("<p>The '" + pageTitle + "' page lists current announcements and scheduled activities for Troop 548.</p>")


				var feedAltPage = documentGallery.errorPage;
				if (documentGallery.shortcut[pageName].altPage != undefined)
					{
						feedAltPage = rssFeedObj.altPage
					}

				if (feedAltPage !== documentGallery.errorPage)
					{
						displayAltPage(feedAltPage, feedURL, "");
					}
				else
					{
						document.getElementById(displayDiv).innerHTML = "<h1>" + feedTitle + "</h1>" + displayNotConnectedPage();
					}

			}

		setWindowLocationHash("#multifeed=" + documentGallery.shortcut[pageName].name);

	}


function loadJSCSSFile(filename, filetype, functionToExecute)
	{
		if (filetype.toUpperCase() =="JS")
			{
				// filename is a external JavaScript file
				var fileref = document.createElement('script')
				fileref.setAttribute("type","text/javascript")
				fileref.setAttribute("src", filename)
			}
		else if (filetype.toUpperCase() =="CSS")
			{
				// filename is an external CSS file
				var fileref = document.createElement("link")
				fileref.setAttribute("rel", "stylesheet")
				fileref.setAttribute("type", "text/css")
				fileref.setAttribute("href", filename)
			}

		if (typeof fileref != "undefined")
			{
				document.getElementsByTagName("head")[0].appendChild(fileref)
			}

	}


function leftPad(number, digits)
	{
		if (digits == undefined)
			{
				digits = 2;
			}

		if (number < 10)
			{
				return "0" + number;
			}
		else
			{
				return number;
			}
	}


function setCurrentPage(locationString)
	{

		if ((locationString == undefined) || (locationString == ""))
			{
				var showLocation = window.location.hash.toString().split("=");
			}
		else
			{
				var showLocation = locationString.split("=");
			}

		switch (showLocation[0].toUpperCase())
			{
				case "":
					{
						// default page
						break;
					}
				case "#FRAME":
					{
						// load remote URL
						loadRemoteURL(showLocation[1], "IFRAME");
						break;
					}
				case "#URL":
					{
						// load local URL
						loadRemoteURL(showLocation[1], "INTERNAL");
						break;
					}
				case "#XML":
					{
						// load local URL
						loadRemoteURL(showLocation[1], "XML");
						break;
					}
				case "#FEED":
					{
						// load RSS feed
						displayRSSFeed(documentGallery.shortcut[showLocation[1]]);
						break;
					}
				case "#MULTIFEED":
					{
						// load blog/calendar page
						displayBlogCalendarPage(showLocation[1]);
						break;
					}
				default:
					{
						displayAltPage("", window.location.hash, "Unable to parse URL locator: " + window.location.hash);
						break;
					}
			}
	}

function loadShortcut(shortcutName, displayDivName)
	{

		if ((displayDivName == "") || (displayDivName == undefined))
			{
				displayDivName = documentGallery.displayDiv;
			}

		switch (documentGallery.shortcut[shortcutName]["action"].toUpperCase())
			{
				case "DISPLAYRSSFEED":
					{
						displayRSSFeed(documentGallery.shortcut[shortcutName]);
						break;
					}
				case "DISPLAYBLOGCALENDARPAGE":
					{
						displayBlogCalendarPage(shortcutName, displayDivName);
						break;
					}
				default:
					{
						alert("Unknown shortcut action: '" + documentGallery.shortcut[shortcutName]["action"] + "'");
						break;
					}
			}
	}

function setConfigOptions(configObj)
	{
		if (configObj)
			{
				newObj = configObj.getElementsByTagName('pageConfig');

				if (newObj.length > 0)
					{
						var configSettingsString = newObj[0].childNodes[0].nodeValue.replace(/\s+/g, "");

						var configSettingsString = newObj[0].childNodes[0].nodeValue.replace(/^\s*|\s*$/g, "");

						var xmlSettings = eval(configSettingsString);

						for (attrName in documentGallery)
							{
								if (xmlSettings[attrName])
									{
										documentGallery[attrName] = xmlSettings[attrName];
									}
							}

						for (attrName in xmlSettings)
							{
								if (documentGallery[attrName] == undefined)
									{
										documentGallery[attrName] = xmlSettings[attrName];
									}
							}
					}
			}
	}

function getWindowSize(dimension, divID, offset)
	{
		var myWidth = 0;
		var myHeight = 0;
		var myWindowSize = 0;
		var myAspectRatio = .75;

		if (offset === undefined)
			{
				var offset = 0;
			}

		if( typeof( window.innerWidth ) == 'number' )
			{
				//Non-IE
				myWidth = window.innerWidth;
				myHeight = window.innerHeight;
			}
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
			{
				//IE 6+ in 'standards compliant mode'
				myWidth = document.documentElement.clientWidth;
				myHeight = document.documentElement.clientHeight;
			}
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
			{
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}

			myAspectRatio = (myHeight / myWidth);

		if ((divID != undefined) || (divID != ""))
			{
				myWidth = document.getElementById(divID).offsetWidth;
				myHeight = Math.max(document.getElementById(divID).offsetHeight, document.documentElement.clientHeight);
			}

		myHeight = Math.min(myHeight, (myWidth * myAspectRatio));

		switch (dimension.toUpperCase())
			{
				case "WIDTH":
					{
						return (myWidth - offset);
					}
				case "HEIGHT":
					{
						return (myHeight - offset);
					}
			}
	}

function playVideo(videoURL, displayID, displayRatio )
	{
		if ((displayID == undefined) || (displayID == ""))
			{
				var displayID = "videoPlayer";
			}

		if ((displayRatio == undefined) || (displayRatio == ""))
			{
				displayRatio = .75;
			}

		try
			{
				var displayWidth = getWindowSize("WIDTH", displayID, 10);
			}
		catch(e)
			{
				var displayWidth = "852";
			}

		try
			{
				var displayHeight = getWindowSize("HEIGHT");
			}
		catch(e)
			{
				var displayHeight = "639";
			}

		displayHeight = Math.ceil(Math.min(displayHeight, (displayWidth * displayRatio)));

		document.getElementById(displayID).innerHTML = "<table height='"
			+ displayHeight
			+ "' width='"
			+ displayWidth
			+ "' valign='center' align='center'><tr><td valign='center' align='center'><br><h2>Loading...</h2></td></tr></table>";

		var fileExt = videoURL.substr(videoURL.lastIndexOf("."), videoURL.length).toUpperCase();

		if (videoURL.indexOf("http:") < 0)
			{
				switch (fileExt)
					{
						case ".FLV": case "SFW": case "MP3":
							{
								// JW FLV Player needs a full URL... go figure...
								videoURL = window.location.toString().substr(0,window.location.toString().indexOf("index.html")) + "media/"+ videoURL;
								break;
							}
						default:
							{
								// An absolute URL was not specified -- assume the video is in the media folder.
								videoURL = "./media/" + videoURL;
							}
					}
			}

		switch (fileExt)
			{
				case ".FLV": case ".SWF":
					{
						// Try to play the media as a Flash video
						var videoPlayer = new SWFObject('scripts/player.swf','ply',displayWidth,displayHeight,'9','#ffffff');
						videoPlayer.addParam('allowfullscreen','true');
						videoPlayer.addParam('allowscriptaccess','always');
						videoPlayer.addParam('flashvars','file=' + videoURL + '&autostart=true');
						//videoPlayer.addParam('scale', 'showall');
						videoPlayer.addParam('wmode','opaque');
						videoPlayer.addVariable('overstretch','fit');
						videoPlayer.write(displayID);
						break;

					}
				case ".MP3":
					{
						// Try to play the media as an MP3 audio file
						var videoPlayer = new SWFObject('scripts/player.swf','ply',displayWidth,'200','9','#FFFFFF');
						videoPlayer.addParam('allowfullscreen','true');
						videoPlayer.addParam('allowscriptaccess','always');
						videoPlayer.addParam('wmode','opaque');
						videoPlayer.addParam('flashvars','file=' + videoURL + '&autostart=true');
						videoPlayer.write(displayID);
						break;
					}
				case ".WMV": case ".MPG": case ".AVI":
					{
						document.getElementById(displayID).innerHTML = "<embed type='application/x-mplayer2'"
							+ "animationatstart='false' "
							+ "autosize='true' "
							+ "autostart='true' "
							+ "enablecontextmenu='true' "
							+ "enablefullscreencontrols='true' "
							+ "loop='false' "
							+ "name='mediaplayer1' "
							+ "pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' "
							+ "showcontrols='true' "
							+ "showdisplay='false' "
							+ "showstatusbar='true' "
							+ "src='" + videoURL + "'"
							+ "transparentstart='true' "
							+  "/>"
						break;
					}
				case ".MOV": case ".MP4":
					{
						document.getElementById(displayID).innerHTML = "<OBJECT classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' "
							+ "width='" + displayWidth + "' "
							+ "height='" + displayHeight + "' "
							+ "controller = 'true' "
							+ "codebase='http://www.apple.com/qtactivex/qtplugin.cab'>"
							+ "<param name='autoplay' value='true'>"
							+ "<param name='bgcolor' value='000000'>"
							+ "<param name='controller' value='true'>"
							+ "<param name='loop' value='false'>"
							+ "<param name='pluginspace' value='http://www.apple.com/quicktime/download/'> "
							+ "<param name='scale' value='tofit'>"
							+ "<param name='showlogo' value='false'>"
							+ "<param name='src' value='" + videoURL + "'>"
							+ "<param name='type' value='video/quicktime' height='" + displayHeight + "' width='" + displayWidth + "'> "
							+ "</OBJECT> "
						break;
					}
				default:
					{
						alert("Unrecognized media type: " + videoURL);

						document.getElementById(displayID).innerHTML = "";

						break;
					}
			}
	}


function displaySlideShow(slideShowDiv, albumID)
	{
		var options = {
			displayTime: 4000,
			transistionTime: 600,
			linkTarget : google.feeds.LINK_TARGET_BLANK,
			scaleImages: true,
			thumbnailSize : GFslideShow.THUMBNAILS_LARGE
			};

		if (slideShowDiv == undefined)
			{
				var slideShowDiv = "slideShow"
			}

		if (albumID == undefined)
			{
				// Re-write to dynamically retrieve album IDs

				albumIDArray = [];

				albumIDArray[0] = "5391910091009499137";

				var albumID = albumIDArray[Math.floor(Math.random() * albumIDArray.length)];
			}

		try
			{
				var albumURL = documentGallery.photoAlbumURL
					+ "/albumid/"
					+ albumID
					+ "?alt=rss&kind=photo&hl=en_US";

				new GFslideShow(albumURL, slideShowDiv, options);
			}
		catch(e)
			{
				alert("Unable to open slideshow: " + e.description);
			}
	}

function loadSlideShowCallBack()
	{
		displaySlideShow();
	}

function loadSlideShow()
	{
		try
			{
				google.load("feeds", "1");
				google.setOnLoadCallback(loadSlideShowCallBack);
				return true;
			}
		catch(e)
			{
				alert("Unable to open slideshow.");
				return false;
			}
	}

function displayPhotoAlbum(albumID, slideShowDiv)
	{
		if (slideShowDiv == undefined)
			{
				var slideShowDiv = "slideShow"
			}

		if (albumOwner == undefined)
			{
				var albumOwner = "FriendsLongmontSeniorCenter";
			}



		if (albumID != undefined)
			{

				var newGallery = "<embed "
					+ "type='application/x-shockwave-flash' "
					+ "src='http://picasaweb.google.com/s/c/bin/slideshow.swf' "
					+ "width='600' "
					+ "height='350' "
					+ "flashvars='host=picasaweb.google.com&hl=en_US&feat=flashalbum&RGB=0xFFFFFF&feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F"
						+ albumOwner
						+ "%2Falbumid%2F"
						+ albumID
						+ "%3Falt%3Drss%26kind%3Dphoto%26hl%3Den_US' "
					+ "pluginspage='http://www.macromedia.com/go/getflashplayer'> "
					+ "</embed>";

				document.getElementById(slideShowDiv).innerHTML = "Loading a new gallery...";

				document.getElementById(slideShowDiv).innerHTML = newGallery;

			}
	}

function newXMLDocument(rootTagName, namespaceURL)
	{
		if (!rootTagName)
			{
				rootTagName = "";
			}

		if (!namespaceURL)
			{
				namespaceURL = "";
			}

		if (document.implementation && document.implementation.createDocument)
			{
				// This is the W3C standard way to do it
				return document.implementation.createDocument(namespaceURL, rootTagName, null);
			}
		else
			{
			// This is the IE way to do it

			// Create an empty document as an ActiveX object
			// If there is no root element, this is all we have to do
			var doc = new ActiveXObject("MSXML2.DOMDocument");

			// If there is a root tag, initialize the document
			if (rootTagName)
				{
					// Look for a namespace prefix
					var prefix = "";
					var tagname = rootTagName;
					var p = rootTagName.indexOf(':');
					if (p != -1)
						{
							prefix = rootTagName.substring(0, p);
							tagname = rootTagName.substring(p+1);
						}

					// If we have a namespace, we must have a namespace prefix
					// If we don't have a namespace, we discard any prefix
					if (namespaceURL)
						{
							if (!prefix)
								{
									// What Firefox uses
									prefix = "a0";
								}
						}
					else
						{
							prefix = "";
						}

					// Create the root element (with optional namespace)
					// as a string of text
					var text = "<" + (prefix?(prefix+":"):"") +  tagname + (namespaceURL ?(" xmlns:" + prefix + '="' + namespaceURL +'"') :"") + "/>";

					// And parse that text into the empty document
					doc.loadXML(text);
				}
				return doc;
			}
	};

function isSibling(searchNode, siblingNode)
	{
		for(var i = 0; i<searchNode.parentNode.childNodes.length; i++)
			{
				if(searchNode.parentNode.childNodes[i] == siblingNode)
					{
						return true;
					}
			}
		return false;
	}

function hasNode(searchNode, nodeName)
	{

		for (var i=0; i < searchNode.childNodes.length; i++)
			{
				if(searchNode.childNodes[i].nodeName == nodeName)
					{
						return true;
					}
			}
		return false;
	}

function debugAlert(message)
	{
		if (documentGallery.debug == true)
			{
				alert(message);
			}
		return true;
	}
