var oldLocation = location.href;
var oldHash="";
var baseLangLink="";

$(document).ready(function() {

	if ($("#contentmenu").length>0) {
	
		baseLangLink=$("#langlink > a").attr("href");

		if ($("#contentmenu > li > a")) {
			tabSelect = document.location.hash.substr(1,document.location.hash.length);
			if (tabSelect.length>0) {
				var found=false;
				$("#contentmenu > li > a").each(
					function(intIndex) {
									
						var id=$(this).attr('id');
						if (id==tabSelect) {
							$("#centralarearightmain").jVertTabs({
								selected:intIndex
							});
							found=true;
							return false;
						}
					}
				);
				if (!found) {
					$("#centralarearightmain").jVertTabs();
				}
			} else {
				$("#centralarearightmain").jVertTabs();
			}
		}
		
		changeTab();
	}
});

// Check when the address bar URI changes, so we can switch between tabs.
setInterval(function() {
	if($("#contentmenu").length>0&&location.href != oldLocation) {
		changeTab();
		oldLocation = location.href;
	}
}, 1000); // check every second

function changeTab() {

	$("#langlink > a").attr("href",baseLangLink+document.location.hash);

	if(!noChange&&document.location.hash!='') {

		tabSelect = document.location.hash.substr(1,document.location.hash.length);
		
		if (oldHash!=tabSelect) {
			$("#contentmenu > li > a").each(
				function(intIndex) {
					var id=$(this).attr('id');
					if (id==tabSelect) {
						$("#centralarearightmain").jVertTabs('selected',intIndex);
						return false;
					}
				}
			);
			oldHash=tabSelect;
		}
	} else {
		oldHash=document.location.hash.substr(1,document.location.hash.length);
		noChange=false;
	}
};
