// JavaScript Document

document.observe("dom:loaded", function() {
		observuj();
});

function observuj() {
		$$("#left li a").each(function(el) {
			 el.observe("click", function(ele) {
				 var what = el.up().up().id;
				 if(what != "") ele.stop(); 
			 
				 var im = el.down();
				 if(elem_exists(im))  {
					 if(im.alt == "plus") {
						 if(el.next() !== null) { 
							 el.next().style.display = "block";
						 }
						 im.alt="minus";
						 im.src=$("t-minus").src;
					 } else {
						 el.next().style.display = "none";
						 im.alt="plus";
						 im.src=$("t-plus").src;
					 }
				 }
 			 });
		});
}
/*
function ajaxuj(el) {
			el = $(el);
				 var what = el.up().up().id;
				 if(what.substr(0,5) == "types") {
					sport = what.substr(6);					 
					what = "types";
				 } else {
					sport = ""; 
				 }
				 var param = el.id;
				 var im = el.down();
				 if(im.alt == "plus") {
					 if(el.next() == null) {
						 new Ajax.Request(base_url+"xhr/"+what+get_query, { method: "post", postBody: "param="+param+"&sport="+sport, onSuccess: function(res) {																																
								insertsub(res.responseText,param);
						 }} );
					 } else {
						 el.next().style.display = "block";
					 }
					 im.alt="minus";
					 im.src=$("t-minus").src;
				 } else {
					 el.next().style.display = "none";
					 im.alt="plus";
					 im.src=$("t-plus").src;
				 }	
}

function insertsub(res,param) {	
		res = res.evalJSON(true);
		a = res.toArray();		
		a = a[0];
		if(typeof(a.id) == "undefined" || typeof(a.id) === null) {
		var ul = new Element(a.element);
		} else {
			var ul = new Element(a.element, {"id" : a.id});
		}
		lis = a.lis.toArray();
		for(var i = 0; i<lis.length; i++) {
				li = new Element("li");
				if(!(typeof(lis[i].href) == "string" )) {
					anch = new Element("a", {"id" : lis[i].id});
					anch.innerHTML = "<img src=\""+base_url+"system/application/gfx/t_plus.gif\" alt=\"plus\" />"+lis[i].inner;					
					li.appendChild(anch);
					anch.observe("click", function(ele) { 
						ajaxuj(this.id);
					});
				} else {
					anch = new Element("a", {"href" : lis[i].href});					
					anch.innerHTML = lis[i].inner;					
					li.appendChild(anch);
				}
				ul.appendChild(li);	
		}
		$(param).up().appendChild(ul);
}
*/
/*
function stopobservovani() {
    	$$("#left li a").each(function(el) {
			 el.stopObserving("click");
		});
}
*/
