// Control Clase de ejecución de archivos ShockWave Flash
// (c)2006 The Mad Pixel Factory --- http://www.madpixel.es

obj_swf=function(){
	this.salida_div=false
	this.trace=false
	this.codificarFlashVars=false
}
obj_swf.prototype.FNtrace=function(){
	this.trace=true
	return true
}
obj_swf.prototype.FNcodificarFlashVars=function(){
	this.codificarFlashVars=true
	return true
}
obj_swf.prototype.FNid_salida=function(p_id_salida){
	if(typeof(p_id_salida)!="undefined"){
		if(document.getElementById(p_id_salida)){
			this.salida_div=true
			this.obj_div=document.getElementById(p_id_salida)
		}
	}
}
obj_swf.prototype.FNborrar=function(){
	delete this
}
obj_swf.prototype.FNgfx_swf=function(){
	//Comprueba parametros básicos
	if(typeof(this.classid)=='undefined'){this.classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'}
	if(typeof(this.codebase)=='undefined'){this.codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'}
	if(typeof(this.quality)=='undefined'){this.quality='high'}
	if(typeof(this.type)=='undefined'){this.type='application/x-shockwave-flash'}
	if(typeof(this.pluginspage)=='undefined'){this.pluginspage='http://www.macromedia.com/go/getflashplayer'}
	if(typeof(this.swliveconnect)=='undefined'){this.swliveconnect="true"}
	if(typeof(this.allowscriptaccess)=='undefined'){this.allowscriptaccess="true"}
	if(typeof(this.id)=='undefined'){var nId=Math.round(Math.random()*100);this.id='swf'+nId}
	//--
	//Crea arrays de contenido
	this.a_object_propios=new Array()
	this.a_comunes=new Array()
	this.a_object_variables=new Array()
	this.a_embed_propios=new Array()
	this.a_embed_variables=new Array()
	//--
	
	//Revisa contenido adquirido
	for(parametros in this){
		var cNomParametro=parametros.toLowerCase()
		var cValorParametro=eval("this."+parametros)
		if(typeof(cValorParametro)=="string"){
			switch (cNomParametro){
				case "classid":
				case "codebase":
				case "onafterupdate":
				case "onbeforeupdate":
				case "onblur":
				case "oncellchange":
				case "onclick":
				case "ondblClick":
				case "ondrag":
				case "ondragend":
				case "ondragenter":
				case "ondragleave":
				case "ondragover":
				case "ondrop":
				case "onfinish":
				case "onfocus":
				case "onhelp":
				case "onmousedown":
				case "onmouseup":
				case "onmouseover":
				case "onmousemove":
				case "onmouseout":
				case "onkeypress":
				case "onkeydown":
				case "onkeyup":
				case "onload":
				case "onlosecapture":
				case "onpropertychange":
				case "onreadystatechange":
				case "onrowsdelete":
				case "onrowenter":
				case "onrowexit":
				case "onrowsinserted":
				case "onstart":
				case "onscroll":
				case "onbeforeeditfocus":
				case "onactivate":
				case "onbeforedeactivate":
				case "ondeactivate":
				case "type":
					this.a_object_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
				case "width":
				case "height":
				case "align":
					this.a_comunes.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
				case "type":
				case "pluginspage":
				case "allowscriptaccess":
				case "width":
				case "height":
				case "align":
				case "vspace": 
				case "hspace":
				case "class":
				case "title":
				case "accesskey":
				case "swliveconnect":
				case "tabindex":
					this.a_embed_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
				case "id":
					this.a_object_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					this.a_embed_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					this.a_embed_propios.push('name'+'="'+cValorParametro+'"' )
					break;
				case "movie":
					this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
					this.a_embed_propios.push('src'+'="'+cValorParametro+'"' )
					break;
				case "flashvars":
					//Revision el contenido de FlashVars para evitar problemas de comillas y caracteres especiales
					if(cValorParametro.indexOf('"')!=-1 || cValorParametro.indexOf("'")!=-1 || this.codificarFlashVars){
						cValorParametro=escape(cValorParametro)
					}
					this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
					this.a_embed_variables.push( cNomParametro+'="'+cValorParametro+'"' )
					//--
					break;
				default :
					this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
					this.a_embed_variables.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
	
			}
		}
	}
	//--
	
	this.a_object_propios=this.a_object_propios.join(" ")
	this.a_comunes=this.a_comunes.join(" ")
	this.a_embed_propios=this.a_embed_propios.join(" ")
	this.a_object_variables=this.a_object_variables.join("\n")
	this.a_embed_variables=this.a_embed_variables.join(" ")
	
	
	//Genera salida
	cad=''
	cad+=('<object '+this.a_object_propios+' '+this.a_comunes+' >'+'\n')
	cad+=(''+this.a_object_variables +'\n')
	cad+=('<embed '+this.a_embed_propios+' '+this.a_comunes+' '+this.a_embed_variables+'></embed>'+'\n')
	cad+=('</object>'+'\n')
	
	if(this.salida_div){
		this.obj_div.innerHTML=cad //Salida a etiqueta ID
	}else{
		document.write(cad) //Escritura directa sobre HTML
	}
	//--
	
	if(this.trace){alert(cad)}
	
}
