/**
 * Menu DropDown
 * 
 * @author: Thomaz Takashi Oda Toyama.
 * @retrun void
 */
 
(function($){
	$.fn.menuDropDown = function(options){
		var iSet 	= $.extend({},$.fn.menuDropDown.defaults,options);
		var parent	= $(this);
		
		parent.each(function(){
			var ul  		= $('> li > ul', this);
			
			$('> li', this).hover(
				function(){
					var liPos 	= $(this).offset();
					var ulSub	= $('> ul',this);
					var dWidth	= $(iSet.relative).width();
					var pos		= liPos.left + ulSub.width();
					
					if(pos > dWidth) ulSub.css({left: 'auto', right:'0'});
					else ulSub.css({left: '0', right:'auto'});
					
					ulSub.delay(iSet.openDelay).stop(true,true).slideDown(iSet.openSpeedy);
				}
				,function(){
					var liPos 	= $(this).offset();
					var ulSub	= $('> ul',this);
										
					ulSub.delay(iSet.closeDelay).stop(true,true).slideUp(iSet.closeSpeedy);
				}
			);
			
		});
		
	};
	$.fn.menuDropDown.defaults = {
		openSpeedy 		: 500
		,closeSpeedy	: 200
		,openDelay		: 1000
		,closeDelay		: 1000
		,relative		: '#cabecalho'
	};
})(jQuery);
