/* ------------------------------------------------------------------------

------------------------------------------------------------------------- */
(function($){

	$.fn.extend({ 
			
		//Pass the options variable to the function
		megaDropdownMenu: function(options) {
			
			//Set the default values, use comma to separate the settings, example:
			var defaults = {
				megaDropdown:true,
				dropdownSpeed:500
			}
			
			var options =  $.extend(defaults, options);
			
			return this.each(function() {
				var o = options;
				
				
				//Function Controller
				
					//Activate Drop Down	
					if (o.megaDropdown==true){
						megaDropdown(o);
					} 		
			});//#end function controller
			
			function megaDropdown (o){
				
				//Capture Initial Drop Down Height
				var initialHeight = $('#pre-order-dropdown').height();
								
				//Reduce to 0px height
				$('#pre-order-dropdown').css("height","0px");
				
				//Restore mouse enter functions
				$('a#pre-order-nav').mouseenter(function(){
					$('#pre-order-dropdown').stop();
					$('#pre-order-dropdown').removeClass('hidden').animate({"height":initialHeight},o.dropdownSpeed);
				});
				
				//Mouse Leave
				$('#pre-order-dropdown').mouseleave(function(){
					$('#pre-order-dropdown').animate({"height":"0px"},o.dropdownSpeed,function(){
						$(this).addClass('hidden');
					});
				});
				
				//All other nav items
				$('a.not-dropdown').mouseenter(function(){
					$('#pre-order-dropdown').animate({"height":"0px"},o.dropdownSpeed,function(){
						$(this).addClass('hidden');
					});
				});
				
				

				
				//disable default function
				$('a#pre-order-nav').click(function(e){
					e.preventDefault();
				})
				
				var deviceAgent = navigator.userAgent.toLowerCase();
					var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
					if (agentID) {
				
					$('a#pre-order-nav').click(function(){
						$('#pre-order-dropdown').stop();
						$('#pre-order-dropdown').removeClass('hidden').animate({"height":initialHeight},o.dropdownSpeed);
						$('a#dropdown-close-touch').removeClass('hidden');
					});
					
					$('a#dropdown-close-touch').click(function(e){
						$('#pre-order-dropdown').animate({"height":"0px"},o.dropdownSpeed,function(){
							$(this).addClass('hidden');
						});
						//e.preventDefault();
					})
				
				}
				
			}//#megadropdown

		}
	});
     
})(jQuery);
