
	window.addEvent('domready', function() {
		var tabElements = $ES("ul.tabs");
		tabElements.addEvent('mouseover', tabsGlow.bindWithEvent(tabElements, "start"));
		tabElements.addEvent('mouseout', tabsGlow.bindWithEvent(tabElements, "stop"));
	//	pageheight = document.getElementById("pagewrapper").clientHeight;

	});


	function tabsGlow (event, startStop) {
		var myTabEffect = new Fx.Styles(event.target, {duration:200});
		if (startStop == "start") {
			myTabEffect.start({
				'margin-top': [3],
				'background-color': ['#00bb55']
			});
		} else {
			myTabEffect.start({
				'margin-top': [4],
				'background-color': ['#aabbdd']
			});
		}
	}


	var TableSorter = new Class({
       		initialize: function(){
			// Initialize Events
			$$("table.ui-sort-table th.ui-sort-col").addEvent('click',this.sortrowsbycolumn.bind(this));
       		},
		sortrowsbycolumn: function(e){
			// Grab Event
			var event = new Event(e);

			// First decide which way to sort
			if (event.target.hasClass('ui-sorted-asc')) var order = 'desc';
			else var order = 'asc';

			// Count which column was clicked
			var sortcol = 0;
			var previous = event.target;
			while (previous = previous.getPrevious()) sortcol++; 
				
			// Find tablerow element (should be parent but loop to be sure)
			var headerrow = event.target;
			while (headerrow.getTag() != 'tr') headerrow = headerrow.getParent();

			// Clear sort-classes from elements
			headerrow.getChildren().each(function(child){
				child.removeClass('ui-sorted-asc').removeClass('ui-sorted-desc');
			});

			// Row clicked is header. Find next siblings.
			var i = 0;
			var row = headerrow;
			var rows = Array();
			while (row = row.getNext()) {
				rows[i] = Array();
				rows[i]['element'] = row;
				var col = 0;
				columns = row.getChildren().each(function(cell){ 
					if (col == sortcol) { rows[i]['value'] = cell.innerHTML; }
					col++;
				});
				i++;

			}


			while (rows.length > 0) {
				// Loop through the rows finding the one that comes first
				var first = '';	var firstkey = '';
				$A(rows).each(function(data,key){
					if (first == '') { first = data['value']; firstkey = key; }
					if ((this.compare(first,data['value']) &&  order == 'asc')
					     || (!this.compare(first,data['value']) &&  order == 'desc')) {
						first = data['value'];
						firstkey = key;
					}
				},this);

				// Put the one that comes first at the top
				rows[firstkey]['element'].injectAfter(headerrow);

				// The ONLY way to delete a row in javascript
				var newrows = Array(); var i = 0;
				$A(rows).each(function(data,key){
					if (key != firstkey) { newrows[i] = data; i++; }
				});
				var rows = Array();
				rows = newrows;
			}

			// Apply Style to Clicked Header
			$(event.target).addClass('ui-sorted-'+order);

		},
		compare: function(a,b){
			// Comparison placed in separate function for future expansion
			// change to lowercase for comparison
			if (a) a = a.toLowerCase();
			if (b) b = b.toLowerCase();
			if (a < b) return true;
			return false;
		}
	});

	window.addEvent('domready', function(){
		tablesorter = new TableSorter();
	});

