/*
	
	Created by UsableWeb Copyright 2004
	
	The following functions are available in this library

	****		
		attachBehaviour
		
			Remark:
				Attaches the evHandler function to all objects of class className for the evName events
			Arguments:
				className is a string containing the css class name
				evName is a string, some example values ('mouseover', 'mouseout', 'click')
				evHandler is a reference to a function object
				any extra couples of arguments that follow are in the form of evName, evHandler 
	****

		getElementsByClass

			Remark:
				returns an array containing all the elements of a given classname
			Arguments: 
				aClassName: string 
	
	****

		attachEventHandler
		
			Remark:
				Works for IE and Mozilla
			Arguments: 
				elem is a reference to the object on which the event handler will be attached to
				evName is a string containing the name of the event to capture. eg: To capture onmouseover events this parameter must equal 'mouseOver'
				evHandler is a reference to a function object
			Example:
				attachEventHandler(window, 'load', init);
			
	****
	
		Notes when implementing an event handler function: 
			- 	Always have a parameter named e in the function parameter list (Mozilla needs this, it is the event object).
			- 	To get a reference to the source element that triggered the event use the eventSrcElement(e) function. e is the above parameter.
		Example:
			
*/

		function getElementsByClass(aClassName)
		{
		  var  my_array = document.getElementsByTagName("*");
		  var  retvalue = new Array();
		  var  i;
		  var  j;
		
		  for (i = 0, j = 0; i < my_array.length; i++)
		  {
			var c = " " + my_array[i].className + " ";
			if (c.indexOf(" " + aClassName + " ") != -1)
			  retvalue[j++] = my_array[i];
		  }
		  return retvalue;
		}
		
	/*	function attachEventHandler(elem, evName, evHandler)
		{	
			if(typeof window.addEventListener != 'undefined'){
				elem.addEventListener(evName, evHandler, false);
			}
			else if(typeof window.attachEvent != 'undefined'){
				elem.attachEvent('on' + evName, evHandler);
			}
		}*/
		
		function eventSrcElement(e){
			if (document.all) return window.event.srcElement;
			return e.currentTarget;					
		}
		
	
		function attachBehaviour(className, evName, evHandler){
			var elems
			elems = getElementsByClass(className)
			for (var i = 0; i < elems.length; i++){
				attachEventHandler(elems[i], evName, onMenuOver);
				for (var j=3; j < arguments.length; j+=2){
					attachEventHandler(elems[i], arguments[j], arguments[j+1]);
				}
			}
		}
			