function fileQueueError(file, errorCode, message)
{
	try {
		var imageName = "error.gif";

		switch (errorCode) {
		case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
			alert('Több képet választottál a megengedettnél! Jelenleg ' + message + ' db képet tölthetsz fel!');
		    break;
		case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
			add('Túl nagyméretű állomány!', file.name, 'error');
			break;
		case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
			add('0 byte-os állomány!', file.name, 'error');
			break;
		default:
			alert(message);
			break;
		}
	} catch (ex) {
		this.debug(ex);
	}

}

function fileDialogComplete(numFilesSelected, numFilesQueued) {
	try {
		if (numFilesQueued > 0) {
			this.startUpload();
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadStart(file)
{
	$("#progress").attr('style', 'display:block');
}
function uploadProgress(file, bytesLoaded)
{
	try {
		var percent = Math.ceil((bytesLoaded / file.size) * 100);

		var status;
		if (percent === 100) {
		    $("#progress p.bar").attr('style', 'width:0');
		    status = 'Bélyegkép létrehozása... <imf src="http://assets.kepguru.hu/img/loader.gif"/>';
		} else {
		    status = '"' + file.name + '" feltöltése...' + percent + '%';
			$("#progress p.bar").attr('style', 'width:' + (Math.ceil($("#progress p.info").width() / 100 * percent)) + 'px');
		}
		$("#progress p.info").html(status);
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadSuccess(file, serverData)
{
	try {
		$("#progress").attr('style', 'display:none');
		if (serverData.substring(0, 3) === "id:") {
			$("#progress p.info").html('Feltöltés...');
			$("#progress p.bar").attr('style', 'width:0');
			add(serverData.substring(3), file.name, 'img');
			var limit = $("#imagesCount").html() - 1;
			if (limit == 0) {
			    $("#upload .enabled").attr('style', 'display:none');
			    $("#upload .disabled").attr('style', 'display:block');
			    limit = 1;
			} else {
				$("#imagesCount").html(limit);
			}
			swfu.setFileQueueLimit(limit);
		} else {
			if (serverData.substring(0, 5) === 'error') {
   				add(serverData.substring(6), file.name, 'error');
			} else {
   				add('Hiba!', file.name, 'error');
			}
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadComplete(file) {
	try {
		if (this.getStats().files_queued > 0) {
			this.startUpload();
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadError(file, errorCode, message)
{
	var imageName =  "error.gif";
	try {
		switch (errorCode) {
		case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
			imageName = "uploadlimit.gif";
			break;
		default:
			alert(message);
			break;
		}
		alert(message + imageName);

	} catch (ex3) {
		this.debug(ex3);
	}

}


function add(item, data, type)
{
	if (type == 'img') {
	    item = '<img src="' + item + '"/>';
	} else if (type == 'error') {
	    item = '<p class="error invalid">' + item + '</p>';
	}
	$('#progress').before('<div class="item">' + item + '<h5>' + data + '</h5></div>');
}
