/** Helps with basic tab functionality.
 * Joshua Logsdon
 * Licensed under the MIT License: http://en.wikipedia.org/wiki/MIT_License
 * Requires: jQuery v1.3+
 */
// Avoid collisions
;if(window.jQuery) (function($) {
	
	// plugin definition
	$.fn.logsdon_slide_block = function(options)
	{
		// Extend our default options with those provided.
		// Note that the first arg to extend is an empty object -
		// this is to keep from overriding our "defaults" object.
		var opts = $.extend({}, $.fn.logsdon_slide_block.defaults, options);
		
		// Other way of extending default options without needing properties
		//var config = {'foo': 'bar'};
		//if (settings) $.extend(config, settings);
		
		// Plugin code
		this.each(function()
		{
			var $container = $(this);
			
			// Hide all sliding blocks that aren't set to be open
			if ( $container.hasClass( opts.active_class ) )
			{
				$container.find( opts.openee ).css('display','block');
			}
			else
			{
				$container.find( opts.openee ).css('display','none');
			}
			
			// In case other elements are supposed to open the blocks
			var $opener = ( opts.opener ) ? $container.find( opts.opener ) : $container;
			
			// Add event handlers
			$opener.click(function(event)
			{
				var $this = $(this);
				
				if ( $container.hasClass( opts.opened_class ) )
				{
					$container.removeClass( opts.active_class +' '+ opts.opened_class );
				}
				else
				{
					// Close all other open blocks
					if ( opts.accordion )
					{
						var $opened = $container.siblings( '.'+ opts.opened_class );
						$opened.find( opts.openee ).slideToggle( opts.duration );
						$opened.removeClass( opts.active_class +' '+ opts.opened_class );
					}
					
					$container.addClass( opts.active_class +' '+ opts.opened_class );
				}
				
				$container.find( opts.openee ).slideToggle( opts.duration );
				
				return false;
			});
			
		});
		
		return this;
	};
	
	// plugin defaults - added as a property on our plugin function
	$.fn.logsdon_slide_block.defaults = {
		'accordion': false,// Whether to close other open blocks like an accordion
		'duration': 'slow',
		'active_class': 'active',
		'opened_class': 'opened',
		'openee': ':nth-child(1)',// Assume the default is the next child element
		'opener': ''// In case a different element should open the block
	};
	
	/*
	// Default implementation
	$(document).ready(function() {
		$('.slide-block').logsdon_slide_block();
	});
	*/
	
// Avoid collisions
})(jQuery);
/*ORIGINAL CODE
* 
// Add event handlers
$('.questions-box li').click(function(event)
{
	var $this = $(this);
	
	if ( $this.hasClass('faq_opened') )
	{
		$this.removeClass('active faq_opened');
	}
	else
	{
		var $opened = $this.siblings('.faq_opened');
		$opened.find('.block').slideToggle('slow');
		$opened.removeClass('active faq_opened');
		$this.addClass('active faq_opened');
	}
	
	$this.find('.block').slideToggle('slow');
	
	return false;
});
*/
/*EXAMPLE MARKUP

<style type="text/css">
.hidden {
	display: none;
}
.questions-box .block {
	display: none;
}
.questions-box li {
	cursor: pointer;
}
.questions-box li li {
	cursor: default;
}
</style>

<ul class="questions-box">
	<li class="slide-block">
		<div class="title">
			<strong>What is AdvisorMed?</strong>
			<a href="#" class="open-close">open-close</a>
		</div>
		<div class="block">
			<div>
				<p>Advisormed.com is a free, online report card/healthcare guide featuring physicians, hospitals, nursing homes, and home healthcare agencies throughout the nation.  Our goal is to help consumers with their healthcare choices.  AdvisorMed is the place consumers come to receive trusted, unbiased information on Healthcare Providers.</p>
			</div>
		</div>
	</li>
	<li class="slide-block even">
		<div class="title">
			<strong>How can AdvisorMed be free?</strong>
			<a href="#" class="open-close">open-close</a>
		</div>
		<div class="block">
			<div>
				<p>If you sign up or link to one of our providers websites (doctors, hospitals, nursing homes or home healthcare agencies marked as sponsored, we earn a referral fee.</p>
			</div>
		</div>
	</li>
</ul>
*/