/* --- JavaScript Document --- */
/* --------- gallery --------- */


initGallery = function() {
	var thumbs, thumbLinks, canvas;
	if (!(thumbs = document.getElementById('thumbs'))) return false;
	if (!(canvas = document.getElementById('canvas'))) return false;
	if (!(thumbLinks = thumbs.getElementsByTagName('a'))) return false;
	for (t=0; t<thumbLinks.length; t++) {
		var thumbLink = thumbLinks[t];
		var thumb;
		if (!(thumb = thumbLink.getElementsByTagName('img')[0])) continue;
		thumbLink.canvasElm = canvas;
		thumbLink.image = thumb.src;
		thumbLink.captionTxt = (thumb.title && thumb.title != "") ? thumb.title : thumb.alt;
		thumbLink.onclick = function() {
			this.canvasElm.innerHTML = "<img src='" + this.image.replace('thumb_','') + "' alt='' /><br />" + this.captionTxt;
			return false;
		}
	}
}

if (document.getElementById && document.getElementsByTagName) {
	addLoadEvent(initGallery);
}

// expand list of functions to be triggered on onload
// call: addLoadEvent(functionName); or addLoadEvent(function() { more code to run on page load });
// from: http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
