

// Defined Constants
var HOOKTYPE_CLASS = 1;
var HOOKTYPE_ID = 2;

// Create BehaviorManager class
function BehaviorManager()
{
	/**** Properties ****/
	this.Behaviors = new Array();
	
	
	/**** Methods ****/
	
	this.RegisterBehavior = RegisterBehavior
	this.InstallBehaviors = InstallBehaviors;
	this.AddBehavior = AddBehavior;
		
	
	/****  Implementation ****/

	
	// Install a Behavoir into the DOM
	function AddBehavior(Tag, Behavior)
	{
		if (Tag.addEventHandler)
			Tag.addEventHandler(Behavior.EventName, Behavior.FunctionName, false);
		else
			eval("Tag.on" + Behavior.EventName + " = Behavior.FunctionName;");
	}
	

	// Install All Registered Behaviors	
	function InstallBehaviors()
	{
		// Loop through all Tags
		var Tags = document.body.getElementsByTagName('*');
		for (var Count=0; Count<Tags.length; Count++)
		{
			// Loop through Behaviors
			for (var BCount=0; BCount<this.Behaviors.length; BCount++)
			{
				// Add Class Behaviors
				if ( this.Behaviors[BCount].HookType == HOOKTYPE_CLASS && Tags[Count].className.indexOf(this.Behaviors[BCount].HookName) != -1 )
					this.AddBehavior(Tags[Count], this.Behaviors[BCount]);
			
				// Add ID Behaviors
				else if ( this.Behaviors[BCount].HookType == HOOKTYPE_ID && Tags[Count].id.indexOf(this.Behaviors[BCount].HookName) != -1 )
					this.AddBehavior(Tags[Count], this.Behaviors[BCount]);
			}
			
						
						
				
			/* Do General OnInstall Actions */
			
			// Hidden By Script
			if ( Tags[Count].className.indexOf('HiddenByScript') != -1 )
				Tags[Count].style.display = 'none';
				
			
		}
	}
	
	
	
	// Register a Behavoir with the Manager
	function RegisterBehavior(HookType, HookName, EventName, FunctionName)
	{
		this.Behaviors.push( new Behavior(HookType, HookName, EventName, FunctionName) );
	}
	
}
