/*
Behaviour v1.1 by Ben Nolan, June 2005. http://bennolan.com/behaviour/
Based largely on the work of Simon Willison. This file is entirely BSD licensed.
Modified by Ryan Parman (http://ryanparman.com) to use Prototype functions.
*/   

var Behaviour = {
	list: new Array,
	
	register: function(sheet) {
		Behaviour.list.push(sheet);
	},
	
	start: function() {
		Behaviour.addLoadEvent(function() {
			Behaviour.apply();
		});
	},
	
	apply: function() {
		for (h = 0; sheet = Behaviour.list[h]; h++) {
			for (selector in sheet) {
				list = $$(selector);
				if (!list) continue;
				for (i = 0; element = list[i]; i++) {
					sheet[selector](element);
				}
			}
		}
	},
	
	addLoadEvent: function(func) {
		var oldonload = window.onload;
		
		if (typeof window.onload != 'function') {
			window.onload = func;
		}
		else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}
};

Behaviour.start();
