
$(document).ready(function() {
	wt_runnerstab();
//	wt_navigation();
	wt_autocomplete();
});

function findValue(li) {
	if( li == null ) return alert("No match!");

	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];

	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue;

	//alert("The value you selected was: " + sValue);
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	return row[0];
}

function wt_autocomplete() {
	$("#NameAjax").autocomplete(
		"db/autocomplete_name.php",
		{
			extraParams: { event_code: function() { return $("#EventAjax").val(); } },
			minChars:2,
			onFindValue:findValue,
			formatItem:formatItem,
			selectFirst: false
		}
	);
}

function wt_navigation() {
	$('#navigation li a').append('<span class="hover"></span>');  
	// span whose opacity will animate when mouse hovers.  

	$('#navigation li a').hover(  
		function() {  
			$('.hover', this).stop().animate({  
			'opacity': 1  
			}, 700,'easeOutSine')  
		},  
		function() {  
			$('.hover', this).stop().animate({  
			'opacity': 0  
			}, 700, 'easeOutQuad')  
		})  
}
	
function wt_reviseresults(resp) {
//	alert("Called results table update"); 
	$('#runners').empty();
	$('#runners').html(resp);

	wt_runnerstab();
}

function wt_runnerstab() {
	
	//alert("In Javascript function");
	$('#stripeme tr:even').addClass("shadow");
	$('#stripeme tr').mouseover(function(){$(this).addClass("over");});
	$('#stripeme tr').mouseout(function(){$(this).removeClass("over");});
	
	$('#stripeme tr') .click(function() {
		if ($(this).hasClass('clicked'))
			$(this).removeClass('clicked');
	   	else
			$(this).addClass("clicked");
	});
	
	$('#runners th a') .click(function(event) {
		var attrs = $(this).attr("id");
//		alert("Calling with params: " + attrs);

		event.preventDefault();
//		$('#runners').fadeOut("fast");

		$.ajax({
			type: "GET",
			dataType: "html",
			url: "db/resultstable.php",
			data: attrs,
			success: function(resp) { wt_reviseresults(resp); }
		});

		return false;
	});
}
