jQuery(document).ready(function() {
//    $('#mainbox').hide();
    $('#busyanim').hide();
//    $('#mainbox').slideDown(2000, function(){
 	$('#mainbox').corner("20px");
        $('div.predbox').corner("10px");
	predict();
//    });
});

function predict()
{
	$('#busyanim').show();
	$('#wprob,#tprob,#lprob').animate({"width": "0%"}, 300);
	$('#ttxt').html("Tie Probability: ?");
	$('#wtxt,#ltxt').html("Win Probability: ?");

	var $ht = $('#hometeam')[0].options[$('#hometeam')[0].selectedIndex].value;
	var $at = $('#awayteam')[0].options[$('#awayteam')[0].selectedIndex].value;
	var $hs = "Normal"; //$('#homespirit')[0].options[$('#homespirit')[0].selectedIndex].value;
	var $as = "Normal"; //$('#awayspirit')[0].options[$('#awayspirit')[0].selectedIndex].value;
	var $qdata = "hometeam=" + $ht + "&awayteam=" + $at + "&homespirit=" + $hs + "&awayspirit=" + $as;

	$.ajax({
		type: "POST",
		url: "query",
		data: $qdata,
		cache: false,
		success: function(d){
			displayprob(d);
		}
	});

	var $hq = "teamname=" + $ht;
	$.ajax({
		type: "POST",
		url: "teamstats",
		data: $hq,
		cache: false,
		success: function(d){
			$('#htstat').html(d);
		}
	});

	var $aq = "teamname=" + $at;
	$.ajax({
		type: "POST",
		url: "teamstats",
		data: $aq,
		cache: false,
		success: function(d){
			$('#atstat').html(d);
		}
	});

	var $mq = "hometeam=" + $ht + "&awayteam=" + $at;
/*
	$.ajax({
		type: "POST",
		url: "matchstats",
		data: $mq,
		cache: false,
		success: function(d){
			$('#games').attr("contentDocument", d);
		}
	});
*/
	$('#games').attr("src", "matchstats?"+$mq);
	$('#games').show();
}

function displayprob(d)
{
	var $arr = d.split(" ");
	
	var $v1 = $arr[0];
	var $v2 = $arr[1];
	var $v3 = $arr[2];

	$('#busyanim').fadeOut(1000);
	$('#wprob').animate({width: $v1}, 300);
	$('#tprob').animate({width: $v2}, 300);
	$('#lprob').animate({"width": $v3}, 300);
	$('#wtxt').html("Win Probability: " + $v1);
	$('#ttxt').html("Tie Probability: " + $v2);
	$('#ltxt').html("Win Probability: " + $v3);
}
