Section = function(li, noClick) {
	
	if(noClick == null) noClick = false;
	
	this.children = [];
	
	this.li = li;
	if(li.getElementsByTagName('a')[0] != null) {
		
		this.a = li.getElementsByTagName('a')[0];
		
		if(!noClick) {
			this.a.onclick = createProxy(this, this.onclick);
			this.a.style.cursor = 'pointer';
		}
	}
}

Section.prototype.li;
Section.prototype.a;
Section.prototype.isOpen = true;
Section.prototype.children;
Section.prototype.openStyle;
Section.prototype.closedStyle;

Section.prototype.add = function(childSection) {
	this.children.push(childSection);
}

Section.prototype.onclick = function() {
	this.setOpen(!this.isOpen);
	return false;
}

Section.prototype.show = function(state) {
	this.li.style.display = state ? "" : "none";
	
	for(var i = 0; i < this.children.length; i++) {
		this.children[i].show(state ? this.isOpen : false);
	}
	
}

Section.prototype.setOpen = function(state, setState) {

	this.isOpen = state;
	
	this.li.className = state ? this.openStyle : this.closedStyle;
	
	if(this.children.length > 0) {
		var span = this.li.getElementsByTagName('span')[0];
		if(span != null) span.innerHTML = state ? "-" : "+";
	}
	
	for(var i = 0; i < this.children.length; i++) {
		
		 if(setState) this.children[i].setOpen(state, setState);
		 this.children[i].show(state);
	}
}


CafeLocator = function(r, styles) {
	
	this.styles = styles;

	var lis = r.getElementsByTagName("LI");
	
	this.sections = [];
	
	for(var i = 0; i < lis.length; i++) {
		
		var c = lis[i];
		
		if(c.parentNode == r) {
		
			this.sections.push(this.addSection(c));
		
		}
		
	}
	
}

CafeLocator.prototype.sections;
CafeLocator.prototype.styles;

CafeLocator.prototype.addSection = function(e) {

	var topLevel = new Section(e);
	topLevel.openStyle = this.styles[0];
	topLevel.closedStyle = this.styles[1];
	
	var childUL = topLevel.li.getElementsByTagName('ul');
	if(childUL[0] != null) {
	
		var children = childUL[0].getElementsByTagName('li');
		
		for(var ii = 0; ii < children.length; ii++) {
			if(children[ii].parentNode == childUL[0]) {
				topLevel.add(this.addSection(children[ii]));
			}
		}
	}
	
	return topLevel;
}

CafeLocator.prototype.closeAll = function() {
	for(var i = 0; i < this.sections.length; i++) this.sections[i].setOpen(false, true);
}

CafeLocator.prototype.openAll = function() {
	for(var i = 0; i < this.sections.length; i++) this.sections[i].setOpen(true, true);
}


function createProxy(oTarget, fFunction) {

    var aParameters = new Array();
    for(var i = 2; i < arguments.length; i++) {
      aParameters[i - 2] = arguments[i];
    }

    var fProxy = function() {
      //var aActualParameters =  Array(arguments);
	  //aActualParameters = aActualParameters.concat(aParameters);
	  
      return fFunction.apply(oTarget, aParameters);
      
    };

    return fProxy;

 }

