﻿function prepareGallery() {
  if (!document.getElementsByTagName) {
    return false;
  }
  var links = document.getElementsByTagName("a");
  var iclass;
  for (var i=0; i<links.length; i++) {
    iclass = links[i].getAttribute("class");
    if (!iclass) {
      iclass = links[i].getAttribute("className");
    }
    if ((iclass == "popthumb")|(iclass == "pthumb")|(iclass == "bthumb")){
      links[i].onmouseover = function() {
        return highlight(this);
      }
      links[i].onmouseout = function() {
        return deHighlight(this);
      }
      links[i].onclick = function() {
        return openPopUp(this);
      }
    }
  }
}

function openPopUp(item) {
  var destination = item.getAttribute("href");
  window.open (destination,'item','height=440,width=660');
  return false;
}

function highlight(item) {
  var destination = "thumbs/" + item.getAttribute("id") + "H.gif";
  item.firstChild.setAttribute("src",destination);
  return false;
}

function deHighlight(item) {
  var destination = "thumbs/" + item.getAttribute("id") + ".gif";
  item.firstChild.setAttribute("src",destination);
  return false;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(prepareGallery);
