/**
 * Por Design Drop Down
 *
 * Copyright (c) 2010 Por Design (pordesign.eu)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

(function($)
{
	$.fn.dropdown = function(options)
	{
		options = $.extend
		({
			speed: 200,
			effect: 'slide',
			timeout: 300
		}, options);
		
		$(this).hover( function()
		{
			$(this).data('current', $(this).hasClass('current'));
			$(this).addClass('current');
			
			$(this).parent('ul.timeout').stop();
			
			if (options.effect == 'slide')
			{
				$(this).children('ul:not(:animated)').stop(true, false).slideDown(options.speed);
			} else if (options.effect == 'fade')
			{
				$(this).children('ul:not(:animated)').stop(true, false).fadeIn(options.speed);
			}
			
			if ($(this).children('ul').offset().left + $(this).children('ul').width() > + $(document).width())
			{
				$(this).children('ul').css('left', -$(this).children('ul').width());
			}
		}, function()
		{
			if ( ! $(this).data('current'))
			{
				$(this).removeClass('current');
			}
			
			if (options.effect == 'slide')
			{
				$(this).children('ul').addClass('timeout').animate
				({
					'opacity': 1.0
				}, options.timeout, function()
				{
					$(this).removeClass('timeout');

					$(this).slideUp(options.speed);
				});
			} else if (options.effect == 'fade')
			{
				$(this).children('ul').addClass('timeout').animate
				({
					'opacity': 1.0
				}, options.timeout, function()
				{
					$(this).removeClass('timeout');

					$(this).fadeOut(options.speed);
				});
			}
		});

		return this;
	}
})(jQuery);

