var cont=0;
var currentState=0;
var currentRemaining =0;
var currentPosition=0;
var indiceVideo = 0;
var flag= 0;
var salta= new Boolean(false);
var showAds = new Boolean(true);
var addRunning = new Boolean(true);
var addEnd= new Boolean(true);
var estadis= new Boolean(true);
var archivoFlv = new Array(); archivoFlv[0]='http://videos.eluniversal.com.mx/videos/out-autosforaneos.flv';
var archivoImg = new Array(); archivoImg[0]="http://videos.eluniversal.com.mx/imagenes/portaautosforaneos.jpg";
var ligaAds ="http://ads.eluniversal.com.mx/RealMedia/ads/adstream_nx.ads/www.eluniversal.com.mx/video@x66";
var ligaplayer="http://www.eluniversal.com.mx/flvplayer.swf";

function checaRefresh(salta){
  if(salta==1){
    if(currentState ==1 || currentState==2){
        setTimeout("checaRefresh(1)",(10 * 60) * 1000);
    }else{
        window.location.reload();
    }
  }else{
     setTimeout("checaRefresh(1)",(10 *60) *1000);

  }
}

function reproduceVideo(idVideo,status){
				salta=false;
            sendEvent('player1','stop');
            loadFile('player1',{file:ligaAds,autostart:'true',category:'commercial'});
            indiceVideo=idVideo;
            pintaTexto(0);
				flag=1;
            showAds=false;
				
}

function loadFile(swf,obj) { 
    thisMovie(swf).loadFile(obj); 
}
function sendEvent(swf,typ,prm) { 
  thisMovie(swf).sendEvent(typ,prm); 
}

function thisMovie(swf) {
     if(navigator.appName.indexOf("Microsoft") != -1) {
        return window[swf];
     } else {
        return document[swf];
     }
}

function getUpdate(typ,pr1,pr2,pid) {
	if(pid != "null") {
		if(typ == "size" && pr1 != undefined ) {
			if(showAds==true){
				if(pid=='player1'){
	 			sendEvent('player1','stop');
				loadFile('player1',{file:ligaAds,autostart:'true',category:'commercial',linkfromdisplay:true});
				}
				showAds=false;
				addRunning=true;
			flag=1;
			}
		}
		if(typ == "state"){
		 currentState = pr1;
		}
		if(typ == "state" && pr1==3){
			if(salta==false){
			if( pid=='player1'){
			addEnd=true;
	 		sendEvent('player1','stop');
			loadFile('player1',{file:archivoFlv[indiceVideo],autostart:'true',category:'video'});
	 		sendEvent('player1','playpause');
			salta=true;
			addRunning=false;
			}else{
			salta=false;
			addEnd=false;
			addRunning=true;
			}
         }else{
				if(indiceVideo==6){
					loadFile('player1',{file:archivoFlv[0],autostart:'true',category:'video'});
					sendEvent('player1','stop');
					showAds=false;
					flag=1;
					indiceVideo=0;
					addRunning=true;
					pintaTexto(0);
					exit;
				}else{
					salta=false;
					sendEvent('player1','stop');
					loadFile('player1',{file:ligaAds,autostart:'true',category:'commercial'});
					showAds=false;
					flag=1;
					indiceVideo=indiceVideo+1;
					pintaTexto(0);

				}
			}
		}
		if(typ == "load" && showAds==false  && (addRunning==true)){
			addRunning=false;
			addEnd=false;
		}
		if(typ == "load" && showAds==false  && addRunning==false){
			if(flag==0){
				sendEvent('player1','playpause');
			flag=1;
			}
		}
		if(typ == "item" && pr1==0 && flag==1){
				sendEvent('player1','playpause');
				if(addRunning==false){
				sendEvent('player1','playpause');
				}
			flag=0;
		}
		if(typ == "time") {
			currentPosition = pr1; pr2 == undefined ? null: currentRemaining = Math.round(pr2);
			if((currentPosition==5) && currentState==2 && addRunning==false){
				if(pid=='player1'){
				var obj = thisMovie("player1").itemData(0);
				   if(obj["category"]=="video" && addEnd==true){
		               	  	addEnd=false;
					var hit="http://hits.eluniversal.com.mx/accesos/accesos_detalle.php?fin=fin&var_cabeza="+archivoTituloSin[indiceVideo]+"&var_secc=300&p_id_nota="+archivoId[indiceVideo]+"&ini=ini&autor=crux";
					var tmpHit = document.getElementById("msgHit"); if (tmpHit) { tmpHit.innerHTML = " <image src=" + hit + " width=1 height=1>"; }
				   }
				}else{
					if(addEnd==false){
					addEnd=true;
					showAds=true;
					salta=false;
					datoHits=pid.split("|");
                                        var hit="http://hits.eluniversal.com.mx/accesos/accesos_detalle.php?p_id_nota="+datoHits[0]+"&var_cabeza="+datoHits[1]+"&var_secc=300&fin=fin";
                                        var tmpHit = document.getElementById("msgHit"); if (tmpHit) { tmpHit.innerHTML = " <image src=" + hit + " width=1 height=1>"; }
					}else{
					   //addEnd=false;
					//addRunning=true;
					//salta=false;
					}
				}
			}
		}
   }
};

checaRefresh(0);


