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

function CMyImageFade(sClassName)
{
  var m_sClassName = sClassName;

  var m_bIsIE = false;
  var m_sDIVName = "";
  var m_nWidth = "";
  var m_nHeight = "";
  var m_arImageList = "";
  var m_arImageListOnClick = "";
  var m_arImageDirection = "";
  var m_sLastImageDirection = "";

  var m_nLastIndex = 0;

  var m_obj_last;
  var m_obj_next;

  var m_pTimerID = 0;

  var m_nCounter = 0;

  this.Init = Init;
  this.OnLoad = OnLoad;
  this.Display = Display;
  this.ShowImage = ShowImage;
  this.FadeImage = FadeImage;
  this.fKillTimer = fKillTimer;

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

    m_sDIVName = sDIVName;
    m_nWidth = nWidth;
    m_nHeight = nHeight;
    m_arImageList = arImageList;
    m_arImageListOnClick = arImageListOnClick;
    m_arImageDirection = arImageDirection;
  }

  function OnLoad()
  {
    //alert("CMyImageFade::OnLoad()");
     for(var i=1; i<m_arImageList.length; i++)
    {
      var oImg = document.getElementById(m_sDIVName+"i"+i);
      oImg.src = m_arImageList[i];
    }
  }

  function Display()
  {
    if(m_sDIVName!="")
    {
      m_sLastImageDirection = m_arImageDirection[0];

      document.write("<div align='center' id='"+m_sDIVName+"' style='position:relative;width:602px;height:602px;overflow:hidden;padding:0px;margin:0px;border-style:solid;border-width:0px;border-color:#FFFFFF;z-index:1;FILTER: progid:DXImageTransform.Microsoft.Fade(Overlap=1.00,duration=0.3,enabled=false);'>");

      for(var i=0; i<m_arImageList.length; i++)
      {
        var sImageLink = m_arImageList[i];
        if(i>0) sImageLink = "img/px.gif";

        var sOnClick = "";
        if(i<(m_arImageList.length-1)) sOnClick = m_arImageListOnClick[i]

        var sVisibility = "hidden";
        if(i==0)
        {
          sVisibility = "visible";
        }

        if(m_arImageDirection[i]=="-")
        {
          document.write("  <div align='center' id='"+m_sDIVName+i+"' style='position:absolute;text-align:center;width:602px;height:451px;visibility:"+sVisibility+";left:0px;top:0px;padding:0px;margin:0px;overflow:hidden;'>");
          document.write("    <img src='img/px.gif' width='1' height='25' /><br/>");
          document.write("    <div align='center' style='background-image:url(gallery/okvirvodoravno.png); width:602px; height:426px;margin-top:0px;'>");
          document.write("      <img src='img/px.gif' width='1' height='40' alt='' /><br/>");
          document.write("      <img style=\"cursor: pointer\" onclick=\""+sOnClick+"\" width=\"520\" height=\"346\" id=\""+m_sDIVName+"i"+i+"\" name=\""+m_sDIVName+"i"+i+"\" src=\""+sImageLink+"\" style=\"position:relative;left:0px;top:0px;padding:0px;margin:0px;border:0px;\" alt=\"\" border=\"0\" />");
          document.write("    </div>");
          document.write("  </div>");
        }
        else
        {
          document.write("  <div align='center' id='"+m_sDIVName+i+"' style='position:absolute;text-align:center;width:426px;height:602px;visibility:"+sVisibility+";left:88px;top:0px;padding:0px;margin:0px;overflow:hidden;'>");
          document.write("    <div align='center' style='background-image:url(gallery/okvirnavpicno.png); width:426px; height:602px;margin-top:0px;'>");
          document.write("      <img src='img/px.gif' width='1' height='40' alt='' /><br/>");
          document.write("      <img style=\"cursor: pointer\" onclick=\""+sOnClick+"\" width=\"346\" height=\"520\" id=\""+m_sDIVName+"i"+i+"\" name=\""+m_sDIVName+"i"+i+"\" src=\""+sImageLink+"\" style=\"position:relative;left:0px;top:0px;padding:0px;margin:0px;border:0px;\" alt=\"\" border=\"0\" />");
          document.write("    </div>");
          document.write("  </div>");
        }
      }
      document.write("</div>");
    }
  }

  function ShowImage(nIndex)
  {
    if((m_sDIVName!="") && (m_nLastIndex!=nIndex))
    {
      if((nIndex>=0) && (nIndex<m_arImageList.length))
      {
        fKillTimer();

        m_nCounter = 0;

        if((m_obj_last) && (m_bIsIE==false))
        {
          m_obj_last.style.visibility="hidden";
        }

        m_obj_last = document.getElementById(m_sDIVName + m_nLastIndex);
        m_obj_next = document.getElementById(m_sDIVName + nIndex);

        if(m_bIsIE==false)
        {
          m_obj_last.style.zIndex=2;
          m_obj_next.style.zIndex=3;

          m_obj_last.style.opacity = 1.00;	
          m_obj_next.style.opacity = 0.00;

          m_obj_last.style.visibility="visible";
          m_obj_next.style.visibility="visible";
        }

        m_pTimerID = setTimeout(m_sClassName+".FadeImage()", 10);

        m_nLastIndex = nIndex;
      }
    }
  }

  function FadeImage()
  {
    // if IE
    if(m_bIsIE==true)
    {
      var pDiv = document.getElementById(m_sDIVName);

      pDiv.filters[0].apply();

      m_obj_last.style.visibility="hidden";	
      m_obj_next.style.visibility="visible";

      pDiv.filters[0].play();
    }
    // if Mozilla
    else
    {
      if(m_nCounter<1)
      {
        m_obj_last.style.opacity = 1.00-m_nCounter;	
        m_obj_next.style.opacity = m_nCounter;

        m_obj_last.style.zIndex=2;
        m_obj_next.style.zIndex=3;

        m_obj_last.style.visibility="visible";
        m_obj_next.style.visibility="visible";

        m_nCounter = m_nCounter + 0.1;

        m_pTimerID = setTimeout(m_sClassName+".FadeImage()", 50);
      }
      else
      {
        m_obj_last.style.visibility="hidden";
        m_obj_next.style.visibility="visible";

        m_obj_last.style.zIndex=2;
        m_obj_next.style.zIndex=3;

        m_pTimerID = 0;
      }
    }
  }

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