/*
*	Dropdown navigation plugin for the jQuery library
*	Author: Jon Watkins
*	Url: http://www.iamjonwatkins.co.uk
*/
jQuery(function($){
	$.fn.extend({
		
		dropnav: function(options) {
			
			/*	Store the parsed element to a variable*/	
			var $this = $(this);
			
			/*  
				Sets the deafult options for the dropnav
				These can be overridden when the plugin is called ie.
				$(document).read(function(){
					$("#nav").dropnav({
						speed:300,
						nudge: true
					});
				});
			*/
			 $.fn.dropnav.defaults = {
				speed:1,
				nudge: false,
				highlight: true,
			 }
			 var opts = $.extend($.fn.dropnav.defaults, options);
			 
			/*	Adds a background image to the first child of a list item that contains a 
			 *	dropdown menu
			 */
			$this.each(function(){
				$("li:has(ul) > a").each(function(){
					$(this).addClass("dropbg");
				});
			});
			
			/*	Show and hide the child unordered list when the parent is hovered*/		
			$this.each(function(){
				$("li:has(ul)").hover(function(){
					$(this).children("ul").fadeIn(opts.speed); /*Mouse in*/
				}, function(){
					$(this).children("ul").fadeOut(opts.speed); /*Mouse out*/
				});
			});	
			
			/*	Nudge the dropdown links when hovered is the option nudge is set to true*/
			if(opts.nudge == true)
			{
				$this.each(function() {
					$("ul ul a").hover(function(){
						$(this).animate({ paddingLeft:'15' },100);
					}, function(){
						$(this).animate({ paddingLeft:'0' },100);					
					});
				});
			}/* 	End if statement*/
			
			/*	Add a class to all of the odd list items to enable you to highlight them*/
			if(opts.highlight == true)
			{
				$this.each(function(){
					$("ul ul li:odd").each(function(){
						$(this).addClass("highlight");
					});
				});
			} /*	End if statement*/	
			
		} /*	End of dropnav*/		
	});
});

