var Categories = {
	init: function(){
		$$(".parent-category").each(function(el){
			el = $(el);
			el.observe("click", this.catClick.bind(this, el));
		}.bind(this));
	},
	catClick: function(el){
		var node = el._node;
		if(!el._node){
			var _childs = el.parentNode.childNodes;
			if(_childs.length > 0){
				for(var i=0; i < _childs.length; i++){
					if(_childs[i].className == "child"){
						node = $(_childs[i]);
						el._node = node;
						break;
					}
				}
			}
		}
		var last_node = null;
		if(node){
			$$(".parent-category").each(function(_el){
				_el = $(_el);
				if(!_el._node){
					var _childs = _el.parentNode.childNodes;
					if(_childs.length > 0){
						for(var i=0; i < _childs.length; i++){
							if(_childs[i].className == "child"){
								_el._node = $(_childs[i]);
								break;
							}
						}
					}
				}
				if(_el._node && _el._node.expanded){
					Effect.BlindUp(_el._node, { duration: 0.3 });
					_el._node.parentNode.className = "parent";
					_el._node.expanded = null;
					last_node = _el._node;
				}
			}.bind(this));
			if(last_node != node){
				node.expanded = true;
				node.parentNode.className = "parent sel";
				Effect.BlindDown(node, { duration: 0.5 });
			}
		}
	}
}
Categories.init();