//	jQuery dropdown plugin.
//	Basically, quick-and-easy code to add a dropdown to a nested list. 
//	YOU MUST DEFINE THE CSS FOR THIS, THIS WILL ONLY DO THE NECESSARY JAVASCRIPT TO SHOW/HIDE LISTS
/*	lists should be structured as follows:
	<ul class="dropdown">
		<li><a href="#">link</a></li>
		<li>
			<a href="#" class="">link</a>
			<ul>
				<li class="">
					<a href="#">sublink</a>
				</li>
				<li class="">
					<a href="#">sublink</a>
				</li>
			</ul>                   
		</li>
		...
	</ul>
	Use CSS to define a .hover class for root-level LI tags.
*/

jQuery.fn.dropdown = function(options){
	// define settings
	// clearBefore:	add a clearing div before the first ul element (useful for IE if elements are floated)
	// zIndex: the z-index of this element.
	// forceParentZIndex: force this element's parent to have a z-index that is 1 higher than settings.zIndex (IE layout bug fix)
	settings = jQuery.extend({
		clearBefore:	true,
		zIndex:		10,
		forceParentZIndex:	true,
		applyParentHover:	false,
		applyFirstLinkHover:	true
	}, options);
	
	if(settings.clearBefore){
		$("li", this).each(function(){
			$('ul:first',this).before('<div style="clear:both; />"');
		});
	}
	
	$(this).css('position:relative');
	
	$(this).css('zIndex', settings.zIndex);
	
	if(settings.forceParentZIndex){
		$(this).parent().css('zIndex', settings.zIndex + 1);
	}
	
	$("li", this).hover(function(){
		if(settings.applyParentHover){
			$(this).parent().addClass("hover");		
		}
		if(settings.applyFirstLinkHover){
			$(this).find('a:first').addClass("hover");		
		}
		$(this).addClass("hover");
		$('ul:first',this).css('visibility', 'visible');
	}, function(){
		if(settings.applyParentHover){
			$(this).parent().removeClass("hover");		
		}
		if(settings.applyFirstLinkHover){
			$(this).find('a:first').removeClass("hover");		
		}
		$(this).removeClass("hover");
		$('ul:first',this).css('visibility', 'hidden');
	});
};
