/** 
 * @projectDescription Invisiblocker Declaration and related functionality. A lot of people have been having difficulty with the map Overriding other dojo classes. 
 * It would appear that even by overriding the z-Index of the map, it still would catch your mouseover events and break up any drag operations you 
 * were performing. I thought the only way to stop this is to use a blocker. As usual, you can find everything you'd ever want at www.sitepen.com.  
 *
 * All material at www.sitepen.com is free to use and so is this.
 *  
 * This is a reduced version of Peter Higgins' dojo.Blocker. 
 * Its been reduced for simplicity and speed, and is only available in 1 color; Invisible. 
 * 
 * @author 	Paul Bernhardt (bernhardtpaul@gmail.com), Peter Higgins (www.sitepen.com)
 * @version 	0.1
 */
dojo.declare("InvisiBlocker", null, {

	zIndex: 78,
	/**
	 * @classDescription InvisiBlocker. After creation (supplying the node), call block to block the node aforementioned, and call free to disable the blocker.
	 * @param {documentElement} node Node to set up blocker on. After setup, the blocker will remain inactive until block() is called. 
	 * @constructor
	 */
	constructor: function(node){

		this.node = dojo.byId(node);

		this.overlay = dojo.doc.createElement('div');

		dojo.place(this.overlay,dojo.body(),"last");
	
		dojo.style(this.overlay,{
				backgroundColor: "#efefef",
				position: "absolute",
				zIndex: this.zIndex,
				display: "none",
				opacity: 0
			});
		
		//this.positionNodeConnect = dojo.connect(this.node,"onresize",this,"_position");
		
		this._position();
		
		console.log("Succesfully created blocker and attached event to onresize: " + this.node);
	},
	/**
	 * @method _position private method but if you need to programatically repostion the blocker, use this.
	 */
	_position: function(){
					
		var pos = dojo._abs(this.node, true);
		
		var pos = dojo.mixin(dojo.marginBox(this.node), {
			l: pos.x, t: pos.y
		});
		
		dojo.style(this.overlay,{
			backgroundColor: "red",
			position:"absolute",
			left: pos.l + "px",
			width: pos.w + "px",
			height: pos.h + "px",
			top: pos.t + "px"
		});
		console.log("blocker repositioned: " + pos.t + ":" + pos.l);
	},
	/**
	 * @method block Block the node as dictated in the constructor.
	 */
	block: function(){

		if(this._showing){ return; }

		// Lets try without this. It may depend on the clients update speed.
		this._position();
		
		dojo.style(this.overlay, { opacity:0, display:"block" });
		
		this._showing = true;
		
		console.log("now blocking");
	},
	/**
	 * @method unblock Removes the blocker, but does not destroy it. 
	 */
	unblock: function(){

		this._showing = false;

		dojo.style(this.overlay, "display", "none");
		
		console.log("blocking off");
	}

});
