/********************************************************************

	FOREX.COM - CONTENT EXPANDER
	
	=========================================
	Author: Dave Bobak (bobak@teehanlax.com)
	Agency: teehan+lax
	Date: July 15, 2008
	=========================================	
	
	contentExpander is a JSON object which simply expands or contracts an html container, when clicking on a "handle." 
	Only one instance can be used per page. For more instances per page, please use the Mootools accordian.
	
	Public Methods
	-------------------------------------------------------------
	init (pseudo-constructor)
		The toggle class is bound to the click event of the handle
		- Arguments:	
			- handle (html id): This is the id of the html "handle" that you will click on to make the content expand
			- content (html id): This is the id of the html "content" that you will expand/contract once the handle has been clicked on 
		- Returns: null
	
	Internal "private" Methods
	-------------------------------------------------------------	
	toggle
		This function determines the current state and simply executes the closeContent or openContent functions accordingly
		- Arguments:
		- Returns: null
	closeContent
		This function uses MooTools effects to apply a nice transformation while closing the content container. A CSS class
		called "down" is removed from the handle when executed. This class controls the direction of little arrow bullet.
		- Arguments:
		- Returns: null		
	openContent
		This function uses MooTools effects to apply a nice transformation while opening the content container. A CSS class
		called "down" is removed from the handle when executed.	This class controls the direction of little arrow bullet.
		- Arguments:
		- Returns: null		
	
	Dependencies
	-------------------------------------------------------------
	- MooTools 1.2
	
*********************************************************************/

var contentExpander = {
	handle : null,
	content : null,
	initHeight: 100,
	blnClosed : false,
	
	init : function(handle, content) {	
		$(handle).addEvent('click', contentExpander.toggle);		
				
		contentExpander.handle = handle;
		contentExpander.contentID = content;
		contentExpander.initHeight = $(content).getSize().y;
	},
		
	toggle : function() {

		if (contentExpander.blnClosed) {
			contentExpander.openContent();
		}
		else {
			contentExpander.closeContent();					
		}
		
		contentExpander.blnClosed = !contentExpander.blnClosed;
	
	},
	
	closeContent : function() {

		var myEffect = new Fx.Morph($(contentExpander.contentID), {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
		 
		myEffect.start({
			'height': 0,
			'opacity': 0
		});
		
		$(contentExpander.handle).removeClass('down');

	},
	
	openContent : function() {

		var myEffect = new Fx.Morph($(contentExpander.contentID), {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
		 
		myEffect.start({
			'height': [0, contentExpander.initHeight],
			'opacity': [0, 1]
		});				
								
		$(contentExpander.handle).addClass('down');
	}				
	
};
