jQuery(function() {
// make links styled as external open in a new window
	jQuery('a.external').click(function() {
		window.open(this.href);
		return false;
	});
	
	jQuery('label.required').append('<span class="required>*</span>');
	
// enable pop-up menu	
	jQuery('#left_menu ul.buttons li a').hover(function() {
		var next = jQuery(this).next();
		// if the next item is a list, that means it's a sub category		
		if (next.length > 0 && next.attr('tagName').toLowerCase() == 'ul') {
			if (!next.data('init') ) {
				next.data('init', true);
				
				var pos = jQuery(this).position();
				next.css({
					position: 'absolute',
					top: pos.top + 11, 
					left: pos.left + 140
				});
				
				next.hover(function () {
					jQuery(this).data('keepShowing', 1);
				}, function() {
					jQuery(this).data('keepShowing', 0);
					setTimeout ('hideMenu()', 200);
				});
			}
			
			next.fadeIn();
			next.data('keepShowing', 1);
			menus.push(next);
		}
	}, function() {
		var next = jQuery(this).next();
		if (next.length > 0 && next.attr('tagName').toLowerCase() == 'ul' ) {
			next.data('keepShowing', 0);
			setTimeout ('hideMenu()', 200);
		}
	});
});

/** currently displayed popup menus */
var menus = new Array();

function hideMenu() {
	var i;
	var tmp = new Array();

	for (i = 0; i < menus.length; i++) {
		if (!menus[i].data('keepShowing') ) {
			// get rid of inactive menus
			menus[i].fadeOut();
		} else {
			// keep a reference of active menus
			tmp.push(menus[i]);
		}
	}

	menus = tmp;
}
