﻿// -----------------------------------------------------------------------
// eros@recoding.it
// jqprint 0.3
//
// - 19/06/2009 - some new implementations, added Opera support
// - 11/05/2009 - first sketch
//
// Printing plug-in for jQuery, evolution of jPrintArea: http://plugins.jquery.com/project/jPrintArea
// requires jQuery 1.3.x
//------------------------------------------------------------------------

(function($) {
    var opt;

    $.fn.jqprint = function (options) {
        var element = (this instanceof jQuery) ? this : $(this);
        
	var iframe = $("#iframe-print");
	
	if (iframe.length == 0) {
	    var iframe = $("<iframe id='iframe-print' />");
	}
	   iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" });
	
	    iframe.appendTo("body");
	    var doc = iframe[0].contentWindow.document;
        
	$("link").each( function() {
		if ($(this).attr("type") == "text/css") {
			if ($(this).attr("media") == "print") {
				doc.write("<link type='text/css' rel='stylesheet' media='print' href='" + $(this).attr("href") + "' />");
			} else {
				doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' />");
			}
		}
	});
	
	doc.write(element.html());
        
        doc.close();
        
	//iframe.contents().find("#zoopy-video").remove();
	
        iframe[0].contentWindow.focus();
        setTimeout( function() { iframe[0].contentWindow.print(); }, 1000);
    }
})(jQuery);