/* This script is written as an optional extra to the tablesort.js stuff.  It gives all of the <th>s that can be clicked a title="" attribute so that when you hover over them they say "sort by Cheese Type" or whatever.   Otherwise it's not very clear - especially to non computer-savvy types - that clicking in a table header sorts the table by that column.

Note: This will break if the <th>s contain html tags.  Well it wont break, but they wil end up in the title attributes.

It would be nice to improve this at some point so that the title attributes contain "sort by Cheese Type (ascending)" or "sort by Cheese Type (descending)", but it's not worth doing at the mo, as it involves:
	* Setting that text on page load (already done below, but commented out)
	* Adding an onclick to each <th> to change the (asc) or (desc) when someone clicks one of the <th>s to sort the table
	*Dealing with the nightmare of determining whether the table sorting javascript is running first or the onclick event for changing the (asc)/(desc).

*/


function init(){
	if(!document.getElementsByTagName("body").length){//if the body hasn't loaded yet
		zyx=setTimeout("init();", 100);//try again
	}
	else{
		ths = document.getElementsByTagName('th');
		sdfljk = setTimeout("add_th_titles();",2000); //add the titles, but we need to leave a delay until the tablesort.js has sorted itself out
	}
}
init();

function add_th_titles(){
	for(i=0; i<ths.length; i++){
		if(ths[i].className.match(/sortcol/) && !ths[i].className.match(/nosort/)){
			//set the title on it
			ths[i].title = 'Sort by '+ ths[i].innerHTML.stripTags(); //relies on Prototype for stripTags()
			/* stuff for if you want (asc)/(desc) as well...
			if(ths[i].hasClassName('sortdesc'))
				direction = 'desc';
			else
				direction = 'asc';
			ths[i].title = 'Sort by '+ ths[i].innerHTML +' ('+ direction +')';
			//put onclick stuff here (see above)*/
		}
	}
}
