//#########################################
//## Copyright EZi Software All rights reserved
//#########################################

function CMyImageSlide(sClassName)
{
  var m_sClassName = sClassName;

  var m_bIsIE = false;
  var m_sDIVName = "";
  var m_nWidth = 0;
  var m_nHeight = 0;
  var m_arImageListSmall = "";
  var m_arImageListSmallOnClick = "";
  var m_arImageListSmallLoaded = "";
  var m_nNumberOfImages = 0;
  var m_nNumberOfImagesToDisplay = 0;

  var m_nScrollPosition = 0;
  var m_nFromPos = 0;
  var m_nToPos = 0;
  var m_nStep = 10;

  var m_pTimerID = 0;
  var m_pSlider;

  this.Init = Init;
  this.OnLoad = OnLoad;
  this.Display = Display;
  this.MoveLeft = MoveLeft;
  this.MoveRight = MoveRight;
  this.fMoveRight = fMoveRight;
  this.fMoveLeft = fMoveLeft;
  this.fKillTimer = fKillTimer;

  function Init(sDIVName, nWidth, nHeight, arImageListSmall, arImageListSmallOnClick, nNumberOfImages, nNumberOfImagesToDisplay)
  {
    uagent = window.navigator.userAgent.toLowerCase();
    m_bIsIE=(uagent.indexOf('msie') != -1)?true:false;
    m_bIsIE = false;

    m_sDIVName = sDIVName;
    m_nWidth = nWidth;
    m_nHeight = nHeight;
    m_arImageListSmall = arImageListSmall;
    m_arImageListSmallOnClick = arImageListSmallOnClick;
    m_arImageListSmallLoaded = arImageListSmall;
    m_nNumberOfImages = nNumberOfImages;
    m_nNumberOfImagesToDisplay = nNumberOfImagesToDisplay;
  }

  function OnLoad()
  {
    for(var i=parseInt(m_nNumberOfImagesToDisplay); i<m_arImageListSmall.length; i++)
    {
      var oImg = document.getElementById("p"+i);
      oImg.src = m_arImageListSmall[i];
    }
  }

  function Display()
  {
    if(m_sDIVName!="")
    {
      if(m_bIsIE==true)
      {}
      else
      {
        document.write("<div style='position:absolute;width:"+m_nHeight+";height:"+(parseInt(m_nWidth)*parseInt(m_nNumberOfImagesToDisplay))+";clip:rect(0 "+m_nHeight+"  "+(parseInt(m_nWidth)*parseInt(m_nNumberOfImagesToDisplay))+" 0);'>");
        document.write("<div id='"+m_sDIVName+"' style='position:relative;height:"+(parseInt(m_nWidth)*parseInt(m_nNumberOfImagesToDisplay))+";'>");

        for(var i=0; i<m_arImageListSmall.length; i++)
        {
          var sSmallImageLink = m_arImageListSmall[i];
          if(i>parseInt(m_nNumberOfImagesToDisplay)) sSmallImageLink = "img/px.gif";

          document.write("<img id=\"p"+i+"\" name=\"p"+i+"\" style=\"cursor: pointer\" src=\""+sSmallImageLink+"\" width=\"80\" height=\"80\" alt=\"\" border=\"0\" onclick=\""+m_arImageListSmallOnClick[i]+"\" /><br/>");
        }

        document.write("</div>");
        document.write("</div>");

        m_pSlider = document.getElementById(m_sDIVName);
        m_pSlider.style.visibility="visible";
        m_pSlider.style.left=0;
      }
    }
  }

  function MoveRight()
  {
    if(m_nScrollPosition>0)
    {
      fKillTimer();
      m_nFromPos = m_nScrollPosition * parseInt(m_nWidth);
      m_nToPos = (m_nScrollPosition-1) * parseInt(m_nWidth);
      m_nScrollPosition--;
      m_pTimerID = setTimeout(m_sClassName+".fMoveRight()", 10);
    }
  }

  function MoveLeft()
  {
    if(m_nScrollPosition<(m_nNumberOfImages-parseInt(m_nNumberOfImagesToDisplay)))
    {
      fKillTimer();
      m_nFromPos = m_nScrollPosition * parseInt(m_nWidth);
      m_nToPos = (m_nScrollPosition+1) * parseInt(m_nWidth);
      m_nScrollPosition++;
      m_pTimerID = setTimeout(m_sClassName+".fMoveLeft()", 10);
    }
  }

  function fMoveLeft()
  {
    if(m_bIsIE==true)
    {}
    else
    {
      m_nFromPos = m_nFromPos + m_nStep;
      if(m_nFromPos>m_nToPos)
      {
        m_pSlider.style.top=-m_nToPos;
      }
      else
      {
        m_pSlider.style.top=-m_nFromPos;
        m_pTimerID = setTimeout(m_sClassName+".fMoveLeft()", 20);
      }
    }
  }

  function fMoveRight()
  {
    if(m_bIsIE==true)
    {}
    else
    {
      m_nFromPos = m_nFromPos - m_nStep;
      if(m_nFromPos<m_nToPos)
      {
        m_pSlider.style.top=-m_nToPos;
      }
      else
      {
        m_pSlider.style.top=-m_nFromPos;
        m_pTimerID = setTimeout(m_sClassName+".fMoveRight()", 20);
      }
    }
  }

  function fKillTimer()
  {
    if(m_pTimerID)
    {
      clearTimeout(m_pTimerID);
      m_pTimerID = 0;
    }
  }
}

