window.onload = function() {
	addThumbLinksEvents();
}

// add hover events to all gallery thumbnail links
function addThumbLinksEvents() {
	var x;
	var thumbs = document.getElementById('colour-thumbs');
	var thumbLinks = thumbs.getElementsByTagName('a');
	var thumbTitle = document.getElementById('thumbTitle');
	
	for (x = 0; x<thumbLinks.length; x++) {
		var tText = (thumbLinks[x].title);
		addEvent(thumbLinks[x], 'mouseover', updateThumbTitle, false);
		addEvent(thumbLinks[x], 'mouseout', updateThumbTitle, false);
		// addEvent(thumbLinks[x], 'onclick', updateThumbTitle, false);
	}
}

// toggle title on mouseover/mouseout
function updateThumbTitle() {
	var thumbTitle = document.getElementById('thumbTitle'); 
	
	if (this.title == thumbTitle.firstChild.nodeValue) {
		thumbTitle.firstChild.nodeValue = '';
	} else {
		thumbTitle.firstChild.nodeValue = this.title;
	}
}

// add event
function addEvent(obj, evType, fn, useCapture) {
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent) {
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    // do nothing
  }
}