/*
 *
 * Copyright (c) 2009 C. F., Wong (<a href="http://cloudgen.w0ng.hk">Cloudgen Examplet Store</a>)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * See details in: <a href="http://cloudgen.w0ng.hk/javascript/javascript.php">Javascript Examplet</a>
 *
 */
(function($){
	function parseCSS(obj,css){
		var r=0;
		obj.css(css).replace(/\b(\d+)px\b/,function(s,t){r=parseInt(t)});
		return r;
	}
	function MattGlass(target){
		if(target){
		    var jNode = $('<div style="background-color:black;-moz-opacity:0.6;opacity:0.6;filter:alpha(opacity=60);position:absolute;z-index:1;_z-index:-1;'
				+'"></div>').appendTo("body");
			this.target=$(target);
			var w=this.target.width()+parseCSS(this.target,'borderLeftWidth')+parseCSS(this.target,'borderRightWidth');
			var h = this.target.height() + parseCSS(this.target, 'borderTopWidth') + parseCSS(this.target, 'borderBottomWidth');
			this.jNode = jNode.css({ top: this.target.offset().top, left: this.target.offset().left, width:"480px", height:"140px" });
//			this.jNode=jNode.css({top:this.target.offset().top,left:this.target.offset().left,width:w+"px",height:h+"px"});
			this.target.data("MattGlass",this);
		}
	}
	MattGlass.prototype.remove=function(){
		this.jNode.remove();
	}
	MattGlass.prototype.show=function(){
		this.jNode.show();
	}
	MattGlass.prototype.hide=function(){
		this.jNode.hide();
	}
	$.fn.addMattGlass=function(){new MattGlass(this)}
	$.fn.removeMattGlass=function(){
		if(this.data("MattGlass")){
			this.data("MattGlass").remove();
		}
	}
	$.fn.showMattGlass=function(){
		if(this.data("MattGlass")) this.data("MattGlass").show()
	}
	$.fn.hideMattGlass=function(){
		if(this.data("MattGlass")) this.data("MattGlass").hide()
	}
})(jQuery);