/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code.
*
* This implementation contains many enhancements by 
* 	Steve Bondy, InTouchTechnologyServices.com
* including enhancements gleaned from other sources.
***********************************************/
var persistmenu="no" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

// Gallery var's defined here as globals
var myGallery;
var myGallerySet;
var GalleryOn = false;

function GetElement(id) {
	//Generic function to get element by id - simplifies crossbrowser scripts
	if(document.getElementById){
		var el = document.getElementById(id);
	}
	else if (document.all) {
		var el = document.all[id];
	}
	return el;
}
function CollapseAll(){
		var ar = GetElement("MainMenu").getElementsByTagName("span");
		//DynamicDrive.com change
		for (var i=0; i<ar.length; i++){
			if (ar[i].className=="submenu") { //DynamicDrive.com change
				ar[i].style.display = "none";
			}
		}
}
function HideElementID(id){
	// Hide an element by id
	var ar = GetElement(id);
	ar.style.display = "none";
}
function ShowElementID(id){
	// Show an element by id
	var ar = GetElement(id);
	ar.style.display = "block";
}
function HideContent() {
	// Close all previously open content, identified by class = "content"
	var ar = GetElement("MainContentArea").getElementsByTagName("div");
	for (var i=0; i<ar.length; i++) {
		if (ar[i].className=="content") { ar[i].style.display = "none"; }
	}
}
function ShowPage(page) {
	CollapseAll();
	parent.location=page;
	return (1);
}
function SwitchMenu(obj){
	var el = GetElement(obj);
	if(el.style.display != "block"){ //DynamicDrive.com change
		// Close previously open menu if any
		var ar = GetElement("MainMenu").getElementsByTagName("span"); 
		for (var i=0; i<ar.length; i++){
			if (ar[i].className=="submenu") //DynamicDrive.com change
			ar[i].style.display = "none";
		}
		// And display new menu
		el.style.display = "block";
	}else{
		// User clicked on menu that was already open, so close it
		el.style.display = "none";
	}
}
function ShowContent(obj){
	// Show content block with id = obj
	var el = GetElement(obj);
	if(el.style.display != "block"){ //DynamicDrive.com change
		HideContent();	// Hide all open content divs
		// And display new content
		if ( obj == "Gallery" && ( GalleryOn ==  false )) { // The gallery has special handling
			// Stop the changing figures display and hide it
			//	myGallery.options.timed = false;
			myGallery.clearTimer();
			HideElementID("SideBar");	// Hide the Sidebar containing the figures
			HideElementID("MainMenu");	// Hide the menu
			if ( ! $defined(myGallerySet) ) {
				// myGallerySet only gets created the first time Gallery is selected from the menu
				myGallerySet = new gallerySet($('myGallerySet'), {
    				timed: false,
				    textShowCarousel: 'Thumbnails',
        			textShowGallerySelector: 'Back to Galleries'
				});
			}
			ShowElementID("Gallery");	// Show the gallery.
			ShowElementID("CloseGallery");// and the close gallery button
			GalleryOn = true;
		}
		else {
			if ( GalleryOn ) {
				// If Gallery was on turn it off
				HideElementID("Gallery");	// This hides the Gallery Div, which contains the GallerySet
				HideElementID("CloseGallery");// and the close gallery button
				GalleryOn = false;
				ShowElementID("MainMenu");	// And restore the menu
				ShowElementID("SideBar");	// And show the Sidebar
				myGallery.nextItem();		// This restarts the changing figures at far right
			}
			el.style.display = "block";	// Show the requested content
		}
	}
}

function HighlightMenu(obj){  //In Touch addition
	var el = GetElement(obj);
	var ar = GetElement("MainMenu").getElementsByTagName("div");
	// First unhighlight all menus
	for (var i=0; i<ar.length; i++){
		if (ar[i].className=="menutitle") ar[i].style.fontWeight = "normal";
	}
	// Then highlight the selected one
	el.style.fontWeight = "bold";
}

function get_cookie(Name) { 
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { 
	offset += search.length
	end = document.cookie.indexOf(";", offset);
	if (end == -1) end = document.cookie.length;
	returnvalue=unescape(document.cookie.substring(offset, end))
    }
  }
    return returnvalue;
}

function onloadfunction(){
  if (persistmenu=="yes"){
    var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
    var cookievalue=get_cookie(cookiename)
    if (cookievalue!="") GetElement(cookievalue).style.display="block"
  }
	// In Touch Technology Services addition
	// Show the MainMenu and hide the old fashioned one.
	// This let's it degrade nicely if javascript is disabled or 
	// not available on the client
	var ar = GetElement("MainMenu");
	if (ar ) {ar.style.display = "block";}
	var ar = GetElement("MainContent");
	if (ar) {ar.style.display = "block";}
	// end In Touch Addition
}

function savemenustate(){
  var inc=1, blockid=""
  while (document.getElementById("sub"+inc)){
    if (document.getElementById("sub"+inc).style.display=="block"){
      blockid="sub"+inc
       break
    }
    inc++
  }
  var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
  var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
  document.cookie=cookiename+"="+cookievalue
 }

/**********************************************************************************/
if (window.addEventListener) window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent) window.attachEvent("onload", onloadfunction)
else if (document.getElementById) window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById) window.onunload=savemenustate


