//****************************************************************
//****************************************************************
//	COPYRIGHT 2008, Vertex Software
//****************************************************************
//****************************************************************

//----------------------------------------------------------------
//----------------------------------------------------------------
// For elements that use the js_toggle class, calls jquery 
// slideToggle on the elementID passed after the js_toggle class
// name. For example, class='js_toggle help' will show teh element
// with id 'help' when the element on which the classes are added
// is clicked. Clicking again will hide the element.
//----------------------------------------------------------------
//----------------------------------------------------------------



//-----------------------------------------------------------
// toggle
//-----------------------------------------------------------
function toggle( element ) {
	var mToggleElementID = "";
	Initialize(element);
	

	//-----------------------------------------------------------
	// Initialize
	//-----------------------------------------------------------
	function Initialize( element ) {
		try {
			if (!element) return;
			var classes = element.className.split( /[ ]+/ );
			if (classes.length < 2) {
				alert( "Toggle Behavior: The ID of the element to be toggled is defined as the second class: class=\"js_toggle elementID\"" );
				return;
				}
			mToggleElementID = classes[1];
			if (!document.getElementById(mToggleElementID)) {
				window.status = ( "Toggle Behavior: Element not found - " + mToggleElementID );
				return;
				}
			$(element).click( onclick );
			}
		catch (error) {
			alert( "defaultText.Initialize: " + error.description  );
			}
		}


	//===========================================================
	// onclick
	//===========================================================
	function onclick( ) {
		try {
			var toggleElement = document.getElementById( mToggleElementID );
			if (!toggleElement) return true;
			$("#"+mToggleElementID).slideToggle("normal");
			}
		catch (error) {
			alert( "onclick: " + error.description  );
			}
		return  false;
		}



	}


AttachBehaviors("toggle");
