﻿//expando menu object
//version 6/27/06 dc


// 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)
function turnOffExpandoClass(){
	
	document.write("<style TYPE='text/css'>");
	document.write(".expando {display: none}");
	document.write("</style>");
	
}

function errorFunction(obj,errorObj){
		return;
		alert("error: "+errorObj+"\nindicatorID: "+
			obj.indicatorID+"\nelement: "+
			document.getElementById(obj.targetID)+"\nstyle: "+
			document.getElementById(obj.indicatorID).style+"\nparentNode: "+
			document.getElementById(obj.indicatorID).parentNode+"\nparentNode.innerHTML: "+
			document.getElementById(obj.indicatorID).parentNode.innerHTML+"\nbackgroundImage: "+
			document.getElementById(obj.indicatorID).style.backgroundImage+"\ntrying to put: "+
			 obj.indicatorURLoff
			);
		
	}
	


	
	//alert("running temp version of expando, for debugging");

	canSee='block';
	

//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.indicatorProperty = "backgroundImage";//'backgroundImage' is the option for modifying by style, leave blank to use old method of img src
	this.locked=false;//lock into ther present state


	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);
		return this.memberList[targetID];
		};
	
	// CLOSE ALL BUT -- closes all items but the one targeted
	this.closeAllBut =closeAllBut;
	 function closeAllBut(memberIDtoskip){
		if(this.locked){return true;}
		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 for loop
		
	}; // end of closeall
	
	this.closeAll = closeAll;
	function closeAll(){
		if(this.locked){return true;}
		closeAllBut("");
	};

	// show
	this.show = show;
	function show(memberIDtoshow){
		if(this.locked){return true;}
		if (!this.supported){return false;}		

		 this.memberList[memberIDtoshow].show();
		
	}; // end of show
	
		// TOGGLE VISIBILITY
	this.toggleVisibility = toggleVisibility;
	function toggleVisibility(memberIDclicked){
		if(this.locked){return true;}

		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='';
			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];}
			
			try{
			if(ele.style.display==canSee)
				{return true;}
			else if (ele.style.display=="none")
				{return false;}		
			}
			catch(er)
			{}
	}
		// showING FUNCTION
		this.show=show;
		function show(){

				try{
					if (this.usesIndicator){
						document.getElementById(this.indicatorID).style.backgroundImage = "url("+this.indicatorURLon+")";}
						}
				catch(er){errorFunction(this,er);}
	
				try{

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

			try{
					if (this.usesIndicator){
						document.getElementById(this.indicatorID).style.backgroundImage = "url("+this.indicatorURLoff+")";}
						}
				catch(er){errorFunction(this,er);}
	
				try{
				

				var current = 'none';

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


}//  end of Expando Object

