/***********************************************************
Scriptname: 	dropdown_menu.js
Dependencies: 	*
Version: 		n/a
Description:	Animating the dropdown menu

Copyright: 		Webavance B.V. 2011
Legal: 			Any use of this script without Webavance B.V.
				express written consent is prohibited
************************************************************/

var menutmr;
(function($) {
	
	$.fn.ddmenu = function(c) {
		if (!c) var c = {};
		var prnt = $(this);
		
		c = $.extend({
			anim: false
		}, c);
		
		$(this).find('li')
			.bind('mouseenter', function() {
				_show_menu($(this).children('ul'));
			}).bind('mouseleave', function() {
				if ($(this).children('ul').length==0) return;
				menutmr = setTimeout(function() {
					_close_menu(prnt.find('ul'));
				}, 200);
			});
		
		
		$(this).find('ul')
			.bind('mouseenter', function(){
				clearTimeout(menutmr);
			}).bind('mouseleave', function(){
				_close_menu($(this));
			});
		
		
		function _show_menu(D) {
			if (D.length==0) return;
			clearTimeout(menutmr);
			
			D.css({ display: 'block' });
		}
		
		function _close_menu(D) {
			if (D.length==0) return;
			
			D.css({ display: 'none' });
		}
	}
	
})($);
