var jtk = new JoookToolkit();

function Layer(emtId, clickSrc){
	this.emt = null;
	this.visible = false;
	this.clickSrc = clickSrc;
	this.canceling = false;

	this.setOrigin = function(x, y){
		this.emt.style.left = x + "px";
		this.emt.style.top = y + "px";
	}
	
	this.show = function(){
		this.canceling = true;
		this.emt.style.display = "block";
		this.visible = true;
	}
	
	this.hide = function(){
		if(!this.canceling){
			this.emt.style.display = "none";
			this.visible = false;
		}
		this.canceling = false;
	}
	
	
	this.attachHandlers = function(){
		var that = this; // Store current object reference for later delegate binding
		
		jtk.addEvent(document.body, "click", function(){
			JTKDelegate.create(that, that.hide());
		});
		
		jtk.addEvent(this.emt, "click", function(){
			JTKDelegate.create(that, that.show());
		});
		
		jtk.addEvent(this.clickSrc, "click", function(){
			JTKDelegate.create(that, that.show());
		});
	}
	
	this.init = function(emtId){
		this.emt = jtk.select("#" + emtId)[0];
		this.emt.style.position = "absolute";
		this.attachHandlers();
	}
	
	this.init(emtId);
}