var $LeftPane = null;
var $TopPane = null;
var $BottomPane = null;
var $Content = null;
var $WintertourLogo = null;
var $StageLinks = null;
var $StageDetails = null;
var stages = {
	"s1": { "information": true, "results": true, "splittimes": true, "splitalyzer": true, "pictures": "https://picasaweb.google.com/115285431954256896003/1Wintertour20112012" },
	"s2": { "information": true, "results": true, "splittimes": true, "splitalyzer": true, "special": true, "pictures": "https://plus.google.com/u/0/photos?tab=wq#photos/115285431954256896003/albums/5684522956348184561" },
	"s3": { "information": true, "results": true, "splittimes": true, "splitalyzer": true, "special": true },
	"s4": { "information": true, "results": true, "splittimes": true, "splitalyzer": true, "special": true, "pictures": "https://picasaweb.google.com/hsvwrnolat/9Wintertour2011124Lauf" },
	"s5": { "information": true, "results": true, "splittimes": true, "splitalyzer": true, "special": true },
	"s6": {},
	"s7": {}
}

function __init() {
	$LeftPane = $("#wt-left-pane");
	$TopPane = $("#wt-top-pane");
	$BottomPane = $("#wt-bottom-pane");
	$Content = $("#wt-content");
	$WintertourLogo = $LeftPane.find("> img");
	$StageLinks = $("#wt-stage-links");
	$StageDetails = $("#wt-stage-details");

	__resize();
}

function __resize() {
	var wintertourLogoHeight = $WintertourLogo.height();
	var topPaneHeight = $TopPane.height();
	var bottomPaneHeight = $BottomPane.height();
	var totalHeight = topPaneHeight + bottomPaneHeight;
	
	$WintertourLogo.css("height", totalHeight + "px");
}

function __select($Elem, stage) {
	$StageDetails.hide();
	$StageDetails.html("");
	$(".active").removeClass("active");
	$Elem.addClass("active");

	if (stages[stage].information)
		$StageDetails.append("<a href='http://www.hsvwrn-ol.at/german/events/informationen/2012/wintertour" + stage.substring(1) + ".pdf' target='_blank'>Laufinformation</a>");

	if (stages[stage].results)
		$StageDetails.append("<a href='http://www.hsvwrn-ol.at/german/events/ergebnisse/2012/wintertour" + stage.substring(1) + ".pdf' target='_blank'>Ergebnisse</a>");

	if (stages[stage].splittimes)
		$StageDetails.append("<a href='http://www.hsvwrn-ol.at/german/events/splittimes/2012/wintertour" + stage.substring(1) + ".htm' target='_blank'>Zwischenzeiten</a>");

	if (stages[stage].splitalyzer)
		$StageDetails.append("<a href='http://www.hsvwrn-ol.at/java-bin/splitalyzer/ergebnisse/2012/wintertour" + stage.substring(1) + ".htm' target='_blank'>Splitalyzer</a>");

	if (stages[stage].special)
		$StageDetails.append("<a href='http://www.hsvwrn-ol.at/german/events/ergebnisse/2012/wintertour" + stage.substring(1) + "_spezialwertung.pdf' target='_blank'>Spezialwertung</a>");

	if (stages[stage].pictures)
		$StageDetails.append("<a href='" + stages[stage].pictures + "' target='_blank'>Fotos</a>");
		
	if (!$StageDetails.html())
		$StageDetails.append("<p>Es sind noch keine Details f&uuml;r diesen Lauf verf&uuml;gbar.</p>");
	
	$StageDetails.show();
}

function __get($Elem, url) {
	$BottomPane.css("background-image", "url(./img/ajax-loading.gif)");
	$(".active").removeClass("active");
	$Elem.addClass("active");
	$.ajax({
		url: url,
		success: function(data, textStatus, jqXHR) {
			$Content.html(data);
			$BottomPane.css("background-image", "none");
			delete data, textStatus, jqXHR;
		}
	});
}
