/*
 * Treelist - jQuery plugin to hide and show branches of a tree list
 * by Samurai Girl
 * http://www.samurai.ge
 *
 *
 * Is not licensed under any licenses :)
 *
 * Revision: 1: jquery.treelist.js 02-07-2009 20:33:47 Elene Latsoshvili
 *
 */

(function($){
$.fn.treelist = function() {
	$(this).each(function() {
        var tree = this;
		// Hide all sub lists
		$('#'+tree.id+' ul').hide();
		$('#'+tree.id+' li').each(function(){
			// If list item is a link, don't make it expandible. Just go to the link
			if ($('>a',this).length==0) {				
				$(this).toggle(function(e){$('> ul',this).show(200);},function(e){ 
																			 
				// Get target element
				if (!e) var e = window.event;
					if (e.target) targ = e.target;
					else if (e.srcElement) targ = e.srcElement;
					if (targ.nodeType == 3) // defeat Safari bug
						targ = targ.parentNode;
				// If the target is not a sublist item, hide list
				if($('> ul',targ).length!=0) $('> ul',this).hide(200);
				else if ($(targ).attr('href')!=null) window.location.href = $(targ).attr('href');
				});
			}
		});
	});
}
})(jQuery);
