/*

 ' Program - JavaScript Image Slider
 ' File Name - js_img_slider.js
 ' Author - Shovon
 ' Email - shuvorim@yahoo.com
 ' Web site - http://www29.websamba.com/shovon
 ' (C) ShuvoRim Pvt. Ltd.
 ' All rights reserved.

 ' Mailing Address-
 ' North Palace (8th Floor), Flat-9A
 ' 75, North Road, Dhanmondi
 ' Dhaka-1205, Bangladesh.


 ' This program is free software; you can redistribute it and/or modify
 ' it under the terms of the GNU General Public License as published by
 ' the Free Software Foundation; either version 2 of the License, or
 ' (at your option) any later version.

 ' This program is distributed in the hope that it will be useful,
 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ' GNU General Public License for more details.

 ' You should have received a copy of the GNU General Public License
 ' along with this program; if not, write to the Free Software
 ' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/



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


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 4 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;
}
