jQuery(document).ready(function(){
   packinglist.init();

});
var packinglist = function() {
	var $j = jQuery;
	var newWindow = null;
	return {
		init : function() {
			$j('.list_properties').bind('click', function() {
				var divname = 'span[name="div' + $j(this).attr("id") + '"]';
				if($j(this).attr("checked")) {
					$j(divname).prependTo($j("#categories")); 
				} else {
					$j(divname).appendTo($j("#hidden")); 
				}
			});
			
			$j('#addEmail').bind('click', function() {
				var number = $j('#emailList ul').size();
				if(number == 5) {
					$j(this).remove();
				}
				$j('#emailList').append('<li><ul><li><label for="toName'+number+'">Naam ontvanger:</label><input name="emails['+number+'][name]" id="toName'+number+'"/></li><li><label for="toAddress'+number+'">E-mail adres ontvanger:</label><input name="emails['+number+'][email]" id="toAddress'+number+'"/></li></ul></li>'); 
					
				return false;
			});
			
			$j('.printlist').bind('click', function() {
				if(newWindow && ! newWindow.closed)	{
					newWindow.close();
				}
				newWindow = window.open('', 'newWindow', 'status=1,scrollbars=1,width=650,height=700"');
				newWindow.document.write('<html><head><style>body { color : #000000; background : #ffffff; font-family : "Times New Roman", Times, serif; font-size : 12pt; width: 600px;}</style><head><body><b>Uw vakantie checklist:</b><br/>' + $j('#categories').html() + '</body></html>');
				$j('INPUT[type="checkbox"]').each( function() {
					$j('#' + $j(this).attr('id'), newWindow.document).attr("checked",$j(this).attr("checked"));
				});
				newWindow.document.close();
				newWindow.print();
			});
			
			$j('.savelist').bind('click', function(){
				var style =  '<link href="/wp-content/plugins/packing-list/style.css" rel="stylesheet" type="text/css"><link href="/wp-content/plugins/packing-list/print.css" rel="stylesheet" type="text/css" media="print">';
				if(newWindow && ! newWindow.closed)	{
					newWindow.close();
				}
				
				newWindow = window.open('', 'newWindow', 'status=1,toolbar=1,scrollbars=1,width=650,height=700"');
				newWindow.document.write(style + '<div style="width: 650px; color:#333333;font-family:arial,helvetica,sans-serif;font-size:13px;"><b>Uw vakantie checklist:</b>' + $j('#categories').html() + '</div>');
				$j('INPUT[type="checkbox"]').each( function() {
					$j('#' + $j(this).attr('id'), newWindow.document).attr("checked",$j(this).attr("checked"));
				});
				newWindow.document.close();
				if (document.execCommand){
					newWindow.document.execCommand("SaveAs");
				}else{
					alert('Feature available only in Internet Exlorer 4.0 and later.');
				}
			});
		}
	}
}();