jQuery(function($){
	var tab = window.location.hash || '#service';
	tab = tab.substr(1, tab.length - 1);
	function selectTab(tab){
		$('.tabs li').removeClass('selected');
		$('.tabSections>li').hide();
		$('.tabs .'+tab).addClass('selected');
		$('#'+tab).show();
		preventScroll(tab);
	}
	$('html, body').scrollTop(0);
	$('.tabs a').click(function(e){
		var t = $(this).attr('href');
		selectTab(t.substr(1, t.length - 1));
	});
	function preventScroll(id){
		var ele = $('#'+id).removeAttr('id');
		var tmp = $('<div/>').attr('id', id).css({'position':'fixed', 'top':'0', 'left':'0'});
		$(document.body).append(tmp);
		setTimeout(function(){
			tmp.remove();
			ele.attr('id', id);
		}, 100);
	}

	var links = $('.selectCol a').click(function(e){
		var parent = $(this).parent();
		var tabSec = $(this).parents('.tabSection:first');
		var dept = tabSec.attr('id');
		var con = tabSec.find('.activeCon').empty().hide();
		$.get(this.href, function(html){
			con.show();
			con.append(html);
			var h = tabSec.height();
			var top = parent[0].offsetTop - con.height()/2 + parent.height()/2;
			if(top + con.height() > h){
				top = h - con.height();
			}
			if(top < 0) top = 0;
			con.css('margin-top', top+'px');
		}, 'html');
		parent.siblings().removeClass('selected');
		parent.addClass('selected');
		e.preventDefault();
		return false;
	});
	
	$('.locationsCon, .activeCon').empty();
	selectTab(tab);
});
