// Box Controller class
function BoxController(controller,dir) 
{
	// Define Params
	this.__dir = dir;
	this.__controller = document.getElementById(controller);
	this.__active;
	this.__state;
	// Container
	this.__container = document.createElement('div');
	this.__container.className = 'dbox';
	// Loader
	this.__loader = document.createElement('p');
	this.__loader.className = 'loader';
	this.__loader.innerHTML = 'Loading';
	// Methods
	if(!BoxController.__initialized) {
		// Load Content
		BoxController.prototype.load = function(file)
		{
			// Toggle off
			if(this.__active==file&&this.__state) {
				this.__controller.parentNode.removeChild(this.__container);
				this.__state = false;
				return;
			}
			// Toggle on
			this.__controller.parentNode.insertBefore(this.__container,this.__controller.nextSibling);
			this.__active = file;
			this.__state = true;
			// Load data
			var parent = this;
			var request = zXmlHttp.createRequest();
			var url = encodeURI(this.__dir+'/'+file+'.php?remote=true');
			request.onreadystatechange = function() 
			{
				// Start loading
				if(request.readyState==2) {
					parent.__container.appendChild(parent.__loader);
				}
				// Finish loading
				if(request.readyState==4) {
					if(request.status==200) {		
						parent.__display(request.responseText);
					} else {
						parent.__display('<p>There was an error loading content.</p>');
					}
				}
			}
			request.open('GET',url,true);
			request.send(null);
		}
		// Display Content
		BoxController.prototype.__display = function(result)
		{
			this.__container.innerHTML = result;
		}
		BoxController.__initialized = true;
	}
}