

var len = img_paths.length;
var img = new Array(len);
var start = 0;
var counter = 0;
var delayTime = 3;
var tempo = 3;


for(i = 0; i < len; i++)
{
  img[i] = new Image();
  img[i].src = img_paths[i];
}


/******************************************
 * Function for getting the user selected
 * delay time for each slide. If nothing
 * was selected, it sets the default delay
 * time to 3 seconds.
 ******************************************/
function getDelayTime(dlTime)
{
  var temp = parseInt(dlTime);

  if(temp != NaN)
  {
    delayTime = temp * 1000;
  }

  else
  {
    delayTime = 4000;
  }
}


/******************************************
 * Function for running the slide show,
 * enabling and disabling buttons on time.
 ******************************************/
function anim()
{
  if(counter < len)
  {
    document.initPic.src = img[counter++].src;
  }

  else
  {
    clearInterval(start);
    with(document.frm_js_img_slider)
    {
      stShow.disabled = false;
      btnBack.disabled = false;
      btnNext.disabled = false;
      spShow.disabled = true;
    }
  }
}


/******************************************
 * Function for starting the slide show,
 * enabling and disabling buttons on time.
 ******************************************/
function slide()
{
  getDelayTime(document.frm_js_img_slider.delay.value);
  with(document.frm_js_img_slider)
  {
    start = setInterval("anim();", delayTime);
    stShow.disabled = true;
    btnBack.disabled = true;
    btnNext.disabled = true;
    spShow.disabled = false;
  }
}


/***********************************************
 * Function to enable the going to the previous
 * image, if available.
 ***********************************************/
function back()
{
  if(counter >= 1)
  {
    document.initPic.src = img[--counter].src;
  }
}


/*******************************************
 * Function to enable the going to the next
 * image, if available.
 *******************************************/
function next()
{
  if(counter < (len - 1))
  {
    document.initPic.src = img[++counter].src;
  }
}


/********************************************
 * Function for stoping the auto slide show.
 ********************************************/
function stopSlide()
{
  clearInterval(start);
  with(document.frm_js_img_slider)
  {
    stShow.disabled = false;
    btnBack.disabled = false;
    btnNext.disabled = false;
    spShow.disabled = true;
  }
}


/******************************************
 * Function for increasing the delay time.
 ******************************************/
function incDelay()
{
  tempo++;

  if(tempo >= 60)
  {
    tempo = 60;
  }

  document.frm_js_img_slider.delay.value = tempo;
}


/******************************************
 * Function for decreasing the delay time.
 ******************************************/
function decDelay()
{
  tempo--;

  if(tempo <= 1)
  {
    tempo = 1;
  }

  document.frm_js_img_slider.delay.value = tempo;
}
