
(function($) {

	$.fn.dynamItDrop = function() {

		return this.each(function() {

			$(this).children('li').children('ul').addClass('opened');

			var to;
			var $shutDown = null;
			var openBox = '';
			$(this).children('li').children('a').click(function() {
				if( !$(this).siblings('ul').length ) return true;
				
				clearTimeout(to);
				$('ul.opened').hide();
				$(this).parent('li').siblings('li').children('a').removeClass('over');

				$(this).addClass('over');
				$shutDown = $(this).siblings('ul').show();
				openBox = $(this).attr('id');
				
				return false;
			}).mouseout(function() {
				if( $(this).attr('id') == openBox ) {
					clearTimeout(to);
					to = setTimeout(function() {
						closeme($shutDown);
					}, 2000);
				} else {
					$(this).removeClass('over');
				}
			});

			$('ul.opened').mouseover(function() {
				clearTimeout(to);
			}).mouseout(function() {
//				$shutDown = $(this);
				clearTimeout(to);
				to = setTimeout(function() {
					closeme($shutDown);
				}, 2000);
			});

		});

	};

	function closeme(o) {
		o.hide();
		o.siblings('a').removeClass('over');
	}

})(jQuery);
