function fileQueueError(fileObj, error_code, message) {
	try {
		var error_name = "";
		switch(error_code) {
			case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED:
				error_name = "You have attempted to queue too many files.";
			break;
		}

		if (error_name !== "") {
			alert(error_name);
			return;
		}

		switch(error_code) {
			case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
				image_name = "zerobyte.gif";
				AddError("<strong>Chyba:</strong> prázdný soubor.");
			break;
			case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
				image_name = "toobig.gif";
				AddError("<strong>Chyba:</strong> soubor je příliš velký.");
			break;
			case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
			case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
			default:
				//alert(message);
				image_name = "error.gif";
				AddError("<strong>Chyba:</strong> "+message+".");
			break;
		}

		//AddImage("images/" + image_name);

	} catch (ex) { this.debug(ex); }

}
var uploadFilesNumber = 0;
function fileDialogComplete(num_files_queued) {
	try {
		if (num_files_queued > 0) {
			uploadFilesNumber = num_files_queued;
			this.startUpload();
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadProgress(fileObj, bytesLoaded) {
	
	try {
		var percent = Math.ceil((bytesLoaded / fileObj.size) * 100);
		
		var stats = swfu.getStats();		
		var progressHtml = '';
		
		if (percent === 100) 
		{
			progressHtml = '<div class="fprog-imgnum">' + (uploadFilesNumber - stats.files_queued + 1) + '/' + uploadFilesNumber + '</div><div class="fprog-message">Generuji náhled fotky ' + fileObj.name + '…</div>';
			
		} 
		else 
		{
			progressHtml = '<div class="fprog-imgnum">' + (uploadFilesNumber - stats.files_queued + 1) + '/' + uploadFilesNumber + '</div><div class="fprog-message">Nahrávám fotku ' + fileObj.name + '…</div>';
		}
		$('#divFileProgressContainer').html(progressHtml);
		
	} catch (ex) { this.debug(ex); }
}

function uploadSuccess(fileObj, server_data) {
	try {
		// upload.php returns the thumbnail id in the server_data, use that to retrieve the thumbnail for display

		AddImage(server_data, null, null, fileObj);

		$('#divFileProgressContainer .fprog-message').html('Náhled vytvořen');


	} catch (ex) { this.debug(ex); }
}

function uploadComplete(fileObj) {
	try {
		/*  I want the next upload to continue automatically so I'll call startUpload here */
		if (this.getStats().files_queued > 0) {
			this.startUpload();
		} else {
			$('#divFileProgressContainer .fprog-message').html('Všechny obrázky nahrány');
			$('#divFileProgressContainer').addClass('done');
		}
	} catch (ex) { this.debug(ex); }
}

function uploadError(fileObj, error_code, message) {
	var image_name =  "error.gif";
	try {
		switch(error_code) {
			case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
				try {
				/*
					var progress = new FileProgress(fileObj,  this.customSettings.upload_target);
					progress.SetCancelled();
					progress.SetStatus("Stopped");
					progress.ToggleCancel(true, this, fileObj.id);
				*/
				}
				catch (ex) { this.debug(ex); }
			case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
				image_name = "uploadlimit.gif";
				AddError("<strong>Chyba:</strong> upload limit exceeded.");
			break;
			default:
				alert(message);
			break;
		}

		//AddImage("images/" + image_name);

	} catch (ex) { this.debug(ex); }

}

function AddImage(filehash,title,description,fileObj)
{
	if(title==null){
		title='';
	};
	if(description==null){
		description='';
	};

	$('#thumbnails').append('<li><img src="./photos/temp/thmb_'+filehash+'" alt="'+filehash+'" width="227" height="170" /><p><small>Titulek</small>: <input type="text" name="titles[]" value="'+title+'" class="inp-text w-full" /> <input type="hidden" name="ids[]" value="'+filehash+'" /><br />' + fileObj.name + '</p><a href="#" onclick="javascript: $(this).parents(\'li\').eq(0).remove();return false;" class="btn-delete" title="Odstranit tento obrázek"><img src="./img/btn-delete.png" alt="X" width="21" height="21" /></a><div class="break"></div></li>');
	
}

function RemoveImage(li_object) {
	
}

function AddError(text){
	$('#thumbnails').append('<div style="margin: 6px;">'+text+'</div>');
}

