var SVUI = {
	objects: [],
	load: function(container, options) {
		SVUI.Base.halt = true;
		this.Base.subclasses.each(function(svui_obj, pos) {
			if(!SVUI.objects[pos])
				SVUI.objects[pos] = new svui_obj();
			// SVUI.objects[pos].clean();
			SVUI.objects[pos].load(container, options);
		});
	},
	
	update: function(element, url, completehandler) {
		// Regex for Removing Page Anchors
		var reAnchor = /#[^\/]+/;
		
		// Request Update
		new Ajax.Updater($(element), url.replace(reAnchor, ''), {
			evalScripts: true,
			onComplete: function() {
				SVUI.load(element);
				completehandler();
			}
		});
	}
};

SVUI.Element = Class.create({
	element: null,
	initialize: function(element) {
		this.element = element;
	}
});

SVUI.Base = Class.create({
	objects: new Array(),
	halt: false,
	load: function(container, options) {
		container = $(container);
		options = options || this.options;
		if(options.autoLoad) {
			$A(options.classSelector).each(function(s) {
				container.getElementsBySelector(s).each(function(e) {
					new this.Element(e);
				}.bind(this));
			}.bind(this));
		}
	},
	
	registerObject: function(object) {
		// this.objects.push(object);
	},
	
	// @todo SVUI.Base.clean() method for cleaning old elements
	clean: function() {
		//this.objects.each(function(obj, pos) {
		//});
	},
	
	options: {
		autoLoad: false
	}
});