/**
 * Print the selected jQuery elements by adding them to a popup window (with the parent window's styles)
 * and then printing that window.
 * @author Eric Poggel
 *
 * @example
 * <a href="javascript:void(0)" onclick="return $('#popUp').print()">print</a>
 *
 * TODO: Test printing with multiple elements */
jQuery.extend(jQuery.fn, {
	print: function() {
	
	    var win = window.open();
	    self.focus();
	    win.document.open();
	    win.document.write('<html><head>');
	    
	    // Add stylesheets.
	    // Does not yet support embeded stylesheets.
	    var links=self.document.getElementsByTagName('link'); 
		for(var i=0;i<links.length;i++) 
			if(links[i].rel.toLowerCase()=='stylesheet') 
				win.document.write('<link type="text/css" rel="stylesheet" href="'+links[i].href+'"></link>');
	    
	    win.document.write('</head><body>');
	    win.document.write('<div id="'+$(this).attr('id')+'" class="'+$(this).attr('class')+'">'+$(this).html()+'</div>'); 
	    win.document.write('</body></html>');
	    win.document.close();
	    win.print();
	    win.close();
	    
	    return false;
	}
});