$(document).ready(function() {

		var resetReady = false;

		//Views Switching
		$("#services_table").hide();
	
		$("#category_view").click(function () {
			$("ul#services").show();
			$("#services_table").hide();
		});
	
		$("#list_view").click(function () {
			$("ul#services").hide();
			$("#services_table").show();
		});

		//Search
		$('table#services_table tbody tr').quicksearch({
			reset: false,
			//resetId: 'reset_view',
			//resetClass: "resetButton",
			//resetLabel: "Reset Table",
			position: 'append',
			attached: 'div#views',
			stripeRowClass: ['odd', 'even'],
			labelText: '',
			inputText: 'Find a service',
			onAfter: function(){
				//$("div#views a#reset_view").css("display","block");
				resetReady = true;
			}
		});

		$("input.qs_input").focus(function () {
			$("ul#services").hide();
			$("#services_table").show();
		});


		//Sort by Category or Letter
		function categorySort(hashString){
			if ( hashString.length >= 1 ){
				$("ul#services").hide();
				$("#services_table").show();
				hashString = hashString.substring(1);
				$("#services_table tr").removeClass("highlight"); //Clear previous highlights

				//Is it by Letter
				if ( hashString.length == 1 || hashString == "all" ){
					$("#services_table").tablesorter( {sortList: [[0,0]]} );
				}
				//Or is it by Category
				else {
					$("#services_table").tablesorter( {sortList: [[1,0]]} );
				}
				$("#services_table tr." + hashString).addClass("highlight").prependTo($("#services_table"));
				//$("div#views a#reset_view").css("display","block");
				resetReady = true;
			}
			else {
				$("#services_table").tablesorter( {sortList: [[0,0]]} );
			}
		};

		//Sort on Load
		categorySort(document.location.hash);
		//Sort on In-Page Service Menu Click
		$("div#nav_services a").click(function (){
			hashString = $(this).parent().attr("id");
			hashString = "#" + hashString.substring(9);
			categorySort(hashString);
		});
		//Sort on In-Page Letter Menu Click
		$("div#sub_views a").click(function (){
			hashString = $(this).attr("href");
			categorySort(hashString);
		});
		//Sort on In-Page Category View Categories
		$("ul#services li h3 a").click(function (){
			hashString = $(this).attr("href");
			categorySort(hashString);
		});
		//Sort on In-Page Table Categories
		$("#services_table tbody tr td:nth-child(2) a").click(function (){
			hashString = $(this).attr("href");
			categorySort(hashString);
		});
		
		
		//Reset View
		$("div#views a#reset_view").click(function () {
			//hashString = "";
			//categorySort(hashString);
			window.location="/its/services/";
		});






























});

