/*
Script: Message.js
	Show message like Message()
Author: 
	Tiago Mateus  -  tiagomsp@hotmail.com
License:
	MIT-style license.
Notes:
	Requie:
		Mootools-release-1.11.js ( Class.js , Class.Extras.js,Element.js)

*/

Message=new Class({
    options:{
		id:"Message"+$random(0,10000),
        width: 400,
        height: 100,
		top:0,
		left:0,
		thema:"default",
		conteiner:document.body,
		path:"",
		imagesPath:""
    },
    initialize: function(message,options){
		if($defined($(this.options.id))){$(this.options.id).remove();}
		this.setOptions(options);
		
        this.message=message;
        //this.options.container=document.body;
		
		this.conteiner=document.body;
		
		if(this.options.left==0){this.options.left=screen.width/2-this.options.width/2}
        if(this.options.top==0){this.options.top=document.body.clientHeight/2-this.options.height/2}
		
        this.options.path=this.getPath();
		this.options.imagesPath=this.options.path+this.options.thema+"/";
		var message=new Element('div',{
			styles:{
				'position':'absolute',
				'top':document.body.scrollTop+200,
				'left':this.options.left+"px",
				'width':this.options.width,
				'height':this.options.height,
				'background-color':'transparent',
				'z-index':10
			},
			events:{
				'click':function(){
					$(this.getParent()).remove();
				}
			}
		});
		message.innerHTML="<div style=\"background:transparent url("+this.options.imagesPath+"tl.png) left no-repeat;float:left;width:18px;height:18px;display:block;\"></div><div style=\"width:"+(this.options.width-36)+"px;background:transparent url("+this.options.imagesPath+"tm.png) repeat-x;float:left;height:18px;display:block\"></div><div style=\"background:transparent url("+this.options.imagesPath+"tr.png) right no-repeat;float:right;width:18px;height:18px;display:block\"></div><div style=\"width:"+this.options.width+"px;background:transparent url("+this.options.imagesPath+"ml.png) repeat-y;float:left;display:block;clear:both\"><div class=\"mr\" style=\"width:"+this.options.width+"\"><div class=\"mm\" style=\"height:"+this.options.height+"px;width:"+(this.options.width-36)+"px\">"+this.message+"</div></div></div><div class=\"bl\"></div><div class=\"bm\" style=\"width:"+(this.options.width-36)+"\"></div><div class=\"br\"></div>";
		var Overlay=new Element('div',{
			styles:{
				'position':'absolute',
				'top':0,
				'left':0,
				'opacity':0,
				'width':document.body.scrollWidth,
				'height':document.body.scrollHeight,
				'background-color':'black'
			},
			events:{
				'click':function(){
					$(this.getParent()).remove();
				}
			},
			'id':this.options.id+"-overlay"
		});	
		this.obj=new Element('div',{'id':this.options.id});
		this.obj.appendChild(Overlay);
		this.obj.appendChild(message);
		this.conteiner.appendChild(this.obj)
		var myEffect = $(this.options.id+'-overlay').effect('opacity', {duration: 1000});
		myEffect.start(0,0.5);
    },
	getPath:function(){
		var result;
		$$('script').each(function(el){
			var path=el.getProperty('src');
			var er =/Message\/Message.js/g;
			if (er.test(path)){result=path}
		});
		return result.substr(0,result.length-10);
	}
});
Message.implement(new Options);