/* 
	SPHE JS Ficha
	© 2010 IntelyGenZ - www.intelygenz.com 
  version 0.07 [16.06.2010]
*/



function PintaBloqueCaratula(){ document.write( DrawBloqueCaratula() ) }
function DrawBloqueCaratula(){
	var sHTML = "";
	var sFechaSalida = ""+DrawDato(maProducto,'Fecha_Salida')+"";

	sHTML += "<div class='caratula'>"
	sHTML += 	DrawCaratula(sIDReferencia,maProducto,sFormato,bCaratula);
				
		if (sFechaSalida!=""){ 
			sHTML += 	"<div class='fecha'>"+sFechaSalida+"</div>"
		}
	sHTML += "</div>"
	
	return(sHTML);
}


// Pinta la Carátula de la Ficha  
// -- Referencia(sRef), Array del que lee (maDatos), 
function PintaCaratula(sRef,maDatos,sFormato,bCaratula) { document.write(DrawCaratula(sRef,maDatos,sFormato,bCaratula)) }
function DrawCaratula(sRef,maDatos,sFormato,bCaratula){
	var sHTML = "", sEXML = ""; 

	sHTML += "<IMG src='"+oIGZ.m_sRootPath+"pix/caratulas/"+sRef+".png' alt=\"<BD>Titulo</BD>\" "
	sHTML += ParseEXMLs (sEXML,"",maDatos,0) + " />"; 

	return (sHTML);
}


// Pinta el Título de una Pelicula con Campo Edición Especial y Campo Pack si existe.
function PintaTitulo(maDatosPeli,maDatosProducto,nCual) { document.write(DrawTitulo(maDatosPeli,maDatosProducto,nCual)) }
function DrawTitulo(maDatosPeli,maDatosProducto,nCual){
	var sHTML = "", sEXML = "", sEXML2 = "";
	if(nCual==null) nCual = 0;

	sEXML  += "<BD>Titulo</BD>  "
	sEXML2 += " <IF fun='\"<BD>Edicion</BD>\"!=\"\"'>[<BD>Edicion</BD>]</IF> <IF fun='\"<BD>Coleccion</BD>\"==\"Pack\"'>[<BD>Coleccion</BD>]</IF> "

	sHTML += ParseEXMLs (sEXML,"",maDatosPeli,nCual) + ParseEXMLs (sEXML2,"",maDatosProducto,nCual);

	return (sHTML);
}


function PintaDatosPeli() { document.write(DrawDatosPeli()) }
function DrawDatosPeli(){
	var sHTML = "", sEXML = "";
	var maDatosPeli = new MArray(['NombreBD','NombreHTML']
	,[
	 ['Productora','Productora']
	,['Genero','Género']
	,['','']
	,['Nacionalidad','Nacionalidad']
	,['nICAA','I.C.A.A.']
	,['','']
	,['DVD_Formato','Formato']
	,['DVD_Formato_tv','Formato TV']
	,['DVD_Formato_imagen','Formato Imagen']
	,['','']
	,['Codigo_Barras','Código de Barras']
	]
	)


	sHTML += "<TABLE border='0'>"

	for(var f=0; f<maDatosPeli.f_length(); f++){
		var sSeccion = maDatosPeli.f_getVal("NombreBD", f);
		var sTitulo  = maDatosPeli.f_getVal("NombreHTML", f);
		
		if (sSeccion!="") {
			sEXML += "<IF bd='"+sSeccion+"' > "
			sEXML += "<TR>"
				sEXML += "<TD><STRONG>"+sTitulo+":</STRONG></TD>"
				sEXML += "<TD><BD>"+sSeccion+"</BD></TD>"
			sEXML += "</TR>"
			sEXML += "</IF>"
		} else {
			sEXML += "<TR><TD class='cajaSep'></TD></TR>"
		}
	}

	var nRegs = maProducto.f_maGetRegs();
	for(var f=0; f<nRegs; f++){
		sHTML += ParseEXMLs (sEXML,"",maProducto,f)
	}	

	sHTML += "</TABLE>"
	
	return(sHTML)
}



// Sinopsis 
function PintaSinopsis(bAdmin) { document.write(DrawSinopsis(bAdmin)) }
function DrawSinopsis(bAdmin){
	var sHTML = "", sEXML = ""; 

		sHTML += "<DIV class='sinopsis'>"
			if (bAdmin) sHTML += DrawTextoDestacado();

			//if (bAdmin) sHTML += "<span>Sinopsis</span><BR />";
	
			sEXML += "<BD>Argumento</BD>"

			sHTML += (ParseEXMLs (sEXML,"",maProducto,0)).f_parse2Format("TEXT", "HTML");		
		sHTML += "</DIV>"
		
	return(sHTML);
}


function PintaPrecioPVP(){ document.write(DrawPrecioPVP()) }
function DrawPrecioPVP(){
	var sHTML = "";
	var sPrecio = DrawDato(maProducto,'Precio');
	var bAlquiler = maProducto.f_maGetVal("bAlquiler", 0);

	if (g_nNivel>=20 && bAlquiler==0){
				sHTML += "<DIV class='fbsCol2Precio'>"
				sHTML += 	"P.V.P. "+sPrecio+" &#128;"
				sHTML += "</DIV>"
	}
	
	return (sHTML);
}


function PintaTextoDestacado() { document.write(DrawTextoDestacado()) }
function DrawTextoDestacado(){
	var sHTML = "", sEXML = "";

	if (maFrase.f_maGetRegs ()  ) {
		if (maFrase.f_maGetVal ("destacado",0) || maFrase.f_maGetVal ("otros",0)) {
			sHTML += "<DIV class='fraseKeySellingPoint'>"
				sEXML += " <BD>Destacado</BD>"
//				sEXML += " <IF bd='otros' ><BR /><BR /><BD>otros</BD></IF>"
				sHTML += (ParseEXMLs (sEXML,"",maFrase,0)).f_parse2Format("TEXT", "HTML");
			sHTML += "</DIV>"
		}
	}
	
	return(sHTML)
}


/* Menu Opciones Ficha */

var g_maMenuOpc = new MArray(['Seccion','Nombre','Enlace']
	,[
	 ['datos','Datos Técnicos','javascript:DrawDatosTecnicos()']
	,['galeria','Galería de Fotos','']
	,['trailer','Trailer','']
	,['website','Website','']
	]
)

function PrintMenuOpciones(sCual,bAdmin,nIDPeli,nIDRef) { document.write(DrawMenuOpciones(sCual,bAdmin,nIDPeli,nIDRef)) }
function DrawMenuOpciones(sCual,bAdmin,nIDPeli,nIDRef){

	var sHTML = "";
	var sEXML2 = "";
	var nMateriales = maTrailer.f_maGetRegs();

			sHTML += "<UL>"

			for (var f=0; f<g_maMenuOpc.f_length(); f++){
				var sClass  = "";
				var sParams = "";

				var sSeccion = g_maMenuOpc.f_getVal("Seccion", f);
				var sNombre  = g_maMenuOpc.f_getVal("Nombre", f);
				var sEnlace  = g_maMenuOpc.f_getVal("Enlace", f);


				if(bAdmin) 	sEnlace = sEnlace+"?idPeli="+nIDPeli+"&idRef="+nIDRef;


				if(sSeccion=="galeria"){
					var nFotosGal = maProducto.f_maGetVal("Fotografias",0)
					sEnlace = "";
					
					if(nFotosGal!=0) {
						sEnlace = "galeria_fotos.asp?idPeli="+nIDPeli+"&idRef="+nIDRef
						if (!bAdmin) sEnlace = "javascript:DrawGaleria()"
					}
				}

				if(sSeccion=="trailer"){
					sEnlace = "";
					if (nMateriales!=0){
							
							if (!bAdmin) {
								sEXML2 = "javascript:AbrirTrailer(<BD>fk_idPelicula</BD>,"+maTrailer.f_maGetVal("IdMaterial",0)+",\""+(maTrailer.f_maGetVal("NombreMaterial",0)).toLowerCase()+"\","+maTrailer.f_maGetVal("ancho",0)+","+maTrailer.f_maGetVal("alto",0)+",\""+maProducto.f_maGetVal("titulo",0)+"\")"
								//sEXML2 = "trailers_ventana.asp?idPeli=<BD>fk_idPelicula</BD>&idMat="+maTrailer.f_maGetVal("IdMaterial",0)+"&seccion="+(maTrailer.f_maGetVal("NombreMaterial",0)).toLowerCase()
							} else {
								sEnlace = "ficha_trailer.asp"
								sEnlace = sEnlace+"?idPeli="+nIDPeli+"&idRef="+nIDRef;
								sEXML2 = ""
							}

							sEnlace += ParseEXMLs (sEXML2,"",maTrailer,0);		
					}
				}

				if(sSeccion=="website"){
					sEnlace =  maProducto.f_maGetVal("Website",0);
					if (sEnlace!="") sParams=" target='_blank' ";
				}

	
				if (sEnlace) {

					if (sSeccion==sCual) sClass = " class='fopcOn'";
					sHTML +="<LI><A "+sParams+" href='"+ sEnlace +"' ";
					if (sSeccion!=sCual) sClass="";
					sHTML += " "+ sClass +" ><SPAN>"+ sNombre +"</SPAN></A></LI> ";

				}
				
			}

			sHTML += "</UL>"
		

	return(sHTML);
}





function PintaProdsAsociados(bAdmin) { document.write(DrawProdsAsociados(bAdmin)) }
function DrawProdsAsociados(bAdmin){
	var sHTML = "", sEXML = "", sHTML2 = "";
	var sHTMLPre = "";
	var sHTMLPost = "";
	var nRegs = maProdsAsociados.f_maGetRegs();
	var sPagina = "ficha.asp";

	if (nRegs>1){

		sHTMLPre = "<DIV class='disponible'>"
		sHTMLPre+= 	"<DIV><STRONG>También disponible en:</STRONG></DIV>"
		sHTMLPre+= 	"<UL>"

		sHTMLPost= "</UL></DIV>"
		
		if(bAdmin) sPagina = "ficha_producto.asp";

		sEXML += "<LI>";
		sEXML += 	"<A href='"+sPagina+"?idPeli=<BD>Pelicula</BD>&idRef=<BD>Referencia</BD>'> ";
		sEXML +=	"<BD>Formato</BD> <IF bd='bAlquiler'>Alquiler<ELSE /><IF bd='Edicion'><BD>Edicion</BD><ELSE />Venta</IF></IF></A> "
		sEXML += 	"<IF bd='Fecha_Salida'>[<BD>Fecha_Salida</BD>]</IF>"
		if (bAdmin){ 
			sEXML += "<IF fun='\"<BD>bAlquiler</BD>\"==\"false\"'><IF bd='Precio'> - [ P.V.P. <STRONG><BD>Precio</BD> €</STRONG> ]</IF></IF>"
		}
		sEXML += "</LI>"
	
		for(var f=0; f<nRegs; f++){
			var sRef = maProdsAsociados.f_maGetVal("Referencia", f)
			if (sRef != sIDReferencia){
			 	sHTML2 += ParseEXMLs (sEXML,"",maProdsAsociados,f);
			}
		}

		sHTML += sHTMLPre + sHTML2 + sHTMLPost;
	}
	return (sHTML);
}




function PintaExtras() { document.write(DrawExtras()) }
function DrawExtras(){
	var nRegs, nRegs2, nRegsExtras
	var sHTML = "", sEXML = "";

	nRegs = maAudio.f_maGetRegs();

	if (nRegs) {
		sHTML += "<strong>Idiomas:</strong>"
		sHTML += "<ul>"
		sHTML += 	"<li>"
		sEXML = ""
		sEXML += "<IF bd='formato'><BD>idioma</BD> <BD>formato_audio</BD>, </IF>"
		for(var f=0; f<nRegs; f++){
			sHTML += ParseEXMLs (sEXML,"",maAudio,f)
		}
		sHTML = sHTML.substring (0,sHTML.length-2)
		sHTML += 	"</li>"
		sHTML += "</ul>"
	}
	
	nRegs2 = maAudio.f_maGetRegs();
	if (nRegs2>1) {
		sHTML += "<strong>Subtitulos:</strong>"
		sHTML += "<ul>"
		sHTML += "	<li>"	
		
		sEXML = ""
		sEXML += "	<IF bd='Subtitulos' ><BD>idioma</BD>, </IF>"
		for(var f=0; f<nRegs2; f++){
			sHTML += ParseEXMLs (sEXML,"",maAudio,f)
		}	
		
		sHTML = sHTML.substring (0,sHTML.length-2)
		sHTML += 	"</li>"
		sHTML += "</ul>"
	}

	nRegsExtras = maExtras[0].length;
	if (nRegsExtras) {
		sHTML += "<strong>Contenidos extra del "+maProducto.f_maGetVal("Formato",0)+":</strong><br />"
	
		for(var h=0; h<nRegsExtras; h++){
			var vValue=maExtras[1][h]
			var sTitulo=maExtras[0][h]
			
			if (vValue) {

				if (vValue==true){

					var nPos = a_sExtrasDVD.f_indexOf (maExtras[0][h])
					if (nPos!=-1) {

						if (sTitulo=="Discos") {
							sHTML += "<UL><LI>"+sTitulo+ ": "+vValue+"</LI></UL>"
						} else {
							sHTML += a_sExtrasDVD[nPos+1] +"<BR />"
						}

					}

				}
				else {
					if (sTitulo=="Discos") sHTML += "<STRONG>Discos:</STRONG> "
					sHTML += vValue.f_parse2Format("TEXT", "HTML")+"<BR />";
				}

			}

		}	

	}

	if (nRegs+nRegs2+nRegsExtras==0) sHTML = ""
	return(sHTML)

}



function PintaDatosTecnicos(){ document.write(DrawDatosTecnicos()) }
function DrawDatosTecnicos(){
		var sHtml = "";
	
		//sHtml +='<DIV id="photos">'
		sHtml += '<P class="titulo">datos técnicos</P>'
				
		sHtml += '<TABLE border="0" class="datosTecnicos">'
		sHtml += '<TR>'
		sHtml += 	'<TD class="dtSize">'
		sHtml += 		DrawProdsAsociados()
		sHtml += 		DrawDatosPeli()
		sHtml += 	'</TD>'					
		sHtml += 	'<TD><img src="'+oIGZ.m_sRootPath+'pix/magic.gif" width="10" border="0" /></TD>'
		sHtml += 	'<TD class="dtSize">'
		sHtml += 		DrawExtras()
		sHtml += 	'</TD>'					
		sHtml += '</TR>'
		sHtml += '</TABLE>'
		//sHtml +='</DIV>'
		
		//alert(document.getElementById("contenido"))
		document.getElementById("FichaOpciones").innerHTML = DrawMenuOpciones("datos");
		document.getElementById("datosTecnicos").style.display = "block";
		document.getElementById("datosTecnicos").innerHTML = sHtml;
		document.getElementById("galeriaTitulo").style.display = "none";

		jQuery('#photos').html(sHtml).galleryView({
				transition_speed: 0,
				transition_interval: 0, // para parar la anim automática
				easing: false,
	    	pause_on_hover: false, 
	    	show_captions: false, 
				fade_panels: false
		});
		document.getElementById("photos").style.display = "none";
		document.getElementById("photos").innerHTML = '';
		//return (sHtml)

}

function PintaGaleria(){ document.write(DrawGaleria()) }
function DrawGaleria(){

	var nFotos = maProducto.f_maGetVal("Fotografias",0)
	if(nFotos>25) nFotos = 25;
	var sHtml = ''
			
			for (var f=0; f<nFotos; f++){
			
				sHtml+=	'<div class="panel">'
				sHtml+=		'<img src="'+oIGZ.m_sRootPath+'WEB_UNIX/inet/galeria_medias/'+maProducto.f_maGetVal("id",0)+'_'+f+'.jpg" />'
//				sHtml+=		'<img src="'+oIGZ.m_sRootPath+'WEB_UNIX/inet/galeria_fotos/'+maProducto.f_maGetVal("id",0)+'_'+f+'.jpg" />'
				sHtml+=	'</div>'
			
			}

			sHtml+=	'<ul class="filmstrip">'
			for (var f=0; f<nFotos; f++){
			
				sHtml+=		'<li><img src="http://www.sonypictures.es/WEB_UNIX/inet/galeria_mini/'+maProducto.f_maGetVal("id",0)+'_'+f+'.jpg" '
				sHtml+=			' alt="'+(f+1)+' de '+nFotos+'" title="'+(f+1)+' de '+nFotos+'"  />'
				sHtml+=		'</li>'
			
			}
			sHtml+=	'</ul>'


	
	document.getElementById("FichaOpciones").innerHTML = DrawMenuOpciones("galeria");
	document.getElementById("datosTecnicos").style.display = "none";
	document.getElementById("datosTecnicos").innerHTML = '';
	document.getElementById("photos").style.display = "block";
	document.getElementById("galeriaTitulo").style.display = "block";

	
	jQuery('#photos').html(sHtml).galleryView({
			//panel_width: 500,
			panel_width: 800,
			panel_height: 450,
			//panel_height: 230,
			frame_width: 100,
			frame_height: 64,
			transition_speed: 2000,
			background_color: '#fff',
			border: 'none',
			easing: 'easeInOutBack',
    	pause_on_hover: false, 
			nav_theme: 'dark',
			transition_interval: 6000, 
//			transition_interval: 0, // para parar la anim automática
//			filmstrip_position: 'top',
			overlay_text_color: 'white',
			caption_text_color: 'black',
			show_captions: true, // muestra los alt-title de las fotos pequeñas
			fade_panels: true
	});
	
}
