
// ************************************* PRINT ****************************************** //
//																						  //
// This function associates every 'print' link an event handler that prints the content	  //
// associated woth that 'print' link.The connection between the 'print' link and the print//
// content is don eby the oder they are displayed in the page.							  //
//																						  //
//	(!) Every 'print' link must have an "name='printButton'" name						  //																				 
//	(!) Every print content must be enclosed between "<div name="printContent">...</div>" //
//																						  //
// ************************************************************************************** //

(
	function(){
		
		$(document).ready(
	
			function(){
				
				//GET ALL PRINT ICONS LINKS
				var printIconsObjects = $('a[name=printButton]');
				
				//GET ALL CONTENTS TO BE PRINTED
				var printContentObjects = $('div[name=printContent]');
				
				// ****************** BUILD PRINT CONTENTS ARRAY *************** //

				var printContentArray = [];
				$.each(printContentObjects,addToContentArray);
				
				function addToContentArray(index, value){
					
					printContentArray[index] = $(value).html();
				}
				
				// ******************* ADD EVENT HANDLERS *********************** //
				
				$.each(printIconsObjects,printContent);
				
				function printContent(index, value){
					
					$(value).click(
					
						function(){
							
							var printContent = printContentArray[index];
							var newPage = window.open();
							var style = '<link rel="stylesheet" href="http://www.aplcp.org/includes/styles/style.css" type="text/css" />'
							
							newPage.document.write(style+printContent);
							newPage.document.close();
							newPage.print();
							
						}
					
					);
					
				}
				
				// ************************************************************** //
				
			}

		)
	}
)();


