function getPointDistance(coords,pointList) {
	var c = coords.match(/\((\d+),(\d+)\)/) || ['','0','0'], distance = [0,0], tempdistance, x, y;
	c[1] = parseInt(c[1]);
	c[2] = parseInt(c[2]);
	for( var i = 0; i < pointList.length; i++ ) {
		x = c[1] - pointList[i][0];
		y = c[2] - pointList[i][1];
		tempdistance = Math.sqrt( ( x * x ) + ( y * y ) );
		if( !i || tempdistance < distance[1] ) {
			distance = [i,tempdistance];
		}
	}
	return distance;
}
function columnSorting(table,column,bydefault,typesort,coords) {
	var sorthead = table.getElementsByTagName('thead')[0].getElementsByTagName('th')[column];
	if( bydefault ) {
		table.lastclicked = sorthead;
		sorthead.className = 'sorted';
	} else {
		sorthead.className = 'clickable';
	}
	sorthead.appendChild(document.createElement('a'));
	sorthead.lastChild.href = '#';
	sorthead.lastChild.appendChild(sorthead.firstChild);
	sorthead.firstChild.onclick = function () {
		table.lastclicked.className = 'clickable';
		if( typesort == 2 ) {
			//supposedly clever; it puts them in order of closest reference point, sorted by distance from that point - sortof logical progression through areas
			sortTableRows(table,column,function (a,b,cellA,cellB) {
				if( !cellA.distance ) {
					cellA.distance = getPointDistance(a,coords);
					//cellA.innerHTML = cellA.distance[0]+' '+cellA.innerHTML;
				}
				if( !cellB.distance ) {
					cellB.distance = getPointDistance(b,coords);
					//cellB.innerHTML = cellB.distance[0]+' '+cellB.innerHTML;
				}
				if( cellA.distance[0] == cellB.distance[0] ) {
					return cellB.distance[1] - cellA.distance[1];
				} else {
					return cellB.distance[0] - cellA.distance[0];
				}
			},true,0);
		} else if( typesort == 1 ) {
			sortTableRows(table,column,true,true,0);
		} else {
			sortTableRows(table,column,function (c,d) {
				var oPadding = unescape('%00');
				c = c.toLowerCase().replace(/[\s-\/']/g,'');
				d = d.toLowerCase().replace(/[\s-\/']/g,'');
				while( c.length > d.length ) { d += oPadding; }
				while( d.length > c.length ) { c += oPadding; }
				return ( c == d ) ? 0 : ( ( d < c ) ? -1 : 1 );
			},true,0);
		}
		table.lastclicked = this.parentNode;
		this.parentNode.className = 'sorted';
		return false;
	};
}