$(document).ready(function(){
	var initialTab = window.location.hash;
	if (initialTab.indexOf('#us') != -1) {
		$('#tab-us a').parents("ul").children("li").removeClass("active");
		$('#tab-us a').parents("li").addClass("active");
		$("#contactUK").hide();
		$("#contactUS").show();
	} else {
		$("#contactUS").hide();
	}
	
	$("#directions").hide();
	$('#tab-uk a').click(function() {
		$(this).parents("ul").children("li").removeClass("active");
		$(this).parents("li").addClass("active");
		$("#contactUS").hide();
		$("#contactUK").show();
		
		$("#directions").fadeOut(500, function() {
			$("#contactForm").fadeIn(500);
		});
		$("#tab-google").removeClass("active");
		$("#tab-flash").addClass("active");
		$("#googlemapuk").hide();
		$("#flashmap").show();
		
		window.location.hash = "uk";
		return false;
	});
	$('#tab-us a').click(function() {
		$(this).parents("ul").children("li").removeClass("active");
		$(this).parents("li").addClass("active");
		$("#contactUK").hide();
		$("#contactUS").show();
		
		$("#directions").fadeOut(500, function() {
			$("#contactForm").fadeIn(500);
		});
		$("#tab-google-us").removeClass("active");
		$("#tab-flash-us").addClass("active");
		$("#googlemapuk").hide();
		$("#flashmap-us").show();
		
		window.location.hash = "us";
		return false;
	});
	$("#tab-google a").click(function(){
		if ($("#directions").children().length > 0) {
			$("#contactForm").fadeOut(500, function() {
				$("#directions").fadeIn(500);
			});
		}
		$("#tab-flash").removeClass("active");
		$("#flashmap").fadeOut(500, function() {
			$("#googlemapuk").css('zIndex','500').fadeIn();
		});
		if(typeof mapPan == 'function') {
			mapPan(PanArray[0]);
		}
		$(this).parents("li").addClass("active");
		return false;
	});
	$("#tab-google-us a").click(function(){
		if ($("#directions").children().length > 0) {
			$("#contactForm").fadeOut(500, function() {
				$("#directions").fadeIn(500);
			});
		}
		$("#tab-flash-us").removeClass("active");
		$("#flashmap-us").fadeOut(500, function() {
			$("#googlemapuk").css('zIndex','500').fadeIn();
		});
		
		if(typeof mapPan == 'function') {
			mapPan(PanArray[1]);
		}
		
		$(this).parents("li").addClass("active");
		return false;
	});
	$("#tab-flash a").click(function(){
		$("#directions").fadeOut(500, function() {
			$("#contactForm").fadeIn(500);
		});
		$("#tab-google").removeClass("active");
		$("#googlemapuk").css('zIndex','1').fadeOut(500, function() {
			$("#flashmap").fadeIn();
		});
		$(this).parents("li").addClass("active");
		return false;
	});
	$("#tab-flash-us a").click(function(){
		$("#directions").fadeOut(500, function() {
			$("#contactForm").fadeIn(500);
		});
		$("#tab-google-us").removeClass("active");
		$("#googlemapuk").css('zIndex','1').fadeOut(500, function() {
			$("#flashmap-us").fadeIn();
		});
		$(this).parents("li").addClass("active");
		return false;
	});
	$("#dirForm").submit(function(){
		$("#tab-flash").removeClass("active");
		$("#tab-google").removeClass("active");
		$("#tab-google").addClass("active");
		$("#flashmap").fadeOut(500, function() {
			$("#googlemapuk").fadeIn();
		});
		setDirectionsUK(this.fromAddress.value);
		$("#contactForm").fadeOut(500, function() {
			$("#directions").fadeIn(500);
		});
		return false;
	});
	$("#dirFormUS").submit(function(){
		$("#tab-flash-us").removeClass("active");
		$("#tab-google-us").removeClass("active");
		$("#tab-google-us").addClass("active");
		$("#flashmap-us").fadeOut(500, function() {
			$("#googlemapus").fadeIn();
		});
		setDirectionsUS(this.fromAddressUS.value);
		$("#contactForm").fadeOut(500, function() {
			$("#directions").fadeIn(500);
		});
		return false;
	});
	
});
