$(document).ready(function(){
	var button = $('.text'), interval;
	new Ajax_upload('#project_template', {
		action: 'upload.php',
		name: 'project_template',
		onSubmit : function(file, ext){
			if (! (ext && /^(psd|zip|rar)$/.test(ext))){
						$(".text").addClass("error");
                        button.text('Непозволен формат');
                        return false;
                }
			$(".text").removeClass("error");
			button.text('Качване');
			this.disable();
			interval = window.setInterval(function(){
				var text = button.text();
				if (text.length < 13){
					button.text(text + '.');					
				} else {
					button.text('Качване');				
				}
			}, 200);
		},
		onComplete : function(file, response){
			button.text('Качване');
			window.clearInterval(interval);
			this.enable();
			if (response == 1)
			{
				$(".text").addClass("error");
                button.text('Непозволен файлов размер (лимит 50 MB)');		
			}
			else if (response == 2)
			{
				$(".text").addClass("error");
                button.text('Файлът не може да бъде прикачен');	
			}
			else
			{
				button.text(response);
				this.disable();
			}
		}	
	});		
});