/**
 * More Information
 * Unobtrusive DHTML clickey-hidey "more information" content sections.
 * 
 * @version 1.4
 * @since 11/02/2008
 * @author Andrew Ramsden <http://irama.org/web/dhtml/more-info/>
 * @license Common Public License Version 1.0 <http://www.opensource.org/licenses/cpl1.0.txt>
 * @requires jQuery (tested with 1.2.2) <http://jquery.com/>
 */
/* start config */
moreInfoConfig = {
	sectionClass : 'more-information',
    openClass    : 'open',
	moreText     : 'Read more',
	hideText     : 'Hide extra information',
	joinText     : 'about'
};
/* end config */

(function($) {// start closure
	$(document).ready(function() {
		$('div.'+moreInfoConfig['sectionClass']).each(setupMoreInfo);
		$('p.more-info-hook a').toggle(showMoreInfo, hideMoreInfo);
	});
	// is applied to each div.more-information
	function setupMoreInfo() {
		
		$(this).hide();
		
		// add a frag-id to the link if a section id exists (for the benefit of "status-glancers")
		id = ($(this).attr('id')!=undefined)?$(this).attr('id'):'';
	
		// Get the the first and biggest heading for the link text
			heading = $(this).parent().firstHeading().text();
			heading = (heading!='')?'<span class="section-heading">'+moreInfoConfig['joinText']+' '+heading+'</span>':'';
		
		$(this).before('<p class="more-info-hook"><a href="#'+id+'"><span class="more-info-prefix">'+moreInfoConfig['moreText']+'</span> '+heading+'</a></p>');
	}
	function showMoreInfo() {
		$(this).find('span.more-info-prefix').empty();
		$(this).find('span.more-info-prefix').append(moreInfoConfig['hideText']);
		$(this).addClass(moreInfoConfig['openClass']);
		$(this).parent().siblings('div.'+moreInfoConfig['sectionClass']).slideDown(500);
		return false;
	}
	function hideMoreInfo() {
		$(this).find('span.more-info-prefix').empty();
		$(this).find('span.more-info-prefix').append(moreInfoConfig['moreText']);
		$(this).removeClass(moreInfoConfig['openClass']);
		$(this).parent().siblings('div.'+moreInfoConfig['sectionClass']).slideUp(500);
		return false;
	}
})(jQuery); // end closure