// JQuery plugin that prints overlay image
jQuery.fn.print = function(collection, image1Path, image2Path, description){
 
	// Create a random name for the print frame.
	var strFrameName = ("printer-" + (new Date()).getTime());
 
	// Create an iFrame with the new name.
	var jFrame = $( "<iframe name='" + strFrameName + "'>" );
 
	// Hide the frame (sort of) and attach to the body.
	jFrame.css( "width", "1px" ).css( "height", "1px" ).css( "position", "absolute" ).css( "left", "-9999px" ).appendTo( $( "body:first" ) );
   
  // Get a FRAMES reference to the new frame.
	var objFrame = window.frames[ strFrameName ];
 
	// Get a reference to the DOM in the new frame.
  var objDoc = objFrame.document;
  
  var imagePath = '<table width="100%" border="0" cellspacing="0" cellpadding="5"><tr><td width="50%"><div align="center"><img src=' + image1Path + ' width="100%"/></div></td>';
  
  if (image2Path != undefined)
      imagePath = imagePath + '<td width="50%"><div align="center"><img src=' + image2Path + ' width="100%"/></div></td>';
  
  imagePath = imagePath + "</tr></table>";  
  
  //alert('print test');
  
	// Write the HTML for the document. 
	objDoc.open();
	objDoc.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
	objDoc.write("<html>");
	objDoc.write("<body>");
	objDoc.write("<head>");
	objDoc.write("<title>");
	objDoc.write(collection);
	objDoc.write("</title>");
	//objDoc.write('<link rel="stylesheet" href="css/print.css" type="text/css" />');
	objDoc.write("</head>");	
	objDoc.write('<br><br><br><br><h1 align="center">' + collection + '</h1>');
	objDoc.write(imagePath);
	objDoc.write('<div align="center">' + description + '</div>');
	objDoc.write("</body>");
	objDoc.write("</html>");
	objDoc.close();
 
  var printed = false;
  var statusOfPrint = 'Processing print job... Please wait.';
  
  var strBrowser; 

  if ((i = navigator.userAgent.indexOf("Opera")) >= 0)
    strBrowser = "Opera";
  else if ((i = navigator.userAgent.indexOf("Netscape6/")) >= 0)
    strBrowser = "Netscape6/";
  else if ((i = navigator.userAgent.indexOf("Gecko")) >= 0)
    strBrowser = "Gecko";
  else if ((i = navigator.userAgent.indexOf("MSIE")))
    strBrowser = "MSIE";  
 
 
  if (strBrowser != "MSIE") {
      window.frames[strFrameName].focus(); 
      window.frames[strFrameName].print();  
  } else {
    // Check to make sure that style image is completely loaded before printing. 
    objDoc.onreadystatechange = function() {   
      if (objDoc.readyState == 'complete') {
        objFrame.focus();
    	  objFrame.print();
    	  printed = true;
    	  statusOfPrint = 'Processing print job... Please wait.';
      } else
        statusOfPrint = 'Loading images... Please wait for the print dialog window.';
    }
  }
  
  // Print the style image when objDoc is cached by browser, and user continues
  //    to click on "Print" to print more than one copy of the SAME style image.
  if (!printed & (objDoc.readyState == 'complete')) { 
    objFrame.focus();
  	objFrame.print(); 
  } 
 
  // Have the frame remove itself in about a minute so that
	// we don't build up too many of these frames.
	setTimeout(
		function(){
			jFrame.remove();
		},
		(60 * 1000)
		);
		
		return statusOfPrint;
  }





