/**
*  jquery.layer.popup.js
*     Layer popup Print
*
*  Author : yang
*/

(function($) {

		$.fn.layerPopup = function( el , options) {

			var layer = $(el);
			var popupStatus = 0;
			var closebtn;

			var opts = $.extend({}, $.fn.layerPopup.defaults, options);

			//options
			if(opts.center) {
				opts.left = document.documentElement.clientWidth/2  - layer.width()/2;
				opts.top  = document.documentElement.clientHeight/2 - layer.height()/2;
			}

			if(!el) layer = $(opts.name);

			this.click(loadPopup);

			var closeBtn = $(opts.closeButton);
			if(closeBtn) closeBtn.bind("click" , disablePopup);

			$(document).keypress(function(e){
				if(e.keyCode==27 && popupStatus==1) disablePopup();
			});

			function disablePopup(){
				if(popupStatus==1){
					layer.fadeOut("fast");
					popupStatus = 0;
				}
			}

			function loadPopup(){
					if(popupStatus==0){
						layer.css({
							"opacity": "1" ,
							"position": "absolute",
							"top": opts.top ,
							"left": opts.left

						});
						layer.fadeIn("fast");
						popupStatus = 1;
					}
			}

		};

		$.fn.layerPopup.defaults = {
				name  : '#popup' ,
				closeButton : '#close' ,
				center : true ,
				width : '900px' ,
				height: '600px' ,
				left  : '0px' ,
				top   : '0px'
			};

})(jQuery);


