var picturewindow;

window.onload = function () {
   var anchors = document.getElementsByTagName("a");
   var xpos=(screen.width - 640)/2
   var ypos=(screen.height - 480)/2
   for (var i=0; i<anchors.length; i++) {
     rel = anchors[i].getAttribute("rel");
     switch(rel) {
       case "external":
         anchors[i].onclick = function() {
           window.open(this.href);
           return false;
         }
       break;
      case "picture" : 
         anchors[i].onclick = function() {
           if (picturewindow) picturewindow.close();
           picturewindow = window.open("image.html?picture=" + escape(this.href) + "&title=" + escape(this.title), "", 
              "scrollbars=no,status=no,toolbar=no,location=no,directories=no,resizable=no,menubar=no,width=640,height=480," +
              "screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos
           );
           return false;
         }
      break;
      case "thumbnail" :
        anchors[i].onclick = function() {
          picture = document.getElementById('picture'+this.id.substr(1,2));
          thumbnail = document.getElementById('i'+this.id.substr(1))
          picturelink = document.getElementById('picture-link'+this.id.substr(1,2));
          picturesrc = thumbnail.src.substr(0, thumbnail.src.length-6);
          picture.src =  picturesrc + '-g.jpg';
          picturelink.href = picturesrc + '-f.jpg';
          a = document.getElementsByTagName("a")
          for (var i=0; i<a.length; i++) {
            if (a[i].getAttribute("rel") == "thumbnail" && a[i].id.substr(0, 3) == this.id.substr(0, 3)) {
              a[i].className = "";
            }
          } 
          this.className = "active"
          return false;
        }
      break; 
     }
   }
}
