﻿// Miscellaneous scripts

function PreloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function SwapImgRestore() {//v1.0
 var doc=document,i; if(doc.$imgSwaps) { for(i=0;i<doc.$imgSwaps.length;i++) {
  var elm=doc.$imgSwaps[i]; if(elm) { elm.src=elm.$src; elm.$src=null; } } 
  doc.$imgSwaps=null; }
}

function SwapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=GetObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function GetObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=GetObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=GetObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function ChangeProp() {//v1.0
 var args=arguments,d=document,i,j,id=args[0],o=GetObjectByID(id),s,ao,v,x;
 d.$cpe=new Array(); if(o) for(i=2; i<args.length; i+=2) { v=args[i+1]; s="o"; 
 ao=args[i].split("."); for(j=0; j<ao.length; j++) { s+="."+ao[j]; if(null==eval(s)) { 
  s=null; break; } } x=new Object; x.o=o; x.n=new Array(); x.v=new Array();
 x.n[x.n.length]=s; eval("x.v[x.v.length]="+s); d.$cpe[d.$cpe.length]=x;
 if(s) eval(s+"=v"); }
}

function ChangePropRestore() {//v1.0
 var d=document,x; if(d.$cpe) { for(i=0; i<d.$cpe.length; i++) { x=d.$cpe[i];
 if(x.v=="") x.v=""; eval("x."+x.n+"=String(x.v)"); } d.$cpe=null; }
}


//-----------------------------------------------------------------------
//	Generate a random number
//-----------------------------------------------------------------------

// Generate a random number between minNumber and maxNumber.
function createRandomNumber(minNumber, maxNumber) {

	var randomNumber = 0;
	
	// To generate random numbers from a given range, follow the steps below:
	//	Get number between 0.0 and 1.0 from random() method.
	//	Multiply it with the difference of upper value and one less than the lower value of the range.
	//	Use floor() to convert it into an integer.
	//	Add the lower value of the range.
	randomNumber = Math.floor( Math.random() * (maxNumber-minNumber-1) ) + minNumber;
	
// Just to be safe.
	if (randomNumber < 0) randomNumber = 0;
	if (randomNumber > maxNumber) randomNumber = maxNumber;

	return randomNumber;
}


//-----------------------------------------------------------------------
//	Determine height of viewable area
//-----------------------------------------------------------------------
function GetViewportHeight() {

	if (document.documentElement && 
		document.documentElement.clientHeight !== undefined) {
	
		return document.documentElement.clientHeight;
		
		}

	else if (document.body.clientHeight !== undefined) {
	
		return document.body.clientHeight;
		
		}
		
	else if (window.innerHeight !== undefined) {
	
		return window.innerHeight;
		
		}

}

//-----------------------------------------------------------------------
//	Automatically scroll past the masthead
//-----------------------------------------------------------------------

function ScrollPastMasthead() {

	// If viewport is not tall enough to show both the menu and the contents
	// then scroll past the masthead (leave main menu showing).
	if (GetViewportHeight() < 590) {
	
		scrollTo(0,45);
	}

}


//-----------------------------------------------------------------------
//	Automatically scroll past the header
//-----------------------------------------------------------------------

function ScrollPastHeader() {

	// If viewport is not tall enough to show both the menu and the contents
	// then scroll past the header (both the masthead image and main menu).
	if (GetViewportHeight() < 590) {
	
		scrollTo(0,74);
	}

}


//-----------------------------------------------------------------------
//	Highlight a link to show it is the currently active (selected) link
//-----------------------------------------------------------------------
function HighlightYouAreHereLink(Section, MenuLink) {

	var myLink = document.getElementById(MenuLink);
	
	switch(Section) {
	
		case "Main":
			myLink.style.fontWeight = "bold";
			break;
			
		case "VisitorInfo":
			myLink.style.borderTop= "1px #00004C dashed";
			myLink.style.borderBottom= "1px #00004C dashed";
			break;
		
		case "Art":
			myLink.style.borderTop= "1px #FCFCB8 dashed";
			myLink.style.borderBottom= "1px #FCFCB8 dashed";
			break;
		
		case "Events":
			myLink.style.borderTop= "1px #00004C dashed";
			myLink.style.borderBottom= "1px #00004C dashed";
			break;
		
		case "GetInvolved":
			myLink.style.borderTop= "1px #FCFCB8 dashed";
			myLink.style.borderBottom= "1px #FCFCB8 dashed";
			break;
		
		case "Shop":
			myLink.style.borderTop= "1px #FCFCB8 dashed";
			myLink.style.borderBottom= "1px #FCFCB8 dashed";
			break;
		
		case "AboutUs":
			myLink.style.borderTop= "1px #FCFCB8 dashed";
			myLink.style.borderBottom= "1px #FCFCB8 dashed";
			break;
		
		case "ContactUs":
			myLink.style.borderTop= "1px #FCFCB8 dashed";
			myLink.style.borderBottom= "1px #FCFCB8 dashed";
			break;
		
		case "Search":
			myLink.style.borderTop= "1px #FCFCB8 dashed";
			myLink.style.borderBottom= "1px #FCFCB8 dashed";
			break;
	}
}


//-----------------------------------------------------------------------
//	Display larger photos on pages with thumbnails
//-----------------------------------------------------------------------

	var PreviousPicture = "";

function ShowPicture(PictureID) {

	// First, if a picture is already displayed, remove it.	
	if (PreviousPicture != "") {
	
		var Picture = document.getElementById(PreviousPicture );
		Picture.style.display = "none";
	
	}

	// Hide Right Columnn since the column's color sticks above the photo area.
	var RightColumnDiv = document.getElementById('ExhibitionsRightColumn');
	RightColumnDiv.style.visibility = "hidden";

	
	// Make sure the div holding the picture is visible.
	var PictureDiv = document.getElementById('ExhibitionsPhotoArea');
	PictureDiv.style.display = "block";
	
	// Display the designated picture.
	var Picture = document.getElementById(PictureID);
	Picture.style.display = "block";
	
	// This will now be the Previous Picture.
	PreviousPicture = PictureID;
	
	// Display the message that allows redisplaying the text.
	var RedisplayText = document.getElementById('RedisplayText');
	RedisplayText.style.display = "block";

}

function RedisplayText() {

	// Remove the large picture that is currently displayed.
	if (PreviousPicture != "") {
	
		// Show Right Columnn again.
		var RightColumnDiv = document.getElementById('ExhibitionsRightColumn');
		RightColumnDiv.style.visibility = "visible";

		// Remove the picture.
		var Picture = document.getElementById(PreviousPicture );
		Picture.style.display = "none";
	
		// Remove the div holding the picture.
		var PictureDiv = document.getElementById('ExhibitionsPhotoArea');
		PictureDiv.style.display = "none";
	
	}
	
	// Remove the "Redisplay Text" message since the text is now displayed.
	var Text = document.getElementById('RedisplayText');
	Text.style.display = "none";

}


//-----------------------------------------------------------------------
//	PARSE URL ARGUMENTS
//-----------------------------------------------------------------------

/*
 * This function parses ampersand-separated name=value argument pairs from
 * the query string of the URL. It stores the name=value pairs in 
 * properties of an object and returns that object. Use it like this:
 * 
 * var args = getArgs();  // Parse args from URL
 * var q = args.q || "";  // Use argument, if defined, or a default value
 * var n = args.n ? parseInt(args.n) : 10; 
 */
 
function getArgs() {
	var args = new Object();
	var query = location.search.substring(1);     // Get query string
	var pairs = query.split("&");                 // Break at ampersand
	
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');          // Look for "name=value"
		if (pos == -1) continue;                  // If not found, skip
		var argname = pairs[i].substring(0,pos);  // Extract the name
		var value = pairs[i].substring(pos+1);    // Extract the value
		value = decodeURIComponent(value);        // Decode it, if needed
		args[argname] = value;                    // Store as a property
	}
	return args;                                  // Return the object
}


//-----------------------------------------------------------------------
//	Determine if "Return to Map" icon is to be displayed
//-----------------------------------------------------------------------

// When some pages are shown from a regular sub-menu, the 'Return to Map' icon should not be displayed.
// However, if the same page is displayed by way of the 'Expect the Unexpected' map, then the icon should be displayed.
//
// Specify the map icon should be displayed as follows:
//    <a href="x.html?FromMap=true">

function ShowMapIcon() {

	var args = getArgs();  // Parse args from URL
	var FromMap = args.FromMap || false;  // Use argument, if defined, or a default value


	var ReturnToMapDiv = document.getElementById('ReturnToMap');
	
	if (ReturnToMapDiv) {
	
		if (FromMap)
			ReturnToMapDiv.style.visibility = "visible";
		else
			ReturnToMapDiv.style.visibility = "hidden";
		}


	var ReturnToMapFromEventsDiv = document.getElementById('ReturnToMapFromEvents');
		
	if (ReturnToMapFromEventsDiv) {
	
		if (FromMap)
			ReturnToMapFromEventsDiv.style.visibility = "visible";
		else
			ReturnToMapFromEventsDiv.style.visibility = "hidden";
	}


	var ReturnToMapTopDiv = document.getElementById('ReturnToMapTop');
		
	if (ReturnToMapTopDiv) {
	
		if (FromMap)
			ReturnToMapTopDiv.style.visibility = "visible";
		else
			ReturnToMapTopDiv.style.visibility = "hidden";
	}

}


//-----------------------------------------------------------------------
//	Determine if "Return to Previous Page" text is to be displayed
//-----------------------------------------------------------------------

// When some of the "Upcoming Events" pages are shown from the "Art / Exhibitions / Upcoming" sub-menu,
// the 'Return to Previous Page' text should not be displayed.
// However, if the same page is displayed by way of the 'Upcoming Events' page, then the text should be displayed.
//
// Specify the text should be displayed as follows:
//    <a href="x.html?FromUpcomingEvent=true">

function ShowReturnToPreviousPageText() {

	var args = getArgs();  // Parse args from URL
	var FromUpcomingEvent = args.FromUpcomingEvent || false;  // Use argument, if defined, or a default value

	var ReturnToPreviousPageDiv = document.getElementById('ReturnToPreviousPage');
	
	if (ReturnToPreviousPageDiv) {
	
		if (FromUpcomingEvent)
			ReturnToPreviousPageDiv.style.visibility = "visible";
		else
			ReturnToPreviousPageDiv.style.visibility = "hidden";
	}
}


//-----------------------------------------------------------------------
//	Determine if "Return to Facility Rental" text is to be displayed
//-----------------------------------------------------------------------

// Specify the text should be displayed as follows:
//    <a href="x.html?FromFacilityRental=true">

function ShowReturnToFacilityRentalText() {

	var args = getArgs();  // Parse args from URL
	var FromFacilityRental = args.FromFacilityRental || false;  // Use argument, if defined, or a default value

	var ReturnToFacilityRentalDiv = document.getElementById('ReturnToFacilityRental');
	
	if (ReturnToFacilityRentalDiv) {
	
		if (FromFacilityRental)
			ReturnToFacilityRentalDiv.style.visibility = "visible";
		else
			ReturnToFacilityRentalDiv.style.visibility = "hidden";
	}
}


//-----------------------------------------------------------------------
//	Build string to append to href
//-----------------------------------------------------------------------

// On some pages, such as the Grassroots Art Center pages, the icon should be displayed
// on the second page, so the first page must invoke the second page with '?FromMap=true'
// if it was invoked with that string.  In other words, just passing the string along
// to the second page.

function BuildFromMapString() {

	var args = getArgs();  // Parse args from URL
	var FromMap = args.FromMap || false;  // Use argument, if defined, or a default value

	if (FromMap)
		return '?FromMap=true';
		else
		return '';
}


//-----------------------------------------------------------------------
//	Resize an image
//-----------------------------------------------------------------------

	var originalHeight = "";
	var originalWidth = "";
	
function ChangeSize(theImage, newHeight, newWidth) {

	originalHeight = theImage.height;
	originalWidth = theImage.width;
	
	theImage.style.zIndex = 2;
	
	theImage.height = newHeight;
	theImage.width = newWidth;

}

function RestoreSize(theImage) {

	theImage.height = originalHeight;
	theImage.width = originalWidth;
	
		theImage.style.zIndex = 1;

}


//-----------------------------------------------------------------------
//	Set height of LeftColumn to match height of ContentMainArea
//-----------------------------------------------------------------------
function SetLeftColumnHeight() {

	ContentMainAreaDiv = document.getElementById('ContentMainArea');
	LeftColumnDiv = document.getElementById('LeftColumnExtension');

	ContentMainAreaHeight = ContentMainAreaDiv.clientHeight;
	
	LeftColumnDiv.style.height = ContentMainAreaHeight + "px";

}


