Shadowbox.init();

$(document).ready(function() {
    	   
   // AJAX PARA SUBIR LAS FOTOS
    $(function(){
		var btnUpload=$('#upload');
		var status=$('#status');
		new AjaxUpload(btnUpload, {
			action: 'http://aglomsa.net/file/upload',
			//Name of the file input box
			name: 'uploadfile',
			onSubmit: function(file, ext){
				ext = ext.toLowerCase();
				if (! (ext && /^(gif|jpg|png|doc|pdf|zip|rar)$/.test(ext))){
	                  // check for valid file extension
					status.text('El archivo seleccionado no es gif|jpg|png|doc|pdf|zip|rar');

					return false;
				}
				status.text('Subiendo...');
				$('#upload').attr('style', 'display:none;');
			},
			onComplete: function(file, response){
				//On completion clear the status
				status.text('');
				//Add uploaded file to list
				if(response!=""){
					$('.nofiles').remove();
					$('tbody').append(html_entity_decode(response));
				} else {
					//$('<li></li>').appendTo('#files').text(file).addClass('error');
					//$('<li></li>').appendTo('tbody').html('No se pudo subir el archivo '+file).addClass('error');	
					status.text(response+'No se pudo subir el archivo '+file);
				}
				$('#upload').attr('style', '');
			}
		});
	});	
	
	function html_entity_decode(str) {
	  var ta=document.createElement("textarea");
	  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
	  return ta.value;
	}
});
