var ODIL_Base = Class.create({
	initialize: function() {
	},
	
	namespace: function() {
		return 'odil-';
	},
	
	properties: {
		version: 0.2
	},
	
	property: function(key) {
		return this.properties.get(key);
	},
	
	set_property: function(key, value) {
		return this.properties.set(key, value);
	},
	
	initialize_properties: function() {
		this.properties = $H(this.properties);
		this.properties.update($H(this.defaults));
		
		this.properties.set('properties_loaded', true);
	},
	
	load_properties: function(element) {
		if(!Object.isHash(this.properties))
			this.initialize_properties();
		
		if(element.readAttribute(this.namespace()))
			this.properties.update($H(element.readAttribute(this.namespace()).evalJSON()));
	}
});

/*
var WebElementsSub = Class.create(ODIL_Base, {
	initialize: function($super) {
		$super();
	},
	
	namespace: function($super) {
		return $super() + 'sub-';
	}
});
*/


// ODIL_Initializer
var ODIL_Initializer = {
	initialize: function() {
		self.selector_actions = new Hash();
	},
	
	add_selector_with_action: function(selector, action) {
		if(self.selector_actions.get(selector)) {
			self.selector_actions.get(selector).push(action);
		}
		else {
			self.selector_actions.set(selector, $A([action]));
		}
	},
	
	run_selectors_on_element: function(root_element) {
		self.selector_actions.each(function(pair) {
			
			root_element.select(pair.key).each(function(element) {
				pair.value.each(function(action) {
					action(element);
				});
			});
		});
	}
};
ODIL_Initializer.initialize();

Event.observe(window, 'load', function() {
	ODIL_Initializer.run_selectors_on_element($$('body').first());
	
/*
	$$('link[rel=behaviour]').each(function(element) {
		alert(element.inspect());
	});
*/
});


/*
Cruft: 

,
	
	run_selectors_on_root: function() {
		self.selector_actions.each(function(pair) {
			
			$$(pair.key).each(function(element) {
				pair.value.each(function(action) {
					action(element);
				});
			});
		});
	}


WebElementInitializers.add_selector_with_action('.selector', function() {
	alert('selector');
});
WebElementInitializers.add_selector_with_action('.another_selector', function() {
	alert('another_selector');
});
WebElementInitializers.add_selector_with_action('.selector', function() {
	alert('anotherFunction');
});
*/
