// JavaScript Document
// @param string option

var Popup = {
	
	 init:	function(width, height)
	 {
		  if (!width || isNaN(width))  { width = 310; }
		  if (!height || isNaN(height)){ height = 200; }
		  
		  var view 		= this.getViewport();
		  var popup  	= document.getElementById ('popup');
		  var overlay 	= document.getElementById ('overlay');
		  var buttonHide 	;
		  if (!!popup && !!overlay) // if popup was created, only show it
		  { 
			   popup.innerHTML   = '';
			   popup.style.display  = 'block';
			   overlay.style.display  = 'block';
			   popup.style.width  = width + 'px';
			   popup.style.height  = height + 'px';
			   popup.style.top   = Math.round(((view.innerHeight - height)/(2 * view.innerHeight)) * 100) + '%';
			   popup.style.left  = Math.round(((view.innerWidth - width)/(2 * view.innerWidth)) * 100) + '%';
			   
			 
		  }
		  else
		  {
			   popup     = document.createElement('div');
			   overlay    = document.createElement('div');
			   popup.id   = 'popup';
			   popup.className  = 'popup';
			   overlay.id    = 'overlay';
			   overlay.className  = 'overlay';
			   overlay.onclick	= function (){ this.style.display = 'none'; popup.style.display ='none';}
			
			   popup.style.top  = Math.round(((view.innerHeight - height)/(2 * view.innerHeight)) * 100) + '%';
			   popup.style.left = Math.round(((view.innerWidth - width)/(2 * view.innerWidth)) * 100) + '%';
			   popup.style.width = width + 'px';
			   popup.style.height = height + 'px';
			
			   //overlay.onclick  = function() { this.hidePopup(); } // when click on overlay, popup whill hidden
			  /*  buttonHide 			= document.createElement('<imput type=\'button\'/>');
				buttonHide.width	= '100px';
				buttonHide.height 	= '50px';*/
				
			   document.body.appendChild(overlay);
			   document.body.appendChild(popup);
		  }
		  return popup; // oject HTML
	 },
	
	 getViewport : function  () 
	 {
		  var viewport = {};
		  if ( self.innerHeight ) 
		  {
			   viewport.pageYOffset = self.pageYOffset;
			   viewport.pageXOffset = self.pageXOffset;
			   viewport.innerHeight = self.innerHeight;
			   viewport.innerWidth  = self.innerWidth;
		  } 
		  else if ( document.documentElement && document.documentElement.clientHeight ) 
		  {
			   viewport.pageYOffset = document.documentElement.scrollTop;
			   viewport.pageXOffset = document.documentElement.scrollLeft;
			   viewport.innerHeight = document.documentElement.clientHeight;
			   viewport.innerWidth = document.documentElement.clientWidth;
		  }
		  return viewport;
	 }
}
