jQuery(document).ready(function() {
	jQuery('.treeGroup').hover(
		function () {
			jQuery(this).addClass('hover');
		},
		function () {
			jQuery(this).removeClass('hover');
		}
	);
	
	jQuery('.treeItem').hover(
		function () {
			jQuery(this).addClass('hover');
		},
		function () {
			jQuery(this).removeClass('hover');
		}
	);
	
	jQuery('.treeGroup').click(function() {
		var src = jQuery(this).attr('src');
		
		var id = jQuery(this).parent();
		var itemsElementId = id.attr('id') +'_items';
		
		// check if the sub-items are visible
		if (jQuery('#'+ itemsElementId).hasClass('notVisible')) {
			if (jQuery(this).hasClass('last')) {
				//jQuery(this).css('padding-bottom', 0); // I don't know why this was originally writte, but its
				// causing problems, so i have disabled it
			} 
			
			// show the sub-items, then navgat to the default url
			jQuery('#'+ itemsElementId).slideDown('slow', function() {
				jQuery('#'+ itemsElementId).removeClass('notVisible');
				
				// if a url has been associated with this div, then redirect to it
				if (src != '' && src != '#parent') {
					window.location = src;
				}
			});
		} else {
			// hide the sub-items
			// jQuery('#'+ itemsElementId).slideUp('slow');
			// jQuery('#'+ itemsElementId).addClass('notVisible');
			
			if (src == '' || src == '#parent') {
				jQuery('#'+ itemsElementId).slideUp('slow');
				jQuery('#'+ itemsElementId).addClass('notVisible');
			} else {
				window.location = src;
			}
		}
	});
	
	jQuery('.treeItem').click(function() {
		var src = jQuery(this).attr('src');
		window.location = src;
	});
});