$(document).ready(function() {
	$(".row-tabs li").each(function() {
		$(this).click(function() {
			loadTab($(this).attr("id"));
		});
	});
	
	// Direct naar een vervolgtab?
	if (document.location.href.indexOf("/search/tab/val/leerlijnen") > 0) {
		setActiveTab('tabLeerlijnen');
	}
	else if (document.location.href.indexOf("/search/tab/val/beroepsgroep") > 0) {
		setActiveTab('tabBeroepsgroep');
	}
});

var activeTab = null;
function loadTab(tab) {
	if (tab == "tabUitgebreid" && activeTab == tab) {
		window.location = "mailto:info@efe.nl";
		return;
	}
	
	$("#infoLabel").text("Ik wil meer informatie over");
	
	var opleidingId = $("#opleidingId").val();
	if (tab == "tabIntro") {
		showIntroductie(opleidingId);
		$("#sidecol").show();
	}
	else if (tab == "tabUitgebreid") {
		showUitgebreideInfo(opleidingId);
		$("#sidecol").show();
		$("#infoLabel").text("Ik heb een vraag over");
	}
	else if (tab == "tabKosten") {
		showKosten(opleidingId);
		$("#sidecol").show();
	}
	else if (tab == "tabStartdata") {
		showStartdata(opleidingId);
		$("#sidecol").hide();
	}
	else if (tab == "tabVervolg") {
		showVervolgmogelijkheden(opleidingId);
		$("#sidecol").hide();
	}
	else if (tab == "tabAlfabetisch") {
		$("#tabAlfabetischData").show();
		$("#tabBeroepsgroepData").hide();
		$("#tabLeerlijnenData").hide();
		//window.location = "/opleidingsaanbod";
	}
	else if (tab == "tabBeroepsgroep") {
		$("#tabAlfabetischData").hide();
		$("#tabBeroepsgroepData").show();
		$("#tabLeerlijnenData").hide();
		//showBeroepsgroepen();
	}
	else if (tab == "tabLeerlijnen") {
		$("#tabAlfabetischData").hide();
		$("#tabBeroepsgroepData").hide();
		$("#tabLeerlijnenData").show();
		//showLeerlijnen();
	}
	activeTab = tab;
	setActiveTab(tab);
}

function setActiveTab(tab) {
	var curTab = $(".row-tabs .act");
	curTab.removeClass("act");
	curTab.html('<span><span><a href="#">' + curTab.text() + '</a></span></span>');
	
	var activeTab = $("#" + tab);
	activeTab.addClass("act");
	activeTab.html('<span><span>' + activeTab.text() + '</span></span>');
}

/**
 * Opleiding introductie
 * 
 * @param id
 * @return
 */
function showIntroductie(id) {
	$.get("/efe/opleiding-ajax/introductie/id/" + id, function(data) {
		$("#opleidingData").html(data);
	});
}

/**
 * Opleiding uitgebreide info
 * 
 * @param id
 * @return
 */
function showUitgebreideInfo(id) {
	$.get("/efe/opleiding-ajax/uitgebreide-info/id/" + id, function(data) {
		$("#opleidingData").html(data);
	});
}

function showKosten(id) {
	$.get("/efe/opleiding-ajax/overige-kosten/id/" + id, function(data) {
		$("#opleidingData").html(data);
	});
}

/**
 * Opleiding startdata
 * 
 * @param id
 * @return
 */
function showStartdata(id) {
	$.get("/efe/opleiding-ajax/get-startdata-tab/id/" + id, function(data) {
		$("#opleidingData").html(data);
		loadMap(id); // in map.js
	});
}

function showVervolgmogelijkheden(id) {
	$.get("/efe/opleiding-ajax/get-vervolgmogelijkheden-tab/id/" + id, function(data) {
		$("#opleidingData").html(data);
	});
}

function showBeroepsgroepen() {
	$.get("/efe/opleiding-ajax/opleidingen-beroepsgroep", function(data) {
		$("#opleidingData").html(data);
	});
}

function showLeerlijnen(id) {
	$.get("/efe/opleiding-ajax/opleidingen-leerlijnen", function(data) {
		$("#opleidingData").html(data);
	});
}

function toggleVervolgdata(id) {
	var dataRow = $("#vervolgdata" + id);
	if (dataRow.css("display") == "none") {
		dataRow.show();
	}
	else {
		dataRow.hide();
	}
}
