$(function() {


	/* set correct content height */
	function setContentHeight() {
		//$.equalHeights(getCurrentContent().height() + getCurrentContent().offset().top + ((ie) ? 40 : 20));
	}

	/* get content associated with current tab */
	function getCurrentContent() {
		return $($.map($("div.tabs li.current a"), function(obj, i) {
			return obj.hash;
		}).join());
	}

	/* show current content and adjust content height */
	function showCurrentContent() {
		$("div.tab_container > div.tab").hide();
		getCurrentContent().show();
		setContentHeight();
	}

	/* tab click handler */
	$("div.tabs a").live( 'click', function(e) {

		/* set clicked tab to current */
		$(this).parents("ul:first").find("> li.current").removeClass("current active");
		$(this).parent().addClass("current active");


		if (typeof statCounterName != "undefined") {
			sitestat("http://nl.sitestat.com/rivm/kiesbeter/s?" + statCounterName + "." + e.target.hash.substring(1));
		}
		
		showCurrentContent();

		/* prevent page jumping */
		e.preventDefault();
		
		if(!$(this).closest(".tabs").hasClass("nobookmark")) {
      var scrollposition= window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
      //window.location.hash = $(this).attr('href');
      scrollTo(0, scrollposition);
    } 
	});
	
	$("div.tabs ul").each( function(i, item){
    $(this).parent().height($(this).height());
    if($(this).height() > "21") {
      $(this).addClass('multiplerows');
    }
  });
	
	/* Jump to the right tab directly from the url */
 	if(window.location.hash != "" && $(window.location.hash).is("*")) {
    $("div.tabs li a[href='"+window.location.hash+"']").click().parent().addClass("active");
  } else {
	 $("div.tabs li.current").addClass("active").find("a").click();
  }
});
