﻿//expando menu object
//version 6/27/06 dc
//Thanks to Chet Nickerson (http://www.bardichouse.com/) for introducing me to the "expando" trick


// set up a style to make all the expando items hide right off the bat (optional, but I get flashed before the script hide everything otherwise)
	document.write("<STYLE TYPE='text/css'>");
	document.write(".para, .expando {display: none}");
	document.write("</STYLE>");
	

	canSee='';
	if(navigator.appName.indexOf("Microsoft") > -1){
		canSee = 'block';
		} else {
		canSee = 'table-row';
		}

//MAIN EXPANDO OBJECT
function expandoMenu() {

 	this.supported =  (document.getElementById || document.all);
 	if (!this.supported){return false;}
 	
	this.radio=true; // behaves as radio buttons by default
	
	this.indicatorURLoff='';
	this.indicatorURLon='';

	this.memberList=function(){};  //empty object - we'll fill this up with properties (menu item names) later
				
	//SET ON INDICATOR
	this.setONindicator=setONindicator;
	function setONindicator(targetID,url){
		this.memberList[targetID].indicatorURLon=url;
	};
	
	//SET OFF INDICATOR
	this.setOFFindicator=setOFFindicator;
	function setOFFindicator(targetID,url){
		this.memberList[targetID].indicatorURLoff=url;
	};
	
	// setONindicators -- set all items to have same indicator
	this.setONindicators=setONindicators;
	 function setONindicators(url){
			if (!this.supported){return false;}	
			for (var thisTargetID in this.memberList)
			{
				this.setONindicator(thisTargetID,url);
			}
		}; // end of setONindicators

	// setOFFindicators -- set all items to have same indicator
	this.setOFFindicators=setOFFindicators;
	 function setOFFindicators(url){
			if (!this.supported){return false;}	

			for (var thisTargetID in this.memberList)
			{
				this.setOFFindicator(thisTargetID,url);
			}
		}; // end of setONindicators

	
	//ADD MENU ITEM
	this.addMenuItem=addMenuItem;
	function addMenuItem(targetID, indicatorID){

		this.memberList[targetID]=new this.menuItem(targetID,indicatorID);

		};
	
	// CLOSE ALL BUT -- closes all items but the one targeted
	this.closeAllBut =closeAllBut;
	 function closeAllBut(memberIDtoskip){

			if (!this.supported){return false;}	
		for (var i in this.memberList)
			{
			try
				{ 
					if (!(this.memberList[i].targetID==memberIDtoskip))
					{
						this.memberList[i].hide();
					}
				}
			catch(err)
				{
				// just go on, for example in safari, there will be a 'prototype' property to deal with
				}
		}
	}; // end of closeall
	
	// show
	this.show = show;
	function show(memberIDtoshow){
	
		if (!this.supported){return false;}			
		 this.memberList[memberIDtoshow].show();
	}; // end of show
	
		// TOGGLE VISIBILITY
	this.toggleVisibility = toggleVisibility;
	function toggleVisibility(memberIDclicked){

		var shown=this.memberList[memberIDclicked].shown();

		if (!this.supported){return false;}

		if (this.radio)
			{
			if( !shown){this.memberList[memberIDclicked].show();
			this.closeAllBut(memberIDclicked);
			}
			// if not shown then nothing
			}
		else
			{
		 	if (shown)
				{this.memberList[memberIDclicked].hide();}
			else
				{this.memberList[memberIDclicked].show();}
			}
		};

// ////////// ///////// ///////// ///////// //////// ///////// Menu Item object
	this.menuItem = menuItem;
	function menuItem(aTargetID, anIndicatorID){
	
			this.usesIndicator=false;
			if (anIndicatorID!='') {this.usesIndicator=true; }
			
			this.desc='';

			this.indicatorID=anIndicatorID;//can be blank, ('') if not using a marker
			this.targetID=aTargetID;//id of the area to be expandoed
			this.indicatorURLoff='f';
			this.indicatorURLon='';
			
				//shown
	
		this.shown=shown;
		function shown(){
			if (document.getElementById)
				{var ele = document.getElementById(this.targetID);}
			else if (document.all)
				{var ele = document.all[this.targetID];}
			if(ele.style.display==canSee)
				return true;
			else if (ele.style.display=="none")
				return false;			
	}
		// showING FUNCTION
		this.show=show;
		function show(){
			
				if (this.usesIndicator&&this.indicatorURLon !=''){
				
				 document.images[this.indicatorID].src = this.indicatorURLon;}//open icon
	
				//var current = this.canSee;

				if (document.getElementById)
					{document.getElementById(this.targetID).style.display = canSee;}
				else if (document.all)
					{document.all[this.targetID].style.display = canSee;}
			}
		   // HIDING FUNCTION
		   this.hide=hide;
			function hide(){

			if (this.usesIndicator&&this.indicatorURLon !=''){
			
				 document.images[this.indicatorID].src = this.indicatorURLoff;}//closed icon

				var current = 'none';

				if (document.getElementById)
					{document.getElementById(this.targetID).style.display = current;}
				else if (document.all)
					{document.all[this.targetID].style.display = current;}
			}// end of hide function
	};//end of menu item


}//  end of Expando Object

