
var currcnt = 1;  //start the loop from the 2nd image
var images = new Array;
var isPaused = 0;
 var frontDiv = "bgDiv1";
 var backDiv =  "bgDiv2";
 var t;

function fnc_init()
{
 preLoadImages ()
 fnc_rotateBG ()
}

function preLoadImages ()
{

 var counter = 0;
 var arrCounter = 0;

 
 while (counter <100)
 {
   var obj = document.getElementById("bg-image-" + counter);
   if (obj) //if this object exists, push into the array
   {
     images [arrCounter] = obj;
     arrCounter++;
   }
  counter++;
 }
}

function fnc_rotateBG ()
{
   var urlString = "";
   var text = ""
   var imageID = ""
   
   if (!(images[currcnt]))
      currcnt = 0;

   urlString = "url(" +images[currcnt].src +")";
   imageID = images[currcnt].id
   text = document.getElementById(imageID).title;
  
   document.getElementById(backDiv).style.display = 'none' ;//hide to remove abrupt transition
   document.getElementById(backDiv).style.backgroundImage = urlString ;
   document.getElementById('tdImageText').innerHTML = text ;
   
   Fade(backDiv,frontDiv)
   currcnt = currcnt + 1;
   
   //switch which of the divs is in front or behind, so you are always switching the image in the backdiv
   //the back div is hidden so that the image switch transitions smoothly
   
   if (frontDiv == "bgDiv1")
      {frontDiv = "bgDiv2";
        backDiv =  "bgDiv1";}
   else
      { frontDiv = "bgDiv1";
        backDiv =  "bgDiv2";}
        
   t = setTimeout(fnc_rotateBG,20000); //20000
  
}
function Fade(fade_in, fade_out)
{
      
  	  new Effect.Appear(fade_out, { duration: 5.0, from: 1.0, to: 0.0} );
      new Effect.Appear( fade_in, { duration: 5.0, from: 0.0, to: 1.0 } ); 
 }

   
function fnc_stepBack ()
{
  clearTimeout(t)
   if (currcnt > 1)
    {currcnt = currcnt - 2 ;
    }
   
  else 
    {
      currcnt = images.length - 2

    }
   
   fnc_rotateBG ();

}

function fnc_stepForward ()
{
  clearTimeout(t)
  if (!(images[currcnt]))
      currcnt = 0;
   fnc_rotateBG ();
  
}


function fnc_pauseRotation ()
{
  //alert (isPaused )
  if (isPaused ==0 )
     { isPaused  = 1
       clearTimeout(t)
       document.getElementById('btnPLAY').style.display = ''
       document.getElementById('btnPAUSE').style.display = 'none'       
     }
  else
  {
    isPaused = 0
    document.getElementById('btnPLAY').style.display = 'none'
    document.getElementById('btnPAUSE').style.display = ''       
    fnc_rotateBG ()
    
  }
   
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function FP_swapImgRestore() {//v1.0
 var doc=document,i; if(doc.$imgSwaps) { for(i=0;i<doc.$imgSwaps.length;i++) {
  var elm=doc.$imgSwaps[i]; if(elm) { elm.src=elm.$src; elm.$src=null; } } 
  doc.$imgSwaps=null; }
}

