/**
 *	ListListener - V1.00.160506 - May 12 2006
 *	---------------------------------------------
 *  Author - Martin Reurings
 *  Depends on: EventHandler.js
 */

var ListListener = {
	cRE:/ ?\bc(2|3|11)\b/i,
	exceptRE:/ ?\b(noclick)\b/i,
	cnRE: /^c[0-9]{1,3}\b/i,
	liRE:/^li$/i,
	inRE:/^(input|a|button|label|textarea)$/i,

	clickHandler:function (e) {
		if(e.shiftKey || e.ctrlKey || e.altKey) return true;
		//if(e.which > 1) return true;
		e = e||event;
		var target = e.target||e.srcElement;
		while (target.parentNode != null && !this.liRE.test(target.nodeName)) {
			if (target.nodeName && this.inRE.test(target.nodeName)) return true;
			target = target.parentNode;
		}
		if (target.nodeName && this.liRE.test(target.nodeName)) {
			var link = target.getElementsByTagName("a")[0];
			//If the linkHandler returns true, it did not perform any action, we'll need to do something ourselves.
			if (LinkListener && LinkListener.linkHandler(link,e)) 
				document.location = link.href;
			return cancelEvent(e);
		} else return true;
	},

	init:function() {
		//Grab all ul's
		var uls = document.getElementsByTagName("ul");
		var self = this;
		for (var i = 0; i < uls.length; i++) {
			var ul = uls[i];
			var contentDiv = ul.parentNode;
			//Search for a parent with a c*** class-name.
			while (contentDiv.parentNode != null && !this.cnRE.test(contentDiv.className)) contentDiv = contentDiv.parentNode;
			//If above-mentions classname, or the ul has a class that matches
			if ( (this.cRE.test(contentDiv.className)||this.cRE.test(ul.className)) 
				&& !this.exceptRE.test(contentDiv.className) ) {
				//Add clickhandler...
				var clicker = addEventHandler(uls[i], "click", function(e) {
					self.clickHandler(e);
				});
			}
		}
	}
}

if (onloadHandler) onloadHandler.add(function() {
	ListListener.init();
});

