/**
 * This class will handle toggling the appearance given div
 * @param {String} expandControllerId The id of the element that 
 * 					will be used as a link to expand/collapse the 
 * 					target element
 * @param {String} id The id of the element to expand/collapse
 * @param {bool} defaultShowing True if the element should be showing
 * 					at first  
 * @param {Object} automaticOnClick True if the object should automatically
 * 					handle expansion/collapse of the target element when
 * 					the controller is clicked.
 */
function ToggleDiv(expandControllerId,id,defaultShowing,automaticOnClick)
{
	this.el = YAHOO.util.Dom.get(id);
	this.id = id;
	var region = YAHOO.util.Dom.getRegion(this.el);
	
	this.defaultWidth = region.right - region.left;
	this.defaultHeight = region.bottom - region.top;
	this.defaultX = region.left;
	this.defaultY = region.top;
	this.isVisible = defaultShowing;
	this.automaticOnClick = automaticOnClick;

	if (!defaultShowing)
	{
		YAHOO.util.Dom.setStyle(this.el, 'width',0);
		YAHOO.util.Dom.setStyle(this.el, 'height',0);		
		YAHOO.util.Dom.setStyle(this.el, 'visibility','hidden');
	}	
		
	this.onToggleDiv = function(e,me)
	{
		if (me.isVisible)
		{
			me.hide();
		}
		else
		{
			me.show();
		}
	}

	this.onFinishedAnimatingShow = function(e,anim,me)
	{
		YAHOO.util.Dom.setStyle(me.id,'visibility','visible');
	}
		
	this.hide = function()
	{		
		if (this.isVisible)
		{
			// hide the div			
		   	var attributes = {
		      	width: { to: 0 }, 
		      	height: { to: 0 }
		   	};
		      
		   	var anim = new YAHOO.util.Anim(this.el, attributes, 0.5, YAHOO.util.Easing.backOut);
			YAHOO.util.Dom.setStyle(this.id,'visibility','hidden');
		   	anim.animate();
		   
		   this.isVisible = false;
		}
	}
	
	this.show = function()
	{
		if (!this.isVisible)
		{
			// show the div
		   	var attributes = {
		      	width: { to: this.defaultWidth }, 
		      	height: { to: this.defaultHeight}
		   	};

			
			YAHOO.util.Dom.setStyle(this.id,'visibility','visible');
		   	var anim = new YAHOO.util.Anim(this.el, attributes, 0.5, YAHOO.util.Easing.backOut);
		   	anim.onComplete.subscribe(this.onFinishedAnimatingShow, this);
		   	anim.animate();
		   
		   	this.isVisible = true;
		}	      
	}
	
	if (this.automaticOnClick)
	{
		YAHOO.util.Event.addListener(expandControllerId,"click",this.onToggleDiv,this,true);
	}	
}

