$(document).ready(function() {
	var button = $("#form-data-upload");
	var upload =
		new AjaxUpload(button,{
			action: 'utils/upload', 
			//name: 'myfile',
			onSubmit : function(file, ext){
				$("#file-upload-method").val('(UPLOAD)');
				$("#uploading").fadeIn('fast');
				// change button text, when user selects file			
				/*button.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload button
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = button.text();
					if (text.length < 13){
						button.text(text + '.');					
					} else {
						button.text('Čekejte, prosím ');				
					}
				}, 200);*/
			},
		  	onComplete: function(file,response){
				if (response == 'success') {
				//	button.text('Nahrát další soubor');
				//	window.clearInterval(interval);

					//alert('Soubor byl uložen na server.');				
					// add file to the list
					//$("#uploading").fadeOut('fast');
					$('<li></li>').appendTo('.files').html('<strong>' + file + '</strong>');
					
					if($("#file-uploaded").val() == 0) {
						$('.files li:first').remove();
					}
					$(".uploaded-files").show();
					
					$("#file-uploaded").val(1);

					$("#mail-info").hide();
					$("#person-info").hide();
					$("#ftp-info").hide();
					$("#upload-note td.label").text('Poznámka k souborům');
					$("#file-upload-method").attr({checked : 'checked'});
					$("#data-error-input").hide();
				}
				else {
				//	window.clearInterval(interval);
				//	button.text('Nahrát soubor');
					
					$("#uploading").fadeOut('fast');
					alert(response + ' Vyskytla se chyba při nahrávní souboru. Zkontrolujte velikost Vašeho souboru a zkuste to znovu nebo později.');
					
				}
				$("#uploading").fadeOut('fast');
				this.enable();			  			
			} 
		});
		
/*		new AjaxUpload('upload_button',{
			action: 'utils/upload',
		  	onComplete: function(file,response){
				if (response == 'success') {
					//alert('Soubor byl uložen na server.');				
					// add file to the list
					$('<li></li>').appendTo('.files').text(file);
					$(".uploaded-files").show();
					
				}
				else 
					alert('Vyskytla se chyba při nahrávní souboru. Zkuste to znovu nebo později.');
				
				this.enable();			  			
			} 
		}
	);*/
});		
