
$(document).ready(function(){
	$("div.mid ul.racenavigation:not(.inactive) li a").click(function() {
		var $target_num = $(this).attr("class");
		$(this).parent().siblings().each(function() {
			$(this).removeClass("active");
		});
		$(this).parent().addClass("active");
		var $main_target = $("div.mid ul.racenavigation");
		$main_target.removeClass();
		$main_target.addClass("racenavigation");
		$main_target.addClass($target_num);
		$(this).blur();
	});
	$("table.racedetails tbody tr:not(.active)").hover(function() {
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	});
	$("table.startdetails tbody tr:not(.active)").hover(function() {
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	});
	$("div.racerdetails table tbody tr td").click(function() {
		// function faking ajax-calls and changing active class in left navigation
		$source_obj = $("div.racerdetails table");
		$source_obj.find("tr.active").removeClass("active");
		$(this).parent().addClass("active");
		$target_window = $("div.pagearea div.mid div.main div.racerdetailview");
		$target_window.load("data/source.html","",function() {
			var rannum = 1;
			rannum = rannum+(Math.floor(Math.random()*10));
			$target_window.find("h2").prepend(rannum+" ");	
		});
	});
	$("table.racedetails tbody tr td a").click(function() {
		return false;
	});
	$("table.calendar div.arena:not(.active,.inactive)").hover(function() {
		$(this).addClass("active");
	}, function() {
		$(this).removeClass("active");
	});
	$("table.dubbleup th.title:not(.empty):not(.rowspan)").click(function() {
		if($(this).hasClass("hilite-col")) {
			$("table.dubbleup").each(function() {
				$(this).find("td.hilite-col").removeClass("hilite-col");
				$(this).find("th.hilite-col").removeClass("hilite-col");
			});
		} else {
			var $obj = $(this).attr("class").split(" ");
			$("table.dubbleup").each(function() {
				$(this).find("td.hilite-col").removeClass("hilite-col");
				$(this).find("td."+ $obj[1]).addClass("hilite-col");
				$(this).find("th.hilite-col").removeClass("hilite-col");
				$(this).find("th."+ $obj[1]).addClass("hilite-col");
			});
		}
	});
	$("table.dubbleup tbody td.title:not(.empty):not(.rowspan)").click(function() {
		var $obj = $(this).parent().attr("class");
		if($(this).parent().hasClass("hilite")) {
			$("table.dubbleup").each(function() {
				$(this).find("tr").removeClass("hilite");
			});
		} else {
			$("table.dubbleup").each(function() {
				$(this).find("tr").removeClass("hilite");
				$(this).find("tr[class*="+ $obj +"]").addClass("hilite");
			});
		}
	});
});
