// JavaScript Document

sfHover = function() {
	var sfEls = document.getElementById("navWrapper").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//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) 
			}) 
		} 
	}) 
	}) 
 

	   //javascript for accordion
      //hide the all of the element with class accordion_body
    $(".accordion_body").hide();
      
    //slides the element with class "accordion_body" when paragraph with class "accordion_header" is clicked 
     $("div.accordion_header").click(function() {    
           $(this).toggleClass('active');
           $(this).next("div.accordion_body").slideToggle("normal").siblings("div.accordion_body").slideUp("normal");      
            $(this).siblings("div.accordion_header").removeClass("active");
      }); 

});


//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) {//these were adding classes each time tables were edited, so adding clean up before adding classes 
				$(this).removeClass('odd').removeClass('even').addClass('even')
			}
			else {
			$(this).removeClass('odd').removeClass('even').addClass('odd')
			}
		}
		rowIndex++
	})
})
