/*
 * selectAndPrint
 *
 * Copyright (c) 2010 Jonathan Schisler
 *
 * Revision: 1
 * Version: 0.1.2
*/
(function($){
$(document).ready(function($) {
   $(".selectAndPrintForm").each(function() {
   
      $(this).attr('target', '_blank');

      $(this).submit(function() {
         var textArray = [];
	 $(this).find(".selectAndPrint_checkbox:checked").each(function() {
	    var textID = $(this).attr("id").replace("_cb_", "_pt_");
	    //var temp = $(this).closest(".selectAndPrintForm");
	    var temp = $(this).closest("table");
	    var textIDapp = "#" + textID;
	    textArray.push(temp.find(textIDapp).html());
	 });
	 var entryTitle = $(this).closest('.post').find(".entry-title").text();
	 var entryPubDate = $(this).closest('.post').find(".published").text();
	 
	 var test = $(this).find("#entryTitle").length;
	 
	 if(test==0) {
	    $(this).append("<input type='hidden' name='entryTitle' id='entryTitle'/>");
	    $(this).append("<input type='hidden' name='entryPubDate' id='entryPubDate'/>");
	    $(this).append("<input type='hidden' name='toPrint' id='toPrint'/>");
	 }
	 
	 $("input[id='entryTitle']").setValue(entryTitle);
	 $("input[id='entryPubDate']").setValue(entryPubDate);
	 $("input[id='toPrint']").setValue(textArray.join("<br/><br/>"));
                  
	 return true;
      });
   });
   
   $(".selectAndPrintFormSubmit").each(function() {   
   	//$(this).attr('disabled', '');
   	$(this).removeAttr("disabled");
   });
   
   
   //$(".selectAndPrint_checkbox").each(function() {
   //   $(this).click(function() {
   //      //event.preventDefault();
   //
   //      $(this).closest('table').find('.selectAndPrint_printText').find('a').animate({
   //         left: '+=25'
   //         },
   //         500,
   //         function() {
   //            // Animation complete. start next
   //            $(this).animate({
   //               left: '-=25'
   //               },
   //               500,
   //               function() {
   //                  $(this).css("color", 'CCCCCC');
   //               }
   //            );
   //         }
   //      );
   //   });   
   //});
   
});
})(jQuery);	
