/* Licuit Interactive SL */
/* main.css */
/* Created June, 2009 */
/* Modified June, 2009
--------------------------------------- */

LicuitCore.FlashUploads = new Class({
        Extends: LicuitCore.licuit,
		
		flashUploaders:null,
		
		initialize: function(){
			this.flashUploaders = [];
        },
		
		addFlashToDiv : function(id,variables){
			if(this.getUploaderFromDiv(id) != undefined)
				return;
			
			var objFlash = {};
			objFlash.id = id;
			objFlash.variables = variables;
			objFlash.flash = this.createFlashUploader(objFlash.id,objFlash.variables);
				
			this.flashUploaders.push(objFlash);		
		},
		
		createFlashUploader : function(divId,variables){
			var tClass = this;
			var obj = new Swiff('/resources/swf/upload.swf', {
			    id: "flash_" + divId,
			    width: 290,
			    height: 20,
			container : divId,
			    params: {
			        wmode: 'transparent',
					scale: "noscale",
					bgcolor: "#EEEEEE"
			    },
			    vars: {
			      	urlupload : variables.urlupload,
					nombre : tClass.replaceFileName(variables.nombre), //timenowany hace que puedas subir cualquier fichero y se añada la hora al nombre.
					carpeta : variables.carpeta,
					filetype : (variables.filetype != undefined) ? variables.filetype : "Imagenes",
					extensions : (variables.extensions != undefined) ? variables.extensions : "*.png; *.jpg; *.jpeg; *.gif",
					oncomplete : (variables.oncomplete != undefined) ? variables.oncomplete : function(){alert("archivosSubido");},
					cftoken : variables.cftoken,
					cfid : variables.cfid
			    }
			});
			
			return obj;
		},
		
		resetFlashOnDiv : function(id){
			var objFlash = this.getUploaderFromDiv(id);
			
			if(objFlash == undefined)
				return;
			
			objFlash.flash.toElement().parentNode.empty();
			objFlash.flash = this.createFlashUploader(objFlash.id,objFlash.variables);			
		},
		
		getUploaderFromDiv : function(id){
			var objFlash;
			
			for(var a = 0; a < this.flashUploaders.length; a++){
				if(this.flashUploaders[a].id == id){
					objFlash = this.flashUploaders[a];
					break;
				}
			}
			
			return objFlash;
		},
		
		replaceFileName : function(nombre){
			var timenow = String(new Date().getTime()) + String(Math.round((Math.random() * 10000)));
			nombre = nombre.split("{timenow}").join(timenow);
			return nombre;
		}
});


