var MessageBox = new Class({
		
	getOptions: function(){
		return {
			initialWidth: 5,
			initialHeight: 5,
			container: 'message',
			contentColor: '#FFF',
			waitDuration: 2000,
			offset: {x:0, y:0},	
			path: 'files/',			
			onOpen: Class.empty,
			onClose: Class.empty
		};
	},

	initialize: function(options) {
		this.setOptions(this.getOptions(), options);
		this.openClosePos = {};
		this.timer = 0;
		this.contentToLoad = {};
		this.index = 0;
		this.opened = false;
		this.contentObj = {};
		this.containerDefaults = {};
		this.elements = {};
		
		this.content = {};	

	},
	
	open: function(options){

		this.type = options.type;
		this.options.data = options.data;
		if (options.method) this.options.method = options.method;
		else this.options.method = 'get';

		this.target = options.target;
		if(!this.opened){
			this.opened = true;
			this.load();
		}else{
			this.load();	
		}
		
	},
	
	close: function(){
		this.containerEffects.start({
			opacity: 0 
		});
		$('MessageBoxContainer').dispose();
		this.opened = false;
	},
	
	
	resize: function(){

		var contentWidth = $('MessageBoxContainer').getSize().x;
		var contentHeight = $('MessageBoxContainer').getSize().y;

		var top = window.getHeight()/2-contentHeight/2+window.getScrollTop();
		var left = window.getWidth()/2-contentWidth/2;
		if(top < 0){top = 0}
		if(left < 0){left = 0}

		$('MessageBoxContainer').setStyles({
    			top: top,
    			left: left,
    			opacity: 0
		});

		$('MessageBoxContainer').underlayer({
			style: {
				width: contentWidth,
				height: contentHeight
			},

			glow: {
				size: 3,
				startColor: '#8E3029',
				endColor: '#8E3029',
				gmode: 'vertical'
			},
		
			fill: {
				startColor: '#a90329',
				endColor: '#702005',
				gmode: 'vertical'
			},

			stroke: {
				size: 5,
				startColor: '#fff',
				endColor: '#fff'
			},
			
			corners: 5
		});

		this.containerEffects = new Fx.Morph($('MessageBoxContainer'), {duration: 500, transition: Fx.Transitions.sineInOut});
		
		this.containerEffects.start({
			opacity: 1 
		});
	},
	
	load: function(){
		//this.container.removeClass('MultiBoxLoading');

		new Element('div', {id:'MessageBoxContainer'}).addClass('MessageBoxContainer').injectInside(this.options.container);

		if(this.type == 'htmlelement'){
			$(this.target).clone().setStyle('display','block').injectInside('MessageBoxContent');	
			this.resize();
		}else if(this.type == 'ajax'){

        		var req = new Request({   
            			method: this.options.method,   
            			url: this.target,   
            			data: this.options.data,     
            			onComplete: function(response) {
									$('MessageBoxContainer').set('html',response);
									MessageBox.resize();
									
								   }
        		}).send();  

			
		}
	}
		
	
});
MessageBox.implement(new Options);
MessageBox.implement(new Events);


