
var vergelijk, vergelijknum = 0;
$(document).ready(function() {
	vergelijk = new Array();
	$(".comp a").click(function(event) {
		r = $(this).attr("rel");
		
		if($("#compare .rij"+ r).length == 0) {
			vergelijk[vergelijknum] = r;
			vergelijknum++;
			l = $("#compare tr").length;
			
			$("#compare .no").hide();
			c = $("#compare .no").clone();
			c.removeClass('no');
			c.addClass('rij' + r);
			c.appendTo($("#compare"));
			c.find(".number").text(l);
			c.find(".name_school").text($("#name" + r).text());
			c.show();
			
			reNumber();
			
			$.get("ajax.php", {module:"rijschool",action:"vergelijk",id:r});
		}
		event.preventDefault();
	});
	$(".remove").live("click", function() {
		if($(this).parents("tr").hasClass("no")) {
		} else {
			r = $(this).parents("tr").attr("id");
			num = r.replace('rij','');
			$.get("ajax.php", {module:"rijschool",action:"ontvergelijk",id:num});
			
			$(this).parents("tr").detach();
			reNumber();
		}
	});
	if($("#rijschool").length) {
		initRijschool();
	}
});
function reNumber() {
	if($("#compare tr").length == 1) {
		$("#compare .no").show();
	} else {
		$("#compare tr").each(function(i) {
			if(i > 0) {
				$(this).find(".number").text(i);
			}
		});
	}
}
var activeRijschoolTab;
function initRijschool() {
	if(location.hash) {
		tab = location.hash.replace("#", "");
	} else {
		tab = jQuery.url.param("tab");
	}

	if(tab != undefined) {
		$("#" + tab).parent("li").addClass("active");
		y = -1;
	} else {
		y = 0;
	}

	$("#tabs a").each(function(i) {
		if(i > y) {
			if ($(this).attr("name") == tab) {
				$(this).parent("li").addClass("active");
				activeRijschoolTab = $(this);
			} else {
				$("." + $(this).attr("name")).hide();
			} 
		} else {
			$(this).parent("li").addClass("active");
			activeRijschoolTab = $(this);
		}
		
		
		$(this).click(function(e) {
			e.preventDefault();
			n = $(this).attr("name");
			if($("." + n).is(":visible")) {
			} else {
				
				$(activeRijschoolTab).parent("li").removeClass("active");
				$(this).parent("li").addClass("active");
				
				last = $(activeRijschoolTab).attr("name");
				activeRijschoolTab = $(this);
				
				$("." + last).fadeOut("fast", function() {
					$("." + n).fadeIn("fast");
				});
			}
			
		});
	});
}

