/*
	© 2009 by Noël Bossart, namics ag
*/
(function($) {
	NX.togglelist = NX.togglelist || {};
	$.extend(NX.togglelist, {
		//amaier: url is set from outside
		url: "",
		init: function(c) { 
			// hide all the sub lists
			$("span.toggle", c).next().hide();

			// add cursor to toggle 
			$("span.toggle", c).css("cursor", "pointer");

			// arrow down sub lists closed
			$("span.toggle", c).addClass("closed");

			// click toggle function for sub list and icon
			$("span.toggle", c).click(function() {
				var $this = $(this);
				$this.next().toggle(100);
				$this.toggleClass("open");				
				if(this.id){
					//amaier: added id check to bind $get on 2nd level spans only
					if(this.id.substring(0,3)!="CAT"){
						// insert animation 
						$this.addClass("loading").wrapInner("<span></span>");
						$.get(NX.togglelist.url, { id: this.id }, function(data){
							$this.removeAttr("id");
							var $data = $(data);
							NX.togglelist.init($data);
							$this.after($data);
							//remove animation
							$this.removeClass("loading");
						});	
					}
				}
				
				return false;
			});
			$("li.toggleshow span", c).addClass("open").next().show();
		}
	});
})(jQuery);


