// JavaScript Document
//Tables and Tabs JavaScript

$(document).ready(function() { 
	//for tabs
	$("#tabs > ul").tabs();
	//Sort the tables
	var alternateRowColors = function($table) { 
		$('tbody tr:odd', $table).removeClass('even').addClass('odd') 
		$('tbody tr:even', $table).removeClass('odd').addClass('even') 
	} 

	$('table.sortable').each(function() { 
		var $table = $(this) 
		alternateRowColors($table) 
		$('th', $table).each(function(column) { 
			if ($(this).is('.sort-alpha')) { 
				$(this).addClass('clickable').hover(function() { 
					$(this).addClass('hover') 
				}, function() { 
					$(this).removeClass('hover') 
				}).click(function() { 
					var rows = $table.find('tbody > tr').get() 
					rows.sort(function(a, b) { 
					var keyA = $(a).children('td').eq(column).text().toUpperCase() 
					var keyB = $(b).children('td').eq(column).text().toUpperCase() 
					if (keyA < keyB) return -1 
					if (keyA > keyB) return 1 
					return 0 
				}) 
				$.each(rows, function(index, row) { 
					$table.children('tbody').append(row) 
				}) 
				alternateRowColors($table) 
			}) 
		} 
	}) 
	}) 

});


//coloring table rows
$(document).ready(function() {
	var rowIndex = 0
	$('tbody tr').each(function(index) {
		if ($('th',this).length) {
			$(this).addClass('subhead')
			rowIndex = -1
		} else {
			if (rowIndex % 2 < 1) {
				$(this).addClass('even')
			}
			else {
			$(this).addClass('odd')
			}
		}
		rowIndex++
	})
})
