

if (!window.Modalbox)
	var Modalbox = new Object();
 
Modalbox.Methods = {
	options: {
		modal:false
	},
	_options: new Object,
	
	setOptions: function(options) {
		Object.extend(this.options, options || {});
	},
	
	initialized: false,
	
	_init: function(options) {
		this.setOptions(options);
		
		//Create the overlay
		var height =  document.body.offsetHeight || window.innerHeight || document.documentElement.clientHeight || 0;
		this.MBoverlay = new Element("div", { id: "MB_overlay", opacity: "0", style: "display: none; height:" +height +"px" });
		
		
		//Create DOm for the window
		this.MBwindow = new Element("div", {id: "MB_window", style: "display: none"});

		var injectToEl =  $(document.body);

		this.MBoverlay.insert(this.MBwindow);
		injectToEl.insert({'top':this.MBoverlay});
		this.initialized = true; // Mark as initialized
		this.hideObserver = this.hide.bindAsEventListener(this);
	},
	
	show: function(content, options) {
		try {
			this._init(options); // Check for is already initialized
			this.content = content;
			if (this.MBwindow.style.display == "none") { // First modal box appearing

				if(this.options.modal==true)
				{
					this.MBoverlay.observe("click", this.hideObserver);
				}
				this.MBoverlay.show();
				this.MBwindow.update(this.content);
				this.MBwindow.show();
				
			}
		}
		catch(e)
		{
			alert("error");
		}
		
	},
	
	hide: function() { // External hide method to use from external HTML and JS
		$(this.MBwindow).hide();
		this._deinit();
	},
	
	_deinit: function()
	{	
		this.MBoverlay.hide();
		this._removeElements();
	},
	_removeElements: function() {
		$(this.MBoverlay).remove();
		$(this.MBwindow).remove();
		
		/* Initialized will be set to false */
		this.initialized = false;
	}
};

Object.extend(Modalbox, Modalbox.Methods);