// set new error
var msgBox = new msgBox_();

//#####################// DOCUMENT READY //#####################//

$(function(){	
	// set the initial dimensions
	msgBox.setDimensions();
	
	// set dimensions on size change
	$(window).resize(function(){
		msgBox.setDivStyle();
	});
});

function msgBox_(){
	//#####################// VARS //#####################//
	
	this.blanketImg = "https://secure.rethinkgroup.org/v1/images/blanket.png";
		
	this.docH;
	this.docW;
	this.winH;
	this.winW
		
	//#####################// FUNCTIONS //#####################//
	
	this.setDimensions = function(){
		this.docH = $(document).height();
		this.docW = $(document).width();
		this.winH = $(window).height();
		this.winW = $(window).width();
		if($('#msgBox').attr("display") == "block"){
			this.show();
		}
	}
	
	this.setDivStyle = function(){
		$('#msgBlanket').height(0).width(0);
		this.setDimensions();
		var style = "position:fixed;max-width:960px;max-height:"+this.winH+"px;overflow-y:auto;overflow-x:visible;z-index:1010;padding:10px;border:1px red solid;background-color:white;font-size:small;-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;";
		$('#msgBox').attr("style",style);
		var blanketStyle = "width:"+this.winW+"px;height:"+this.docH+"px;z-index:1009;position:absolute;background-image:url("+this.blanketImg+");left:0px;";
		$('#msgBlanket').attr("style",blanketStyle);
		this.position();
	}
		
	this.show = function(html,symbol){
		if($('#msgBox').length){
			this.hide();
		}
		if(symbol){
			var img;
			switch(symbol){
				case 1:
					img = "warning";
					break;
				case 2:
					img = "question";
					break; 
			}
			html = '<div style="text-align:center"><img src="../images/'+img+'.png"></div>'+html;
		}
		var msgBox = '<div id="msgBox" style="display:none;">'+html+'</div>';
		var msgBlanket = '<div id="msgBlanket" style="display:none;"></div>';
		$('body').append(msgBox).prepend(msgBlanket);
		this.setDivStyle();
	}
	
	this.position = function(){
		var msg = $('#msgBox');
		msg.show();
		var msgW = msg.width();
		var msgH = msg.height();
		var posL = ((this.docW - msgW)/2);
		var posT = ((this.winH - msgH)/2);
		msg.css("left",posL+"px").css("top",posT+"px");
		if(this.winW < msgW){
			this.hide();
		}
	}
	
	this.hide = function(){
		$('#msgBox').remove();
		$('#msgBlanket').remove();
	}
}
