/**
 * @author Cientista
 */


document.onkeyup = function(e) {
	var kC  = (window.event) ? event.keyCode : e.keyCode; // MSIE or Firefox?
		var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE // MSIE : Firefox
        
    if(kC==Esc) Popup.close();
}

var Popup = new function() {
	// Private Properties
	function divBlanket() { return document.getElementById("blanket"); }
	function framePopup() { return document.getElementById("popup-iframe"); }
	
	this.pReturn = function(value1, value2) { // This is called by the popup window
		this.close();
		this.onReturn(value1, value2);
	}
	
	this.onClose = function() {} // Should override
	this.onReturn = function() {} // Should override
	
	this.open = function(page) {
		var width;
		
		divBlanket().style.width = "100%";
		divBlanket().style.height = Sizes.totalHeight()+"px";
		
		framePopup().src = page;
		//width = Sizes.clientWidth() / 2;
		width = 640;
		framePopup().style.width = width + "px";
		framePopup().style.left = ((Sizes.clientWidth() - width) / 2) + "px";
		framePopup().style.height = (Sizes.clientHeight() / 1.3) + "px";
		framePopup().style.top = (Sizes.clientHeight() / 9) + "px";
		
		var fade = new nFader();
		Utils.setDisplay(divBlanket(), true);
		fade.fadeIn(framePopup());
	}
	
	this.close = function() {
		$(divBlanket()).hide();
		var fade = nFader();
		fade.fadeOut(framePopup());
		this.onClose();
	}
	
	function nFader() {
		var cFader = new Fader();
		cFader.speed = 0.1;
		return cFader;
	}
}

