/**
 * General JS for TER
 *
 * @author Nick Nettleton
 * @copyright 2008 Loft Digital / www.loftdigital.com
 */
/*global queue*/
var stop_clicking = false;
var hack_needed = false;

function niceties() {
	// min height for low-content pages
	var c = document.getElementById('content');
	if (c && c.offsetHeight < 280) {
		c.style.height = '280px';
	}

	// make listing tables nice
	var els = document.getElementsByTagName('table');
	for (var i = 0, l = els.length; i < l; i++) {
		if (!els[i].className.match(/(^|\s)listing(\s|$)/)) {
			continue;
		}
		for (var j = 0, m = els[i].rows.length; j < m; j += 1) {
			var row = els[i].rows[j];
			if (!(j % 2)) {
				row.className = 'alt';
			}
			row.onmouseout	= function () {
				this.className = this.oc;
			};
			row.onmouseover	= function () {
				this.oc = this.className;
				this.className = 'over'; 
			};
			var x = row.getElementsByTagName('a');
			if (x.length == 1) {
				row.onclick		= function () {
					// if there's a link in the first col, apply it to the whole row
					var td = this.getElementsByTagName('td');
					if (td.length) {
						var a = td[0].getElementsByTagName('a');
						if (a.length) {
							var click = true;
							if (a[0].onclick) {
								click = a[0].onclick();
							}
							if (click && a[0].href) {
								location.href = a[0].href;
							}
						}
					}
					
				};
			} else if (x.length > 1 ){
				var td = row.getElementsByTagName('td');
				for (var z = 0; z < td.length; z += 1) {
					var a = td[z].getElementsByTagName('a');
					if (a.length == 0) {
						td[z].onclick = function () {
							var a = this.parentNode.getElementsByTagName('a');
							if (a[0].onclick) {
								click = a[0].onclick();
							}
							if (click && a[0].href) {
								location.href = a[0].href;
							}
						}
					} else if (a.length == 1) {
						td[z].onclick = function () {
							var a = this.getElementsByTagName('a');
							var click = true;
							if (a[0].onclick) {
								click = a[0].onclick();
							}
							if (click && a[0].href) {
								location.href = a[0].href;
							}
						}
					}
				}
			}
			var td = row.getElementsByTagName('td');
			if (td.length && td[0].getElementsByTagName('a').length) {
				row.style.cursor = 'pointer';
			}
		}
	}
}
queue(niceties);
