var H = screen.height;// (screenheight - boxheight) / 2
var W =screen.width ;// (screenwidth - boxwidth) / 2
var H=180;
var W=20
var hpo=120;
var z=0;
//****************** alter this section when adding or deleting an ad

//   STEP 1
// NB rem the 1st ad (tablead1)is always the IMMS logo
// 1st change nofads to equal the last ad in the rotation where inc(i) ="y"

var nofads=5;

// now change the y to n and vice versa to include a particular Ad
// you can have up to ten Ads - make sure u have a tablead for each "y"

var inc1="y";   //logo
var inc2="n";   //Ad 2
var inc3="n";   //Ad 3
var inc4="y";   //Ad 4
var inc5="n";   //Ad 5
var inc6="n";   //Ad 6
var inc7="n";   //Ad 7
var inc8="n";   //Ad 8
var inc9="n";   //Ad 9
var inc10="n";  //Ad 10

//**********************************
var count=5; //this is the interval in seconds -- tablead1 is the IMMS logo
var count1=count; 
nofads=nofads+1;
// choose which ad to start from - this increments for each ad starting at 0 for logo
var t=1;
var tim=800;// timer especiall for the blank ad conditions

function countdown() {
  if(z==0)
{count=-1;}
  if(count>=0){
  //alert(count);
    var obj = document.getElementById("countdown");
    obj.replaceChild(document.createTextNode(count.toMinutesAndSeconds()), obj.firstChild);
    count--;
    
    window.setTimeout("countdown()",tim);
  } else {
  t=t+1; tim=800;
  //alert("t= "+t+"    and count= "+count);

 // if (t==1)
 if (t==1 & inc1=="y")
  {
 
  tablead1.style.position='absolute';
 tablead1.style.top=10;
tablead1.style.left=hpo;
//******* put the last tablead number below
//******* so -if there are three adds then tablead3
//******* or if you only wish to rotate between the logo and 1 add then this 
//******* should be the table add you want to have on view
  tablead3.style.position='absolute';
 tablead3.style.left=-3330;
 count=1;
 var recur_call = "countdown()";
setTimeout(recur_call, count); 
  }
  //if (t==2)
  if (t==2 & inc2=="y")

  {
  //alert("t=  "+t);
  
  tablead2.style.position='absolute';
 tablead2.style.top=10;
tablead2.style.left=hpo;
  tablead1.style.position='absolute';
 tablead1.style.left=-3330;
  count=count1+6;
  var recur_call = "countdown()";
setTimeout(recur_call, count); 

   } 
  if (t==2 & inc2=="n")
{
 tablead1.style.position='absolute';
 tablead1.style.top=10;
tablead1.style.left=hpo;
count=0;tim=0;
  var recur_call = "countdown()";
setTimeout(recur_call, count); 

}
  
  if (t==3 & inc3=="y")

  {
    tablead3.style.position='absolute';
 tablead3.style.top=10;
tablead3.style.left=hpo;
  tablead2.style.position='absolute';
 tablead2.style.left=-3330;
 count=count1+8;
  var recur_call = "countdown()";
setTimeout(recur_call, count);
 
 }
 if (t==3 &inc3=="n")
 {
  tablead1.style.position='absolute';
 tablead1.style.top=10;
tablead1.style.left=hpo;

 tablead2.style.position='absolute';
 tablead2.style.left=-3330;
  count=0;
  tim=0;
  var recur_call = "countdown()";
setTimeout(recur_call, count);


  } 
 
 if (t==4 & inc4=="y")

  {
    tablead4.style.position='absolute';
 tablead4.style.top=10;
tablead4.style.left=hpo;
  tablead3.style.position='absolute';
 tablead3.style.left=-3330;
  count=count1+5;
  var recur_call = "countdown()";
setTimeout(recur_call, count); 

 }
 if (t==4 & inc4=="n")
 {
  tablead1.style.position='absolute';
 tablead1.style.top=10;
tablead1.style.left=hpo;
 tablead3.style.position='absolute';
 tablead3.style.left=-3330;

   count=0;tim=0;
  var recur_call = "countdown()";
setTimeout(recur_call, count);

  } 
if (t==5 & inc5=="y")

  {
    tablead5.style.position='absolute';
 tablead5.style.top=10;
tablead5.style.left=hpo;
  tablead4.style.position='absolute';
 tablead4.style.left=-3330;
  count=count1+7;
  var recur_call = "countdown()";
setTimeout(recur_call, count); 

 }
 if (t==5 & inc5=="n")
 {
  tablead1.style.position='absolute';
 tablead1.style.top=10;
tablead1.style.left=hpo;
 tablead4.style.position='absolute';
 tablead4.style.left=-3330;

   count=0;tim=0;
  var recur_call = "countdown()";
setTimeout(recur_call, count);

  }
  if (t==6 & inc6=="y")

  {
    tablead6.style.position='absolute';
 tablead6.style.top=10;
tablead6.style.left=hpo;
  tablead5.style.position='absolute';
 tablead5.style.left=-3330;
  count=count1;
  var recur_call = "countdown()";
setTimeout(recur_call, count); 

 }
 if (t==6 & inc6=="n")
 {
  tablead1.style.position='absolute';
 tablead1.style.top=10;
tablead1.style.left=hpo;
 tablead5.style.position='absolute';
 tablead5.style.left=-3330;

   count=0;tim=0;
  var recur_call = "countdown()";
setTimeout(recur_call, count);

  }
  if (t==7 & inc7=="y")

  {
    tablead7.style.position='absolute';
 tablead7.style.top=10;
tablead7.style.left=hpo;
  tablead6.style.position='absolute';
 tablead6.style.left=-3330;
  count=count1;
  var recur_call = "countdown()";
setTimeout(recur_call, count); 

 }
 if (t==7 & inc7=="n")
 {
  tablead1.style.position='absolute';
 tablead1.style.top=10;
tablead1.style.left=hpo;
 tablead6.style.position='absolute';
 tablead6.style.left=-3330;

   count=0;tim=0;
  var recur_call = "countdown()";
setTimeout(recur_call, count);

  }
  if (t==8 & inc8=="y")

  {
    tablead8.style.position='absolute';
 tablead8.style.top=10;
tablead8.style.left=hpo;
  tablead7.style.position='absolute';
 tablead7.style.left=-3330;
  count=count1;
  var recur_call = "countdown()";
setTimeout(recur_call, count); 

 }
 if (t==8 & inc8=="n")
 {
  tablead1.style.position='absolute';
 tablead1.style.top=10;
tablead1.style.left=hpo;
  tablead7.style.position='absolute';
 tablead7.style.left=-3330;

   count=0;tim=0;
  var recur_call = "countdown()";
setTimeout(recur_call, count);

  }
  if (t==9 & inc9=="y")

  {
    tablead9.style.position='absolute';
 tablead9.style.top=10;
tablead9.style.left=hpo;
  tablead8.style.position='absolute';
 tablead8.style.left=-3330;
  count=count1;
  var recur_call = "countdown()";
setTimeout(recur_call, count); 

 }
 if (t==9 & inc9=="n")
 {
  tablead1.style.position='absolute';
 tablead1.style.top=10;
tablead1.style.left=hpo;
  tablead8.style.position='absolute';
 tablead8.style.left=-3330;

   count=0;tim=0;
  var recur_call = "countdown()";
setTimeout(recur_call, count);

  }
  if (t==10 & inc10=="y")

  {
    tablead10.style.position='absolute';
 tablead10.style.top=10;
tablead10.style.left=hpo;
  tablead9.style.position='absolute';
 tablead9.style.left=-3330;
  count=count1;
  var recur_call = "countdown()";
setTimeout(recur_call, count); 

 }
 if (t==10 & inc10=="n")
 {
  tablead1.style.position='absolute';
 tablead1.style.top=10;
tablead1.style.left=hpo;
  tablead9.style.position='absolute';
 tablead9.style.left=-3330;

   count=0;tim=0;
  var recur_call = "countdown()";
setTimeout(recur_call, count);

  }
  //once all ads seen - recycle 
 if (t>=nofads)
 {t=0;z=1;
 count=count1;
 //alert("t= "+t+"    and count= "+count);
 } 
  }
}
Number.prototype.toMinutesAndSeconds = function() {
// convert numeric seconds input to minutes and seconds string output
  var nn, curTime = new Date(this * 1000);
  return nn=curTime.getMinutes() + ":" +
      (((nn=curTime.getSeconds())<10)?"0"+nn:nn);
}

function invis() 
{
tablead1.style.left=-3330;
tablead2.style.left=-3330;

}

