//********************************************************************
//
//
//  Visor de vídeo - © 2004 Antena 3 Televisión		
//  Diseño y desarrollo: David G.Bonacho Modificado: Alberto Sánchez González
//
//********************************************************************

function parseAte(campo){ // © 2001  - DGB
 var texto = location.search.substring(1, location.search.length);
 var result = false;
 if(texto.indexOf(campo)>=0){
  var txtRst = texto.substring(texto.indexOf(campo),texto.length);
  var txtCmp = txtRst.substring(0,txtRst.indexOf('&'));
  if (txtCmp=='') txtCmp = txtRst.substring(0,txtRst.length);
  result = txtCmp.substring((txtCmp.indexOf('=')+1),txtCmp.length);
 }
 return(result);
}


codweb=parseAte('codweb');
if (codweb == false)
  codweb = '0';
videoURL100=parseAte('videoURL100');
videoURL56=parseAte('videoURL56');
////Comprobamos si es video de 7d7n. Estos videos comienzan por ese string
if ( (videoURL100.indexOf("7d7n")>=0) || (videoURL100.indexOf("7D7N")>=0)  || (videoURL100.indexOf("7dias7noches")>=0))
   codweb=0;  //En cero estara el caso especial


function resicear(){
window.top.resizeTo(775,690);
}

function ponvideo(elvideo,ancho,alto){
if(publicidad[codweb]==1)
{  
  
  
  elvideo = elvideo.substring(0,elvideo.length-3);
  elvideo = elvideo + "asx";
  //if(campanias[codweb][1].videos.substring(campanias[codweb][1].videos.length-1)=='/')
  //{
    //elvideo = campanias[codweb][1].videos + elvideo;
  //}
  //else
  //{
    //elvideo = campanias[codweb][1].videos + '/' + elvideo;
  //}
  elvideo=elvideo.substring(elvideo.lastIndexOf("/")+1,elvideo.length);
  
  //CAMBIAR ANTES DE SUBIR
  elvideo = "/visorvideos_web/publicidad/"+carpetapubli[codweb]+"/" + elvideo;
  //elvideo = "http://www.antena3.com/visorvideos_web/publicidad/"+carpetapubli[codweb]+"/" + elvideo;
  //FIN CAMBIAR ANTES DE SUBIR

  
}
//vd =   '<OBJECT name="xvideo" ID="xvideo" CLASSID="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" width="'+ancho+'" height="'+alto+'" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" standby="Cargando" standby="...Cargando vídeo..." TYPE="application/x-oleobject">\n';
vd =   '<OBJECT name="xvideo" ID="xvideo" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'+ancho+'" height="'+alto+'" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" standby="Cargando" standby="...Cargando vídeo..." TYPE="application/x-oleobject">\n';
//vd +=  '<PARAM NAME="FileName" VALUE="'+elvideo+'">\n';
vd +=  '<PARAM NAME="url" VALUE="'+elvideo+'">\n';
//vd +=  '<PARAM NAME="AnimationatStart" VALUE="false">\n';
//vd +=  '<PARAM NAME="TransparentatStart" VALUE="false">\n';
vd +=  '<PARAM NAME="AutoStart" VALUE="true">\n';
//vd +=  '<PARAM NAME="ShowControls" VALUE="0">\n';
//vd +=  '<PARAM NAME="ShowStatusBar" VALUE="0">\n';
//vd +=  '<PARAM NAME="SendPlayStateChangeEvents" VALUE="-1">\n';
vd +=  '<PARAM NAME="SendPlayStateChangeEvents" VALUE="True">\n';
vd +=  '<PARAM NAME="CurrentPosition" VALUE="0">\n';
//vd +=  '<PARAM NAME="ShowGotoBar" VALUE="0">';
vd +=  '<PARAM NAME="uiMode" VALUE="none">\n';
vd += '<Embed TYPE="application/x-mplayer2"\n';//Mozilla
vd += 'pluginspage="http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Plugin&"\n';
vd += 'SRC="'+elvideo+'  "\n';
vd += 'ShowControls=0\n';
vd += 'ShowStatusbar=0\n';
vd += 'Width='+ancho+'\n';
vd += 'Height='+alto+' name="xvideo">\n';
vd += '</embed>\n';
vd +=  '</OBJECT>\n';
return(vd);
}

function ponflash(){
var htm='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"  width="240" height="180">';
htm+='    <param name="movie" value="http://antena3.es/visorAntena3/img/cabecera.swf">';
htm+='    <param name="wmode" value="transparent">';
htm+='    <param name="quality" value="high">';
htm+='    <embed src="value="http://antena3.es/visorAntena3/img/cabecera.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="240" height="180"></embed></object>';
return(htm);
}

function letrero1(qTxt){
var htm = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" class="txt3">';
htm+='<br>'+qTxt+'</td></tr><tr><td align="center">&nbsp;</td></tr></table>';
return(htm);
}

function ponCalidad(){
var htm = '<table width="100%" border="0" cellspacing="0" cellpadding="0">\n';
    htm+= '  <tr> \n';
    htm+= '    <td align="center" class="txt3">Selecciona una calidad:</td>\n';
    htm+= '  </tr>\n';
    htm+= '  <tr> \n';
    htm+= '    <td align="center"> <table width="150" border="0" cellspacing="0" cellpadding="0">\n';
    htm+= '        <tr> \n';
    htm+= '          <td width="71" align="center"><a href="visor.htm?videoURL100='+videoURL100+'&codweb='+codweb+'" class="lk"><img src="img/wm-adsl1.gif" width="60" height="20" border="0"></a></td>\n';
    htm+= '          <td width="68" align="center"><a href="visor.htm?videoURL56='+videoURL56+'&codweb='+codweb+'" class="lk"><img src="img/wm-modem1.gif" width="60" height="20" border="0"></a></td>\n';
    htm+= '          <td width="1"><img src="img/spacer.gif" width="1" height="31"></td>\n';
    htm+= '        </tr>\n';
    htm+= '      </table></td>\n';
    htm+= '  </tr>\n';
    htm+= '</table>\n';
	return(htm);
}

curI = new Image();
curI.src = 'images/visorTickPos.gif';
curN = new Image();
curN.src = 'images/spacer.gif';


function aposicion(cual){//

	for(h=0;h<=20;h++){
		document.images["cur"+h].src = curN.src;
	}
	for(h=0;h<=cual;h++){
		document.images["cur"+h].src = curI.src;
	}
	/*document.getElementById("xvideo").Stop();
	document.getElementById("informa1").innerHTML="Espere unos segundos ...";
	trozo = document.getElementById("xvideo").Duration/20;
	document.getElementById("xvideo").currentPosition = parseInt(trozo*cual);
	document.getElementById("xvideo").play();*/
  document.getElementById("xvideo").controls.Stop();
	document.getElementById("informa1").innerHTML="Espere unos segundos ...";
	trozo = document.getElementById("xvideo").currentMedia.duration/20;
	document.getElementById("xvideo").controls.currentPosition = parseInt(trozo*cual);
	document.getElementById("xvideo").controls.play();
	setTimeout("aposicion2()",6000);
}

function ponerEnposicion(cual,act){

act++;

if(act<=cual){
	document.images["cur"+act].src = curI.src;
	setTimeout("ponerEnposicion("+cual+","+act+")",400);
}
}

function aposicion2(){
	document.getElementById('informa1').innerHTML="Reproduciendo";
}

function barracurso(){
var ht='<table width="100" border="0" cellspacing="1" cellpadding="0">';
ht+='<tr>';
for(i=0;i<=20;i++){ht+='<td bgcolor="#999999"><img src="img/spacer.gif" width="9" height="8" border="0" id="cur'+i+'" onMouseDown="aposicion('+i+')" alt="Avanzar-retroceder"></td>'};
ht+='</tr></table>';
return(ht);
}

function ponBotonera(){
var htm = '<table width="100%" border="0" cellspacing="1" cellpadding="0">\n';
    htm+= '  <tr> \n';
    htm+= '    <td align="right" bgcolor="#DBDBDB"> <table width="50" border="0" cellspacing="0" cellpadding="1">\n';
    htm+= '        <tr> \n';
    htm+= '          <td>'+barracurso()+'</td>\n';
    htm+= '          <td><img src="img/spacer.gif" width="22" height="23" border="0"></td>\n';

if(!promo[codweb]){
  htm+= '          <td><a href="JavaScript:xresicea()" class="lk"><img src="img/ampliar.gif" width="22" height="23" border="0" id="ampliarimg" alt="Ampliar / reducir la imagen"></a></td>\n';
}
    htm+= '          <td><a href="JavaScript:xstop()" class="lk"><img src="img/stop.gif" width="22" height="23" border="0"></a></td>\n';
    htm+= '          <td><a href="JavaScript:xpause()" class="lk"><img src="img/pausa.gif" width="22" height="23" border="0"></a></td>\n';
    htm+= '          <td><a href="JavaScript:xplay()" class="lk"><img src="img/play.gif" width="22" height="23" border="0"></a></td>\n';
    htm+= '        </tr>\n';
    htm+= '      </table></td>\n';
    htm+= '  </tr>\n';
    htm+= '  <tr> \n';
    htm+= '    <td bgcolor="#767676"><table width="100%" border="0" cellspacing="0" cellpadding="1">\n';
    htm+= '        <tr> \n';
    htm+= '          <td class="txt2"><span id="informa1">Reproduciendo</span></td>\n';
    htm+= '          <td align="right" class="txt2"><span id="informa2">Extrayendo duración total...</span></td>\n';
    htm+= '        </tr>\n';
    htm+= '      </table></td>\n';
    htm+= '  </tr>\n';
    htm+= '</table>\n';
	return(htm);
}




function PonPantalla()
{
	var enPantalla = '';
	if (videoURL100==false){
    falta();
		enPantalla=ponflash();
	//	var elemento=document.getElementById("informa1");
	//	elemento.innerText="Video NO CARGADO";
		document.getElementById('informa1').innerText="Video NO CARGADO";
	//	document.getElementById('informa2').innerTEXT=" ";
	}else{
		Idff = window.setTimeout("falta()", 3000);
		enPantalla=ponvideo(videoURL100,320,240);
		//Idff = window.setTimeout("falta()", 3000);
	}
	document.getElementById('espacioVideo').innerHTML=enPantalla;
}

// Controles de video
var pause=false;
var posicionVideo=0;

function xstop(){
	aposicion('0');
	//document.images[0].src = curI.src;
	document.getElementById('informa1').innerHTML="Parado";
	document.getElementById('xvideo').controls.CurrentPosition = 0;
	document.getElementById('xvideo').controls.Stop();
}
function xpause(){
	pause=true;
	document.getElementById('informa1').innerHTML="Congelado";
	/*if (document.getElementById("xvideo").PlayState==2 && xvideo.IsBroadcast==false) {
		document.getElementById("xvideo").Pause();
	}*/
  if (document.getElementById("xvideo").PlayState==3 && xvideo.IsBroadcast==false) {
		document.getElementById("xvideo").controls.Pause();
	}
  
}
function xplay(){
	/*if (document.getElementById("xvideo").playstate!=2 && pause==false) {
		document.getElementById('informa1').innerHTML="Reproduciendo";
		document.getElementById("xvideo").play();
	}
	if (document.getElementById("xvideo").playstate!=2 && pause==true) {
		document.getElementById("xvideo").Stop();
		document.getElementById('xvideo').currentPosition=posicionVideo;
		document.getElementById("xvideo").play();
		pause=false;
	}*/
  if (document.getElementById("xvideo").playstate!=3 && pause==false) {
    document.getElementById('informa1').innerHTML="Reproduciendo";
		document.getElementById("xvideo").controls.play();
	}
	if (document.getElementById("xvideo").playstate!=3 && pause==true) {
		document.getElementById("xvideo").controls.Stop();
		document.getElementById("xvideo").controls.currentPosition=posicionVideo;
		document.getElementById("xvideo").controls.play();
		pause=false;
	}
}


function falta(){
if(codweb<1001)
{
	if(promo[codweb][1])
  {
		wrpromo();	
    if(videoURL100!=false)
    {
      setTimeout("falta2()", 1000);
    }
  }
  else
  {
    PonImagen();
    if(videoURL100!=false)
    {
      setTimeout("falta2()", 1000);
    }
  }
}
else
{
    PonNoticias();
    if(videoURL100!=false)
    {
      setTimeout("falta2()", 1000);
    }
}
}

function falta2(){
	//ttotal = document.getElementById('xvideo').Duration;
  ttotal = document.getElementById('xvideo').currentMedia.duration;
	restant = document.getElementById('xvideo').controls.currentPosition;
  if (restant!=0)
    {posicionVideo=restant;}
	restant2 = ttotal - restant;
	minres = parseInt(restant2/60);
	secres = parseInt(restant2%60);
	d=parseInt(((2*restant*100)/ttotal)/10);

	for(h=0;h<=d;h++){
		document.images["cur"+h].src = curI.src;
	}
	document.getElementById('informa2').innerHTML = 'Faltan ' + minres + ' m ' + secres + ' sg';
	setTimeout("falta2()",1000);
}

function send(id)
{

    var url="http://www.antena3.com/a3noticias/servlet/Noticias?destino=../a3n/noticia/noticia.jsp&id="+id;
    var objVentana=window.parent;
    objVentana.opener.location=url;
    window.parent.close();    
}

function wrpromo()
{
  var htm ='<table width="100%" border="0" cellspacing="0" cellpadding="0" valign"top"><tr>';
if(promo[codweb].length==2)
{
    if(promo[codweb][1].imagen)
    {
      htm+='<td width="100%" style="border: #e6e6e6 solid 1px; padding-left:1px;" valign="top" class="etiqueta2">';
      htm+='<a href="' + promo[codweb][1].url + '" target="_blank">';
      htm+='<img src="/visorvideos_web/promos/' + promo[codweb][1].imagen  + '" width="300" height="250" style="border:solid 1px #CCCCCC"></a></td>';
    }
}
else
{
  for(var j=1;j<promo[codweb].length;j++)
  {
    if(j==3 || j==5)
    {
      htm+='</tr><tr>';
    }
    
    htm+='<td width="50%" style="border: #e6e6e6 solid 1px; padding-left:1px;" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr valign="top">';

    if(promo[codweb][j].texto!="" && promo[codweb][j].imagen!="" && promo[codweb][j].texto!="null" && promo[codweb][j].titulo!="null" && promo[codweb][j].imagen!="null")
    {
      htm+='<td colspan="2" class="etiqueta2">';
      htm+= promo[codweb][j].cabecera;
      htm+='</td></tr><tr><td colspan="2" height="4"><img src="images/shim.gif" height="4"></td></tr><tr><td width="58" style="padding-bottom:10px" rowspan="2" align="center">';
      htm+='<img src="/visorvideos_web/promos/' + promo[codweb][j].imagen  + '" width="50" height="60" style="border:solid 1px #CCCCCC"></td>';
      htm+='<td style="padding-left:6px; padding-right:6px;" heigth="16" valign="top"><a href="' + promo[codweb][j].url + '" class="parrafo1" target="_blank"><b>';
      htm+= promo[codweb][j].titulo + '</a></td></tr>';
      htm+= '<tr><td style="padding-left:6px; padding-right:6px;" valign="top"><a href="' + promo[codweb][j].url + '" class="enlace" target="_blank">';
      htm+= promo[codweb][j].texto + '</a></td></tr></table></td>';
      
    }
    else
    {
      if((promo[codweb][j].imagen!="" || promo[codweb][j].imagen!="null") && (promo[codweb][j].texto=="" || promo[codweb][j].texto=="null"))
      {
        htm+='<td heigth="16" class="etiqueta2">';
        htm+= promo[codweb][j].cabecera;
        htm+='</td></tr><tr><td style="padding-top:4px" height="4" align="center"><a href="' + promo[codweb][j].url + '" target="_blank">';
        htm+='<img src="/visorvideos_web/promos/' + promo[codweb][j].imagen  + '" width="120" height="60" border="0">';
        htm+='</a></td></tr>';
        htm+='</table></td>';
      }
      else
      {
        if ((promo[codweb][j].texto2=="") || (promo[codweb][j].texto2==null) || (promo[codweb][j].texto2=="null"))
        {
           htm+='<td heigth="16" class="etiqueta2">';
           htm+= promo[codweb][j].cabecera;
           htm+='</td></tr><tr valign="middle"><td width="97%" align="left" valign="middle" style="padding-left:6px; padding-right:6px; padding-top:4px"><a href="' + promo[codweb][j].url + '" target="_blank" class="parrafo1">';
           htm+='<strong>' + promo[codweb][j].titulo + ':</strong>&nbsp;';
           htm+='<span class="enlace">' + promo[codweb][j].texto + '</span>';
           htm+='</td></tr>';
           htm+='</table></td>';
        }
        else
        {
           htm+='<td colspan="2" heigth="16" class="etiqueta2">';
           htm+= promo[codweb][j].cabecera;
           htm+='</td></tr><tr valign="middle"><td class="parrafo1" width="3%" valign="middle" style="padding-top:10px">&nbsp;&gt;&nbsp;</td><td width="97%" align="left" valign="middle" style="padding-top:4px"><a href="' + promo[codweb][j].url + '" target="_blank" class="parrafo1">';
           htm+='<strong>' + promo[codweb][j].titulo + ':</strong>&nbsp;';
           htm+='<span class="enlace">' + promo[codweb][j].texto + '</span>';
           htm+='</td></tr><tr valign="middle"><td class="parrafo1" width="3%" valign="middle" style="padding-top:4px">&nbsp;&gt;&nbsp;</td><td width="97%" align="left" valign="middle" style="padding-top:4px"><a href="' + promo[codweb][j].url2 + '" target="_blank" class="parrafo1">';
           htm+='<strong>' + promo[codweb][j].titulo2 + ':</strong>&nbsp;';
           htm+='<span class="enlace">' + promo[codweb][j].texto2 + '</span>';
           htm+='</a></td></tr>';
           htm+='</table></td>';
        }   
      }
    }
  }
}

  htm+='</tr></table>';
  document.getElementById('promociones').innerHTML = htm;
}

//function paraPromo(){
	//document.getElementById('lapromo').innerHTML = '';
//}


function PonImagen()
{
  var htm ='<center><table cellspacing="0" cellpadding="0" border="0" width="300" height="250" align="center"><tr>';
  htm += '<td valign="top" border="0" width="300" height="250">';
  if(typeof(adlink_randomnumber)=="undefined"){var adlink_randomnumber=Math.floor(Math.random()*10000000000)}
  htm +='<scr'+'ipt language="JavaScr' + 'ipt" src="http://ad.es.doubleclick.net/adj/'+htmban2[codweb]+';sz=300x250;tile=2;ord='+adlink_randomnumber+'?"></scr'+'ipt>';
  //htm +='<noscr'+'ipt>';
  htm +='<a href="http://ad.es.doubleclick.net/jump/'+htmban2[codweb]+';sz=300x250;tile=2;ord=1234567890?" target="_blank">'; 
  htm +='<img src="http://ad.es.doubleclick.net/ad/'+htmban2[codweb]+';sz=300x250;tile=2;ord=1234567890?" border="0" width="300" height="250">';
  htm +='</a>';
  htm +='</td></tr></table></center>';
  document.getElementById('promociones').innerHTML = htm;
}

function PonNoticias()
{
  var histo='<table width="100%" border="0" cellspacing="0" cellpadding="5">';
  var ubicacion="http://www.antena3.com/a3n/a3n_contenidos/contenidos";
  window.parent.focus();
  for(i=0;i<=2; i++)
	{
    histo += '  <tr> ';
    histo += '    <td align="center"> <table width="272" border="0" cellspacing="0" cellpadding="1">';
    histo += '    <tr> ';
    histo += '          <td bgcolor="#999999"><table width="274" border="0" cellspacing="0" cellpadding="5">';
    histo += '              <tr> ';
    histo += '                <td valign="top" bgcolor="#FFFFFF"><a href="javascript:send('+id[i]+');" class="link">'+texto[i]+'</a></td>';
    histo += '                <td width="1" valign="top" bgcolor="#FFFFFF"><img src="'+ubicacion+foto[i]+'" width="68" height="51"></td>';
    histo += '              </tr>';
    histo += '            </table></td>';
    histo += '        </tr>';
    histo += '      </table></td>';
    histo += '  </tr>';
  }
  histo += '</table>';
  document.getElementById('promociones').innerHTML = histo;
}












