var buffer = null;
var shoper = false;

function show_node(e) {
	e=(e)?e:window.event;	
		
	var leftOffset = parseInt((e.layerX) ? e.layerX : e.offsetX);
	if((leftOffset < 15 || shoper) && this.className != 'end') {		
		var subnode = this.parentNode.getElementsByTagName('UL')[0]
		if(subnode) {			
			var open_node = (this.className == 'curr') ? false : true;
			if(open_node) {
				if(this.parentNode.className == 'last') this.parentNode.style.backgroundPosition = '5px ' + (this.parentNode.firstChild.offsetHeight - 36) + 'px';
				this.className = 'curr';
				subnode.style.display = 'block';				
			} else {
				if(this.parentNode.className == 'last') this.parentNode.style.backgroundPosition = '-150px -22px';
				this.className = '';
				subnode.style.display = 'none';			
			}		
		}		
		this.blur();
		return false;			 
	}
}

function init_tree(name) {
	
	plus = new Image();
	plus.src = '/img/cat-list-plus.gif';
	
	minus = new Image();
	minus.src = '/img/cat-list-minus.gif';	
	
	end = new Image();
	end.src = '/img/cat-list-end.gif';
	
	if(name.indexOf('shoper') != -1 || name.indexOf('docs') != -1) shoper=true;
	var tree_obj = document.getElementById(name);
	if(tree_obj) {
		var items = tree_obj.getElementsByTagName('A');
		for(var i=0; i<items.length; i++) {
			items[i].onclick = show_node;
		}
	}
	
	var ntc = document.getElementById('NEED_TO_CLICK');
	if(ntc) {		
		ntc.style.backgroundPosition = '5px ' + (ntc.firstChild.offsetHeight - 36) + 'px';			
	}		
}