/* Behaviour v 2.1 
 *
 * @author Jussi L�f
 * (c) 2007 Ambientia Ltd.
 *
 * usage HTML:
 *
 * <p func="myFunctionName" myAttributes="optional,attributes,can,be,given"> Foo & Bar </p>
 *
 * usage javascript:
 *
 * Behaviour.list.mousedown_myFunctionName = function (node) {
 *    // the first param is the event source
 *    var clickedNode = node;
 *    //get your attributes this way
 *    var myAttributes = node.getAttribute('myAttributes');
 *    // do something...
 * }
 *
 */


function attachEH(object, event, handlerFunction)
{
	if (object.attachEvent)	object.attachEvent("on" + event, handlerFunction);
	else object.addEventListener(event, handlerFunction, true);
}

var Behaviour = {
	list : {},

	handle : function (event)
	{
		//IE compability
		if (!event) event = window.event;

		try { Behaviour.trigger(event.srcElement || event.target, event.type) } catch (err) {}
	},

	trigger : function (node, eventType)
	{
		do { 
				try {
					if (node.getAttribute('func')) {
						this.list[eventType + "_" + node.getAttribute('func')](node) 
					} else {
 						var hashName = eventType + "_" + (node.id ? node.id : '') + "_" + (node.className ? node.className : '');
 						this.list[hashName](node);
					}
					
					if (node.last) {
						break;
					}
				} catch (err) {} 
		} while ( (node = node.parentNode) )
	},

	start : function ()
	{
		// start needed eventhandlers here
	    	attachEH(document.body, 'mousedown', Behaviour.handle);
	}
}

attachEH(window, 'load', Behaviour.start);	

