(function( $ ){
  $.fn.printPage = function(options) {
    var pluginOptions = {
      attr : "href",
      url : false,
      message: "Please wait while we create your document" 
    };
    $.extend(pluginOptions, options);

    this.live("click", function(){  loadPrintDocument(this, pluginOptions); return false;  });
   
    function loadPrintDocument(el, pluginOptions){
      $("body").append(components.messageBox(pluginOptions.message));
       $("#printMessageBox").css("opacity", 0);
        $("#printMessageBox").animate({opacity:1}, 300, function() { 
	  	 unloadMessage();
		});
      
    }
    
    function unloadMessage(){
      $("#printMessageBox").delay(1000).animate({opacity:0}, 700, function(){
		$(this).remove();
		window.print();
	  });
    }
    
    var components = {
      iframe: function(url){
        return '<iframe id="printPage" name="printPage" src="'+url+'" style="position:absolute;top:0px;left:0px;width:0px;height:0px;border:0px;overflow:none;z-index:999"></iframe>';
      },
      messageBox: function(message){
        return "<div id='printMessageBox' style='\
          position:fixed;\
          top:50%; left:50%;\
          text-align:center;\
          margin: -60px 0 0 -155px;\
          width:310px; height:120px; font-size:16px; padding:10px; color:#222; font-family:helvetica, arial;\
          opacity:1;\
		  filter:alpha(opacity=100);\
		  z-index:999;\
          background:#fff url(http://www.mdcoastdispatch.com/images/print_icon.gif) center 40px no-repeat;\
          border: 6px solid #555;\
          border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px;\
          box-shadow:0px 0px 10px #888; -webkit-box-shadow:0px 0px 10px #888; -moz-box-shadow:0px 0px 10px #888'>\
          "+message+"</div>";
      }
    }
  };  
})( jQuery );
