/**
 * jquery pluggin to toggle visibility of a container when it's first heading is clicked
 *
 * @example: 	$(".toggle").boxToggle();
 *
 * @author Richard Allsebrook <richard@futurate.com>
 * @version 1.0.0
 */
$.fn.boxToggle = function() {

	// process each container
	this.each(function() {
	
		// find the first heading in this container
		var h = $(this).find("h1,h2,h3,h4,h5,h6")[0];
		
		/**
		 * @param speed mixed slow, normal, fast, or delay in MS
		 */
		var hideBox = function (speed) {

		  $(h).siblings().hide(speed);
		  
			$(h).addClass("hide")
					.removeClass("show")
					.unbind("click")
					.click(function() {
						showBox(0);
					});
			
		}
		
		/**
		 * @param speed mixed slow, normal, fast, or delay in MS
		 */
		var showBox = function (speed) {

			$(h).siblings().show(speed);
			
			$(h).addClass("show")
					.removeClass("hide")
					.unbind("click")
					.click(function() {
						hideBox(0);
					});
		
		}
		
		// initially, hide all the elements in the container
		// this should be done at speed 0 to avoid a flicker when page loads
		showBox(0);
		
	});
	
};

