/* Usage 

1:  Get JQuery (jquery.com)
2: Put these lines in your header  ( assuming the name of the jquery here )
	<script type="text/javascript" src="scripts/jquery-1.1.2.js"></script>

	<script type="text/javascript" src="scripts/div_toggler.js"></script>
3: 
	Learn how to use jQuery Selectors ( mostly like CSS )
4:
	<script type="text/javascript">
		$(document).ready(function(){
			$("a.toggler_thing").toggler("div.thing_to_toggle", "toggledClass");
			$("a.toggler_thing").toggler("div.other_thing_to_toggle","other_toggled_class");		
		});
	</script>
*/


jQuery.fn.toggler = function( what, eclass, hidey){
	
	jQuery(this).click(function(){
		/* Find MY parent */
		var scope=jQuery(this).parent();
		/* Mark My contents with TX */
		jQuery("."+eclass,scope).addClass('tx');
		
		/* close all open windows */
		if( hidey ){
			jQuery(" ."+eclass).not(jQuery(what, scope)).each(function(){
				if ( jQuery(this).is("."+eclass) && !jQuery(this).is(".tx") )
				{
					jQuery(this).animate({height: 'hide'},300);
				}
			});
		};
		jQuery(" ."+eclass).removeClass(eclass);
		
		/* toggle teh chosen one */
		if( hidey ){
			if(  jQuery(what,scope).is("."+eclass) != true ){
	
					
				jQuery(what, scope).animate({height: 'toggle'},300);
			};
		};
		jQuery(what, scope).toggleClass(eclass);
		
		/* kill all tx's */
		var txnode = jQuery('.tx');
		/*if( hidey){
			txnode.animate({height: 'hide'},300);
		}*/
		txnode.removeClass(eclass);
		txnode.removeClass('tx');
		
		return false;
	});
	
	
	return this;
};

