var timerID = 0;
var segs = 5;
var est = 0;
var bis='a';
var imgfile='';
var playing = false;
var avs=1;

function showest() {
//    
    if (bis=='b') {
        imgfile=imgdir+'/ygran-est'+ests[est]+'.jpg';
     } else {
        imgfile=imgdir+'/xgran-est'+ests[est]+'.jpg';
     }
     document.getElementById('est').src=imgfile;
     document.getElementById('seg').innerHTML=seg[est];
     document.getElementById('num').innerHTML=(est+1)+"/"+tot;
     document.getElementById('tex').innerHTML=txt[est];
     segs=seg[est]*vec[est];
     //if ()
}

function player() {
	 tiempo=1000;
   if(timerID) {
      clearTimeout(timerID);
   }
   if (avs==1){
     avs=0; avis('');
   }else{
	   segs=segs-1;
	   if (segs<0) {
				if (lad[est]>1 && bis=='a'){
						bis='b';
				}else{
						est=est+1;
						bis='a';
				}
	      if (est>=tot) {Stop(); return;}
	      avis(sready);
	      avs=1;
	      tiempo=3000;
	      showest();
	    }
	 }
   document.getElementById('seg').innerHTML=segs;
   timerID = setTimeout("player()", tiempo);
}

function Start() {
  if (!playing){
	  avis(sready);
	  avs=1;
		if (est>=tot) est=0;
		timerID  = setTimeout("player()", 1000);
		document.getElementById('start').innerHTML="&brvbar;";
		playing=true;
   } else {
		avis(spause);
		if(timerID) {
		clearTimeout(timerID);
		timerID  = 0;
		}
		playing=false;
		document.getElementById('start').innerHTML="&rsaquo;";
   }
}

function Skip(n) {
   est=est+n;
   if (est<0) est=0;
   if (est>=tot) est=0;
   //playing=false;
   bis='a';
   avs=1;
   showest();
}

function Stop(){
   if(timerID) {
      clearTimeout(timerID);
      timerID  = 0;
   }
   est=0;
   playing=false;
 	 document.getElementById('start').innerHTML="&rsaquo;";
 	 avis(smsjini);
   showest();
}

function avis(msj){
  if (msj==''){
  	document.getElementById('avi').style.width='0px';
  }else{
  	document.getElementById('avi').style.width='98%';
  }
	document.getElementById('aviso').innerHTML=msj;
}

function Redim() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  myHeight=myHeight-20;
  var iratio=300/248;
  var diezmo;
  diezmo=Math.round(myHeight/10);
  document.getElementById('est').style.width=Math.round(myHeight*iratio)+'px';
  document.getElementById('est').style.height=myHeight+'px';
  document.getElementById('seg').style.fontSize=(Math.round(myHeight/3))+'px';
  document.getElementById('tit').style.fontSize=(Math.round(myHeight/20))+'px';
  document.getElementById('prev').style.fontSize=diezmo+'px';
  document.getElementById('next').style.fontSize=diezmo+'px';
  document.getElementById('start').style.fontSize=diezmo+'px';
  document.getElementById('stop').style.fontSize=diezmo+'px';
  document.getElementById('close').style.fontSize=diezmo+'px';
  document.getElementById('num').style.fontSize=diezmo+'px';
  document.getElementById('tex').style.fontSize=(Math.round(myHeight/20))+'px';
  document.getElementById('aviso').style.fontSize=diezmo+'px';
}

