/**
 * @author tom bran
*/
//Creates a queue of functions to be executed when the page loads using addLoadEvent(functionName);
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}

$(document).ready(function(){
// use title attribute for value in form field - by tommy bran
	var input = $(".useTitleForValue");
	input.attr({"value": input.attr("title")})
	input.addClass("inactive")
	
	input.focus(function(){
		if ($(this).val() == input.attr("title")) {
			input.removeAttr("value");
			input.removeClass("inactive");
		}
	})
	input.blur(function(){
		if ($(this).val() == "") {
			input.attr({"value": $(".useTitleForValue").attr("title")});
			input.addClass("inactive");
		}
	})
	
});

function showPic(ourloc) {
	if (!document.getElementById("mainImg")) return true;
  var source = ourloc.getAttribute("href");
  var placeholder = document.getElementById("mainImg");
  placeholder.setAttribute("src",source);
  
  // Addition by Dan Forys
  // 12th Sept 2008
  // Change CSS classes of links
  // First remove any 'selected' links
  $('#galleryHolder a.galleryThumb').removeClass('selected');
  // Now add the selected class to the event element
  $(ourloc).addClass('selected'); 
  
  return false;
	}

function prep() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("galleryHolder")) return false;
  var gallery = document.getElementById("galleryHolder");
  var links = gallery.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {
      return showPic(this);
    }
  }
}


addLoadEvent(prep)
