var IDL,IDL2; 
var doindex = 0;
var page=1;
var stop = 0;
var f_,uid_;
var status = 0;

function INIT(doindex,t,f,uid,cs){
f_=f;
uid_=uid;
  if(t=="all"){
	IDL = setInterval(function(){ 	
		if(isplaying()!=false) {if(P==0) clearInterval(IDL);}else{if(P == doindex)clearInterval(IDL); loadSWF(++doindex,f_,uid_,cs);} },500);
  }else  { clearInterval(IDL);loadSWF(t,f_,uid_,cs);}
}



function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  }	else {
    return document[movieName]
  }
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {

  if (typeof(theMovie) != "undefined") {
	try
	{
        return  theMovie.PercentLoaded() == 100;
	}catch(ex)
	{
		setTimeout('pause()',1000);
	}    
  } else {
    return false;
  }
}


function pause(){
return true;
}

function wait(){
return false;
}

function playmovie() {
//alert(movieIsLoaded(thisMovie(movieName)));
//  if (movieIsLoaded(thisMovie(movieName))!=true) {    
    thisMovie(movieName).Play();

//  }
}

function stopmovie() {
  if (movieIsLoaded(thisMovie(movieName))) {
    status=1;document.getElementById('status_').src='/js/play.gif';
    document.getElementById('status_').title="Play";
    thisMovie(movieName).StopPlay();
  }
}


function go(theFrame) {
  if (movieIsLoaded(thisMovie(movieName))) {
    thisMovie(movieName).GotoFrame(theFrame);
  }
}

function totalframes() {
  if (movieIsLoaded(thisMovie(movieName))) {
    return thisMovie(movieName).TotalFrames();
  }
}

function isplaying() {
  if (movieIsLoaded(thisMovie(movieName))) {
    return thisMovie(movieName).IsPlaying();
  }
}

function golabel(thelabel) {
if (movieIsLoaded(thisMovie(movieName))) {
thisMovie(movieName).TGotoLabel("_level0/",thelabel);
}
}


function loadSWF(fn,f,uid,cs){
page=fn;
 if(movieIsLoaded(thisMovie(movieName))==true){

	var randomseed = new Date().getSeconds();
	var fk = Math.round(99999999999*Math.random());
	url = "?cs=" + cs + "&url=" + fn + "&F=" + f + "&ID=" + uid + "&key"+ fk + "=" + fk;
	Net.get({
	   url: "../TTS/loader.asp"+ url,
	   vars: "",
	   onsuccess: function(res) {
                
		GetCap(fn);
                pageColor(fn);
		status=0;document.getElementById('status_').src='/js/pause.gif';
                document.getElementById('status_').title="Pause";
	        document.getElementById('dev').innerHTML = res.responseText; 
	   },
	   onerror: function() {  	}
	 });
 }
}

function Loading(todo){
document.getElementById('loading1').style.display=todo;
document.getElementById('loading2').style.display=todo;
document.getElementById('loading3').style.display=todo;
}

function GetCap(fn){
	for (var k = 1; k <= P+1; k++){
	 var cap = 'cap'+k;
	 if(k == fn) {         document.getElementById(cap).style.visibility='visible'; painter(0,BL[k]+2,"black",k); count=0; movieName="flash"+k; TextCap(fn); }
	 else {document.getElementById(cap).style.visibility='hidden';}
	}
    
}

function TextCap(k){
	IDL2 = setInterval(function(){        
		if(isplaying()!=false) {TextColorer(k);}else{} },25);
}

var count=0;
function TextColorer(k){
var color="red";
var wrd=0;

  if (movieIsLoaded(thisMovie(movieName))) {   
    Loading('none');

    try
    {
        wrd = thisMovie(movieName).GetVariable('d'+k); 	
    } catch (ex)
    {
        if (ex.message.indexOf('Unspecified') == -1)
        {
            //throw ex;
            if(wrd==0)wrd=1;
        }
        else
        {
            //alert('caught the error!');
            if(wrd==0)wrd=1;
        }
    }

 
        





        if(wrd>1)wrd=wrd*1+1;
	if(document.getElementById('w'+k+'_'+wrd)){
                document.getElementById('w'+k+'_1').style.color = color;
		if (wrd > 0)   { if(document.getElementById('w'+k+'_'+(wrd)).style.color != color){ document.getElementById('w'+k+'_'+(wrd)).style.color = color;count++;}}
		if (count<wrd) { painter(count,wrd,color,k);count=wrd;}
	}
   if(wrd==0){
	//document.getElementById('w'+k+'_'+count).style.color = color;
	status=1;document.getElementById('status_').src='/js/play.gif';
        document.getElementById('status_').title="Play";
        painter(0,BL[k]+2,color,k);
        stop=1;
   }
  }
}

function painter(c,w,color,k){


//document.getElementById('deva').innerHTML=k + "c=" +c+ " w="+w;

//var thisMovie ="flash"+k;
//var t_f=document.getElementById(thisMovie).TotalFrames;
//document.getElementById('deva').innerHTML="Page:"+ k + "; Segment:"+ w +"; Total frames:" + t_f;


if(c==0)c=1;
if(c>w){c_=w; w_=c;}
else{c_=c; w_=w;}

for (i=c_;i<w_;i++){ 
	document.getElementById('w'+k+'_'+i).style.color = color; 	
}

}

function pageColor(pid){
  for(var i=1; i<=P+1; i++){
   if(i != pid)	{Loading('block');document.getElementById('page'+i).style.background="#ffcc99";document.getElementById('page'+i).style.color="black";}
   else {document.getElementById('page'+pid).style.background="#FFEEDE";document.getElementById('page'+pid).style.color="red";}
  }
}

function ImgFlip(ob){
	if (status==1) {status=0;document.getElementById(ob).src='/js/pause.gif'; document.getElementById(ob).title="Pause"; playmovie();}
	else { status=1;document.getElementById(ob).src='/js/play.gif';document.getElementById(ob).title="Play"; clearInterval(IDL);stopmovie();}
}
