// JavaScript Document// Mootools Ajax form submission
//
// create a modal window

var modalbox = {
	
	init: function () {
		this.overlay = new Element('div', {'id': 'mdoverlay'}).injectInside(document.body).fade('hide');
		this.container = new Element('div', {'id': 'mdcontainer', 'styles': {'marginLeft': -(500/2)}}).injectInside(document.body).fade('hide');
		this.content = new Element('div', {'id': 'mdcontent'}).injectInside(this.container);
		this.bottom = new Element('div', {'id': 'mdbottom'}).injectInside(this.container);
		this.closebtn = new Element('a', {'id': 'mdclose', 'href': '#'}).injectInside(this.bottom).addEvent('click', this.close);
		this.redirect = '';
		this.position();
		window.addEvent('scroll', this.position);
		window.addEvent('refresh', this.position);
	},
	
	position: function (){
		modalbox.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
		modalbox.container.setStyles({'top': window.getScrollTop() + 200});
	},
	
	setcontent: function (content) {
		this.content.removeClass('mdloading');
		this.content.set('html',content);
	},
	
	setredirect: function (url) {
		this.redirect=url;
	},
	
	close: function () {
		if (modalbox.redirect!=''){
			location.href=modalbox.redirect;
		}
		else {
			modalbox.overlay.fade('out');
			modalbox.container.fade('out');
			window.removeEvent('scroll', this.position);
			window.removeEvent('refresh', this.position);
			return false;
		}
	},

	open: function () {
		this.content.empty().addClass('mdloading');
		this.overlay.fade(0.8);
		this.container.fade('in');
	}
	
};

window.addEvent('domready', modalbox.init.bind(modalbox));
