/** JLG mod for special books dropdown **/

var to;
var $shutDown = null;
(function($) {

	$.fn.dynamItDrop = function() {

		return this.each(function() {

			$(this).children('li').children('ul, div').addClass('opened');

/*			$(this).children('li').not('.goonclick').children('a').mouseover(function() { //
				clearTimeout(to);
				$('.opened').not($(this).siblings('.opened')).stop(true, true).hide().siblings('a').removeClass('over');

				if($(this).siblings('.opened').length) {
					$(this).addClass('over');
					$shutDown = $(this).siblings('.opened').slideDown('slow');
				}
			});*/

			$(this).children('li.goonclick').children('a').click(function() {
				clearTimeout(to);
				$('.opened').not($(this).siblings('.opened')).stop(true, true).hide().siblings('a').removeClass('over');

				if($(this).siblings('.opened').length) {
					$(this).addClass('over');
					$(this).bind('mouseover',stayopen); 
					$shutDown = $(this).siblings('.opened').slideDown('slow');
				}
				return false;
			});

			$(this).children('li').children('a').mouseout(function() {
				if($(this).hasClass('over')) {
					$shutDown = $(this).siblings('.opened');
					to = setTimeout(function() {
						closeme($shutDown);
					}, 1000);
				}
			});

			$('.opened').mouseover(function() {
				clearTimeout(to);
			}).mouseout(function() {
				$shutDown = $(this);
				to = setTimeout(function() {
					closeme($shutDown);
				}, 1000);
			});

		});

	};

	function closeme(o) {
		o.slideUp('slow');
		o.siblings('a').removeClass('over').unbind('mouseover');
	}

	function stayopen() {
		clearTimeout(to);
	}

})(jQuery);
