/****************************************
(c) 2004-2009 SINTECH Dr.Alexander Stern
*****************************************/

TIME_STAY = 3000;
TIME_CHANGE = 30;
STEP_COUNT = 50;

IMG1 = "slide_show_img1";  // img object names
IMG2 = "slide_show_img2";
IMG_WIDTH = 100;

ImgFiles = new Array();
var img1, img2;  // images

StepIndex = 0;
ImgIndex = 0;

//------------------------------------------------------------------------
function SlideShow()
{

  if (!(img1 = FindObject (IMG1)) || !(img2 = FindObject (IMG2)))
  {
    return;
  }

  for (var i=0; i<SlideShow.arguments.length; i++)
    ImgFiles [ImgFiles.length] = SlideShow.arguments[i];

  LoadImages (ImgFiles);
  Dispatch(); 
}


//------------------------------------------------------------------------
function LoadImages(FileNames)
{
  if(document.images)
  { 
    if(!document.ss_images) 
      document.ss_images=new Array();

    var i, j=document.ss_images.length;

    for(i=0; i<FileNames.length; i++)
    { 
      document.ss_images [j] = new Image; 
      document.ss_images [j].src = FileNames[i];
      j++;
    }
  }
}

//------------------------------------------------------------------------
function FindObject (ObjectName)
{
  var Obj;
  if(!(Obj=document [ObjectName]) && document.all) 
    Obj=document.all [ObjectName]; 

  for (i=0; !Obj && i<document.forms.length; i++) 
    Obj = document.forms[i][ObjectName];

  for(i=0; !Obj && document.layers && i<document.layers.length; i++)  
    Obj = FindObject (ObjectName, document.layers[i].document);

  if(!Obj && document.getElementById) 
    Obj = document.getElementById (ObjectName); 

  return Obj;
}

//------------------------------------------------------------------------
function Dispatch ()
{
  if (StepIndex == 0)
    img1.src = document.ss_images [ImgIndex].src;
    
  img2.width = IMG_WIDTH * StepIndex / STEP_COUNT;
  img1.width = IMG_WIDTH - img2.width;

  if (StepIndex == 0)
    img2.src = document.ss_images [(ImgIndex == ImgFiles.length-1) ? 0 : ImgIndex+1].src;
  
  if (StepIndex == STEP_COUNT)
  {
    StepIndex = 0;
    ImgIndex++;
    if (ImgIndex == ImgFiles.length)
      ImgIndex = 0;
    setTimeout ("Dispatch()", TIME_STAY);
  }
  else
  {
    StepIndex++;
    setTimeout ("Dispatch()", TIME_CHANGE);
  }
}


