/*
 * Composicion de busqueda avanzada
 */
function objetoComposicionBusqueda(composicion,indice,tabEfectos){  
	
	this.composicion = composicion;
	this.indice = indice;
	this.idDiv = "composicion" + this.indice;
	this.idComposicion = this.composicion.get('idComposicion');
	this.codigoComposicion = this.composicion.get('codigoComposicion');
	this.compositor = this.composicion.get('compositor');
	this.idImagen = 'img'+ this.codigoComposicion;
	this.visNovedad = 'visibility:hidden';
	this.contenidoPrincipal = null;
	this.elBotonComprarObra = null;
	this.titulo = this.composicion.get('titulo');
	this.compositores = this.composicion.get('compositoresPseudonimo'); 
	this.notas = this.composicion.get('nota');
	this.logado = logado;
	this.tabEfectos = tabEfectos;
	this.textoOferta = this.composicion.get('textoOferta');
	this.duracionFicheroFormato = this.composicion.get('duracionFichero1Formato');
	this.novedad = this.composicion.get('novedad');
	this.destacado = this.composicion.get('destacado');
	this.compositores = this.composicion.get('compositoresPseudonimo');
	this.compositorPrincipal = this.composicion.get('nombreCompositorPrincipal');
	this.licenciaEfecto = this.composicion.get('licenciaEfecto');
	this.numeroEfectos = this.composicion.get('numeroEfectos');
	this.precioOfertaEfecto = this.composicion.get('precioOfertaEfecto');
	this.compositorPrincipal = this.composicion.get('nombreCompositorPrincipal');
	this.visNovedad = 'width: 0px; overflow:hidden;';
	
	this.seleccion = this.composicion.get('seleccion');
	this.carrito = this.composicion.get('carrito');
	this.duracionCarrito = this.composicion.get('duracionCarrito');
	this.licenciaCarrito = this.composicion.get('licenciaCarrito');

	if (this.textoOferta==null) {
		this.visLowcost = 'visibility:hidden';
	}else{
		this.visLowcost = '';
	}
	if (this.numeroEfectos == 1)
		this.numeroEfectos += " " + localize('efecto')
	else this.numeroEfectos += " " + localize('efectos')
	
	if (this.licenciaEfecto == 5)
		this.icono = "../img/premium.gif";
	else 
		this.icono = "../img/basic.gif";
	if (this.novedad==true){
		this.visNovedad = '';
	}
	if (this.licenciaEfecto == 5)
		this.icono = "../img/premium.gif";
	else 
		this.icono = "../img/basic.gif";
	if (this.novedad==true){
		this.visNovedad = 'width: 35px; margin-right: 20px;';
	}
	
 	this.htmlComposicion = '' +		 				
 				'<div id="{idDiv}" class="composicion">'+
 					'<div  style="width:100%;">'+
 					  '<div class="composicionc0" style="width:620px;">'+
	 					'<div class="composicionf0">'+
							'<div class="carritoc0" style="padding-top:2px;"><div><img src ={icono} width="12" height="12"/></div></div>'+
							'<div class="carritoc1" style="width: 150px;"><b>{titulo}</b></div>'+
							'<div style="width: 55px; float: left; padding-right: 10px; text-align: right;">{precioOfertaEfecto}</div>'+
							'<div class="carritoc2efectos" style="width: 230px;">{numeroEfectos}</div>'+
							'<div class="c4comprarObra"><a href="javascript:void(0)" '+ (this.carrito?'style="color: #E4103E"':'') + '><span style="position:relative;top:1px;"><img src="../img/carrito' + (this.carrito?'S':'') + '.jpg" width="16" height="13"/></span>'+localize('comprar')+'</a></div>'+
						'</div>\n'+
				 		'<div class="composicionf1">\n'+
							'<div class="carritoc0">&nbsp</div>'+
							'<div class="carritoc1" style="width: 150px;"><b>{codigoComposicion}</b></div>'+
							'<div style="width: 55px; float: left; padding-right: 10px; text-align: right;">&nbsp;</div>'+
							'<div class="carritoc2efectos" style="width: 230px;">{notas}</div>'+
							'<div class="c4selecciones"><a href="javascript:void(0)" '+ (this.seleccion?'style="color: #E4103E"':'') + '><span style="position:relative;top:1px;"><img src="../img/seleccion' + (this.seleccion?'S':'') + '.jpg" width="11" height="11"/></span> '+localize('misCarpetas')+'</a></div>'+
						'</div>'+
						'<div class="composicionf2">'+
							'<div class="carritoc0">&nbsp;</div>'+
							'<div class="carritoc1" style="width:150px;color:#dd1144;"><div style="float:left;widht:35px;{visNovedad}"><img src="../img/novedad.png" width="35" height="14"/></div><div class="lowcost"><img src="../img/lowcost.png" width="60" height="14"/></div></div>'+
							'<div class="carritoc2efectos" style="width:65px;text-align:right;margin-right:5px;"></div>' +
							'<div class="c4selecciones" style="width:165px;"></div>'+
						'</div>'+
					  '</div>'+
					'<div class="composicionc1"><a href=\'javascript:cargarObra("{compositorPrincipal}","{codigoComposicion}",1)\'>'+
					'<img src="../img/player_play_portal.png" id="{idImagen}" width="40" height="40"></a></div>'+
					'</div>'+
					'<div class="oferta">{textoOferta}</div>'
				'</div>';
	
	this.tplComposicion = new Ext.Template(this.htmlComposicion);		
	this.tplComposicion.compile();	
			
	this.booleanExpandido = false;
				
 	this.pintar = function(){					
 		
 		this.elComposicion = Ext.get('composicionBusqueda').createChild();
		var m = this.duracion1/60;
									
		// si ya existe ese div
		this.contenidoPrincipal = this.tplComposicion.append(this.elComposicion , {
			idDiv: this.idDiv,
			numeroEfectos:this.numeroEfectos,
			icono:this.icono,
		    titulo: this.titulo,
		    numeroEfectos:this.numeroEfectos,		    
		    codigoComposicion:this.codigoComposicion,
			notas:this.notas,
			textoOferta:this.textoOferta,
			precioOfertaEfecto:this.precioOfertaEfecto,
			visNovedad:this.visNovedad
		});
		
		this.elContenidoPrincipal = Ext.get(this.contenidoPrincipal);
		this.elComposicion.addClass('composicionpadre');
		var padre = this;
		
		// obra a carrito
		this.botonComprarObra = this.elContenidoPrincipal.select('div.c4comprarObra').elements[0];
		this.elBotonComprarObra = Ext.get(this.botonComprarObra);		
		this.elBotonComprarObra.on('click',function(){
			padre.addCarrito(this);
		});
		
		// obra a mis selecciones
		this.botonSelecciones = this.elContenidoPrincipal.select('div.c4selecciones').elements[0];
		this.elBotonSelecciones = Ext.get(this.botonSelecciones);		
		this.elBotonSelecciones.on('click',function(){
			padre.misSelecciones();
			if (logado) {
				this.dom.getElementsByTagName("img")[0].src = '../img/seleccionS.jpg';
				this.dom.firstChild.style.color = "#E4103E";
			}
		});
		
		
	}
		   				    	
	this.addCarrito = function(capaCarrito){
		this.tabEfectos.addCarrito(this.idComposicion,this.licenciaEfecto,capaCarrito);				
	}
	
	this.misSelecciones = function(){
		if(this.logado==true){
			this.tabEfectos.addMisSelecciones(this.idComposicion,"titulo");
		}else{
			Ext.MessageBox.alert(localize("addlibrary"), localize("soloRegist"));
		}	
	}
				
}

/**
 * 	Componente Check
 */	
function checkComposicion(elemento,duracion){
	this.elemento = elemento;
	this.estado = "off";;
	this.duracion = duracion;
	this.check2 = null;
	this.check3 = null;
	
	this.init = function(){
		if(this.duracion==null){
			this.inutilizar();
		}else{
			var padre = this;
			this.elemento.on('click',function(){
				padre.clickado();
			});
		}
	}
	
	this.activar = function(){
		this.estado="on";
		this.elemento.dom.src = "../img/radioOn.gif";
		
		// desactivamos los checks afines
		if(this.check2!=null){
			this.check2.desactivar();
		}
		if(this.check3!=null){
			this.check3.desactivar();
		}
	}
	this.desactivar = function(){
		if(this.estado!="disable"){
			this.estado="off";
			this.elemento.dom.src = "../img/radioOff.gif";
		}
	}
	this.inutilizar = function(){
		this.estado="disable";
		this.elemento.dom.src = "../img/guion.jpg";
	}
	this.clickado = function (){
		if(this.estado=="on"){
			this.desactivar();
		}else{
			if(this.estado=="off"){
				this.activar();
			}
		}
	}
	this.setCheck2 = function (elCheck2){
		this.check2 = elCheck2;
	} 
	this.setCheck3 = function (elCheck3){
		this.check3 = elCheck3;
	} 
}
