(function ($) {
$(function () {
	$('li.cat-item ul.children').each(function () {
		var me = $(this);
		var parent = me.parent();
		me.hide();
		parent.addClass('hasChildren').prepend("<span class='turnkey'>&nbsp;</span>");
		parent.find('span.turnkey').click(function () {
			if (parent.hasClass('open')) {
				parent.children('ul.children').slideUp();
				parent.removeClass('open');
			} else {
				parent.children('ul.children').slideDown();
				parent.addClass('open');
			}
			return false;
		});
	});
	$('li.current-cat').children('span.turnkey').click();
	$('li.current-cat').parents('li.cat-item').children('span.turnkey').click();
	
	function positionOnMouse (elem) {
		return function (e) {
			elem.css({top: e.clientY + 20, left: e.clientX - elem.width() + 100});
		};
	}
	
	var helpDisappearTimer = null;
	jQuery('#info .icon').mouseover(function (e) {
        jQuery(this).css('cursor', 'pointer');
		window.clearTimeout(helpDisappearTimer);
		var dockHelp = jQuery('#info-description');
		jQuery(window).mousemove(positionOnMouse(dockHelp));
		dockHelp.fadeIn();
	}).mouseout(function (e) {
		jQuery(window).unbind('mousemove');
		helpDisappearTimer = window.setTimeout(function () {
			jQuery('#info-description').fadeOut(400, function () {});
		}, 500);
	});
	
	jQuery('#info a').hover(function() {
	   jQuery('#info').addClass('over');
	}, function() {
	   jQuery('#info').removeClass('over');
	});
});
})(jQuery);
