(function($) 
   {
      $.fn.popup = function (content)
      {				
  			 var B = $("body").eq(0);
				 var P = this;				 
				 
		this.popupHolder = $("<div>").addClass("popupHolder").fullScreen();
         this.popupWindow = $("<div>").addClass("popupWindow").appendTo(this.popupHolder);
         this.popupLogo = $("<div>").addClass("popupLogo").appendTo(this.popupWindow);
         this.popupClose = $("<div>").addClass("popupClose").appendTo(this.popupWindow);
         this.popupContent = $("<div>").addClass("popupContent").appendTo(this.popupWindow);
				 
         this.onKeyUp = function(e) {
            if (e.keyCode == 27) P.hidePopup();
         };		
				 
         this.showPopup = function (e) 
         { 
            e.preventDefault();
            e.stopPropagation();		
						$(document).bind('keyup',P.onKeyUp);
            P.popupContent.html( $(this).attr("content") || $("#"+ $(this).attr("content_id")).html() || content);            
            P.popupHolder.appendTo(B.css({overflow:"hidden"})); 
            P.popupWindow.hide().center().show('fast').center();
         };
                           
         this.hidePopup = function (e) 
         { 
            if (e) {
							e.preventDefault();
	            e.stopPropagation();
						}
						$(document).unbind('keyup',P.onKeyUp);
            P.popupHolder.detach();
            P.popupContent.html("");
            B.css({overflow:"auto"});
         };
         
         this.lock = function (e){ 
           //e.preventDefault();
            e.stopPropagation();
         };
        
				 this.popupHolder.click(this.hidePopup);
         this.popupWindow.click(this.lock);
         this.popupClose.click(this.hidePopup);

         $(this).click(this.showPopup);
				 
				 return this;
      }
   }(WP.$));
   
   WP.$(function($) 
	{
	if ( $().popup ) popups = $("#openPopup").popup();
	});

