var Jt_Alert = new Class({
	initialize: function(type,title,texts,modality) {
		this._type			   = ('string' === $type(type)) ? type : 'JT_ALERT_INFO';
		this._title			   = ('string' === $type(title)) ? title : 'Info';
		this._texts			   = ('object' === $type(texts)) ? $H(texts) : $H();
		this._modality		   = (modality === 'JT_ALERT_MODAL' || 
								  modality === '') ? 'JT_ALERT_MODAL' : modality;
		this._body 			   = this._getBody();
		this._alert			   = null;
		this._modalityEnforcer = null;
		
		this._create();
	},
	
	destroy: function() {
		this._alert.dispose();
		if('element' === $type(this._modalityEnforcer)) {
			this._modalityEnforcer.dispose();
		}
	},
	
	_getBody: function() {
		return document.getElementsByTagName('body')[0];
	},
	
	_create: function() {
		if(this._modality === 'JT_ALERT_MODAL') {
			this._createModalityEnforcer();
		}
		
		this._alert = new Element('div',{
			'id': 'jtAlert__container'
		});
		
		this._alert.setStyles({
			'top': parseInt(((window.getSize().y-200)/2)+window.getScroll().y,10)+'px',
			'left': parseInt(((window.getSize().x-400)/2)+window.getScroll().x,10)+'px'
		});
		
		this._createTitle().inject(this._alert);
		this._createBody().inject(this._alert);
		this._createButton().inject(this._alert);
		this._alert.inject(this._body,'top');
	},
	
	_createTitle: function() {
		var self  = this;
		var title = new Element('div',{
			'id': 'jtAlert__title',
			'html': self._title 
		});
		
		return title;
	},
	
	_createBody: function() {
		var self	= this;
		var content = '';
		var bg		= '/pix/jt/icons/';
		
		this._texts.each(function(text){
			content += '<p>'+text+'</p>';
		}.bind(this));
		
		var body = new Element('div',{
			'id': 'jtAlert__body',
			'html': content
		});
		
		switch(this._type) {
			case 'JT_ALERT_INFO':
				bg += 'info.png';
				break;
			case 'JT_ALERT_WARNING':
				bg += 'warning.png';
				break;
			case 'JT_ALERT_ERROR':
				bg += 'error.png';
				break;
		}
		
		body.setStyle('background-image','url('+bg+')');
		
		return body; 
	},
	
	_createButton: function() {
		var button = new Element('div',{
			'id': 'jtAlert__button',
			'html': 'OK'
		});
		
		button.addEvent('click',function(){
			this.destroy();
		}.bind(this));
		
		return button;
	},
	
	_createModalityEnforcer: function() {
		this._modalityEnforcer = new Element('div',{
			'id': 'jtAlert__modalityEnforcer'
		});
		
		this._modalityEnforcer.setStyles({
			'width': (window.getSize().x)+'px',
			'height': (window.getScrollSize().y)+'px',
			'opacity': 0.5
		});
		
		this._modalityEnforcer.inject(this._body,'top');
	}
});
