/****************************************************************
 *
 * jQuery toggler plugin - by Kreck Design Solutions
 * v0.9.2
 * 
*****************************************************************/

/*

Sample usage: 

<style type="text/css">
ul#myList ul {
 display:none;	
}
</style>

<div id="someOptionalWrapperDiv">
	<ul id="myList">
		<li><a href="#">First Section</a>
			<ul>
				<li><a href="1a.html">Sub 1A</a></li>
				<li><a href="1b.html">Sub 1B</a></li>
				<li><a href="1c.html">Sub 1C</a></li>
			</ul>
		</li>
		<li><a href="#">Second Section</a>
			<ul>
				<li><a href="2a.html">Sub 2A</a></li>
				<li><a href="2b.html">Sub 2B</a></li>
			</ul>
		</li>
	</ul>
</div>

<script type="text/javascript">
$(document).ready(function() {
	$('#myList').toggler([], '#myList');		// yes, this seems like awkward usage. Sorry!
});
</script>

*/




(function($) {


	$.fn.toggler = function(options, parentListSelector) {

		// We're asking for a parentSelector now to make the jQuery "live" click handler
		// isolate its scope instead of binding to ALL list-items on the page...
		// This means we end up with goofy/weird usage parameters...

		return this.each(function() {

			// "this" should be our parent UL (although may be several UL's if you want, I suppose?)
			var $ul = $(this);

			// initially hide all child divs (or child lists!) inside our parent-list list items.
			
			$ul.find('li > div, li > ul').hide();

			// listen for toggle event on all LIST ITEMS inside of our parent-list
			// Note, WAS: a link within the li!
			// NOTE! Cannot use with "live" event, it will end up binding to ALL list-items on page unless
			// we give a better selector than just "li"...
			//$ul.find('li').live('click', function() {
			$(parentListSelector + ' li').live('click', function() {
																 
				// only slide and cancel, if there are children! Won't someone think of the children?!?!
				var $possibleChildren = $(this).find('div:first, ul:first');
				if ($possibleChildren.length > 0) {
					$possibleChildren.slideToggle('fast');
					return false; 		// cancel the native click event
				}
				else {
					// just let the link work normally...	
				}
			});

		});

		// what about a show-all or hide-all ??

	};



})(jQuery); 


