function MM_findObj(n, d)
{ //v4.01
  var p,i,x;
  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length)
  {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if (!(x=d[n])&&d.all)
    x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++)
    x=d.forms[i][n];
  for (i=0;!x&&d.layers&&i<d.layers.length;i++)
    x=MM_findObj(n,d.layers[i].document);
  if (!x && d.getElementById)
    x=d.getElementById(n);
  return x;
}

function getX( oElement )
{
  var iReturnValue = 0;
  while( oElement != null )
  {
    iReturnValue += oElement.offsetLeft;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}

function showHideLayers(Layers, TurnOn, ParentID)
{ //v6.0
  var i,p,v,obj;
  var ParentObj, LeftOffset;

  ParentObj = document.getElementById(ParentID);
  LeftOffset = ParentObj ? getX(ParentObj) : 0;
  for (i=0; i<(Layers.length); i++)
  {
    if ((obj = document.getElementById(Layers[i])) != null)
    {
      if (obj.style)
      {
        st = obj.style;
        v = (TurnOn == Layers[i]) ? 'visible' : 'hidden';
        display = (TurnOn == Layers[i]) ? 'block' : 'none';
        v=(v=='show')?'visible':(v=='hide')?'hidden':v;
        st.visibility = v;
        st.display = display;
        if (TurnOn == Layers[i])
          st.left = LeftOffset + "px";
      }
    }
  }
}

function pviiClassNew(obj, new_style)
{
  obj.className = new_style;
}


// gives up and down scroll buttons to images, spans, ... named up_name, down_name, respectively.
// will keep the default scroll_box's style overflow if it encounters errors (so make overflow: auto;)

// usage: put this after the scrollbox div:  var div_scroll1 = new TextScroll('div_scroll1', 'scroll_box');
function TextScroll(scrollname, div_name, up_name, down_name, top_name, bottom_name)
{
    this.div_name = div_name;
    this.name = scrollname;
    this.scrollCursor = 0;
    this.speed = 5;
    this.timeoutID = 0;
    this.div_obj = null;
    this.up_name = up_name;
    this.dn_name = down_name;
    this.top_name = top_name;
    this.bottom_name = bottom_name;

    {
        if (document.getElementById) {
            div_obj = document.getElementById(this.div_name);
            if (div_obj) {
                this.div_obj = div_obj;
                this.div_obj.style.overflow = 'hidden';
            }
            div_up_obj = document.getElementById(this.up_name);
            div_dn_obj = document.getElementById(this.dn_name);
            div_top_obj = this.top_name ? document.getElementById(this.top_name) : false;
            div_bottom_obj = this.bottom_name ? document.getElementById(this.bottom_name) : false;

            if (div_up_obj && div_dn_obj) {
              div_up_obj.onmouseover = function() { eval(scrollname + ".scrollUp();") };
              div_up_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
              div_dn_obj.onmouseover = function() { eval(scrollname + ".scrollDown();") };
              div_dn_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
            }
            if (div_top_obj) {
              div_top_obj.onclick = function() { eval(scrollname + ".resetScroll();") }
              div_top_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
            }
            if (div_bottom_obj) {
              div_bottom_obj.onclick = function() { eval(scrollname + ".scrollBottom();") }
              div_bottom_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
            }
        }
    }

    this.stopScroll = function() {
        clearTimeout(this.timeoutID);
    }

    this.scrollUp = function() {
        if (this.div_obj) {
            this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollUp()", 60);
        }
    }

    this.scrollDown = function() {
        if (this.div_obj) {
            this.scrollCursor += this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            if (this.div_obj.scrollTop == this.scrollCursor) {
              this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);
            } else {
              this.scrollCursor = this.div_obj.scrollTop;
            }
        }
    }

    this.scrollBottom = function() {
        if (this.div_obj) {
            this.div_obj.scrollTop = this.div_obj.scrollHeight;
            this.scrollCursor = this.div_obj.scrollTop;
        }
    }

    this.resetScroll = function() {
        if (this.div_obj) {
            this.div_obj.scrollTop = 0;
            this.scrollCursor = 0;
        }
    }
}

function ShowPic(Index)
{
  Img = document.getElementById("GalleryPic");
  if (Img)
  {
    Pic = Images[Index];
    Link = Links[Index];
    Img.innerHTML = "<a href=\"" + Pic + "\" target=_blank><img src=showthumb.php?pic=" + Link + "&size=large></a>";
  }
  else
    alert("Couldn't get GalleryPic element");

  Previous = document.getElementById("edsPrevious");
  if (Previous)
  {
    if (Index > 0)
    {
      PrevIndex = Index - 1;
      Previous.innerHTML = "<a href=#gallery_table onclick=\"ShowPic(" + PrevIndex + ")\"><img src=images/previous.jpg border=0 alt=previous /></a>";
    }
    else
      Previous.innerHTML = "&nbsp;";
  }
  else
    alert("Couldn't get Previous element");

  Next = document.getElementById("edsNext");
  if (Next)
  {
    if (Index < (Images.length-1))
    {
      NextIndex = Index + 1;
      Next.innerHTML = "<a href=#gallery_table onclick=\"ShowPic(" + NextIndex + ")\"><img src=images/next.jpg border=0 alt=next /></a>";
    }
    else
      Next.innerHTML = "&nbsp;";
  }
  else
    alert("Couldn't get Next element");

}

