// JavaScript Document

// function for homepage tabs
var currentTab = 0; // Set to a different number to start on a different tab.

function openTab(clickedTab) {
	var thisTab = $(".tabbed-box .tabs a").index(clickedTab);
	$(".tabbed-box .tabs li a").removeClass("active");
	$(".tabbed-box .tabs li a:eq("+thisTab+")").addClass("active");
	$(".tabbed-box .tabbed-content").hide();
	$(".tabbed-box .tabbed-content:eq("+thisTab+")").show();
	currentTab = thisTab;
}


$(document).ready(function() { 
	//for content page tabs
	$("#tabs > ul").tabs();
	
	//change the colors of the rows of a table
	var alternateRowColors = function($table) { 
		$('tbody tr:odd', $table).removeClass('even').addClass('odd') 
		$('tbody tr:even', $table).removeClass('odd').addClass('even') 
	} 
	//make a table sortable
	$('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) 
			}) 
		} 
	}) 
	}) 
		//Make a table filterable
	 //add index column with all content.   
 $(".filterable tr:has(td)").each(function(){   
   var t = $(this).text().toLowerCase(); //all row text   
   $("<td class='indexColumn'></td>")   
    .hide().text(t).appendTo(this);   
 });//each tr   
 $("#FilterTextBox").keyup(function(){   
   var s = $(this).val().toLowerCase().split(" ");   
   //show all rows.   
   $(".filterable tr:hidden").show();   
   $.each(s, function(){   
       $(".filterable tr:visible .indexColumn:not(:contains('"  
          + this + "'))").parent().hide();   
   });//each   
 });//key up.   
	$(".viewAll").click(function() {
		$(".filterable tr:hidden").show();
	})
	
	// for home page content tabs
	$(".tabs li:eq(0) a").css("border-left", "none");
	
	$(".tabbed-box .tabs li a").click(function() { 
		openTab($(this)); return false; 
	});
	
	$(".tabbed-box .tabs li a:eq("+currentTab+")").click()	
	
	
//Code for show/hide dropdown menus

	//For DDC How do I dropdown
		$('#IWantTo').change(function() {
    	$('#taskContainer div').hide('slow');            // added a bit of animation
    	var e = '#' + $(':selected', $(this)).attr('name');
    	$(e).show('slow');                             // while we change the feed
		});

		$('#taskContainer div').hide();
	
		
		//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");
	}); 
 
	
})

