function addOverlay(callbackFunc) {
	var overlay = $('<div>');
	overlay.attr('id','overlay');
	$(document.body).css({overflow:'hidden'});
	overlay.css({
		opacity: .6,
		backgroundColor: '#000000',
		width: $(document.body).width(),
		height: $(document.body).height(),
		zIndex: 900,
		position: 'absolute',
		top:   $(window).scrollTop()+'px',
		left: '0px'
	});
	overlay.click(callbackFunc);
	$(document.body).append(overlay);
}
function removeOverlay() {
	$('#overlay').remove();
	$(document.body).css({overflow:'auto'});
}
function openDialog(dialogid) {
	var leftpos = ($(dialogid).parent().width() / 2) - ($(dialogid).width() / 2);
	var toppos = ($(document.body).height() / 2) - ($(dialogid).height() / 2) + $(window).scrollTop();
	$(dialogid).css({ left: leftpos+'px', top: toppos+'px' });
	addOverlay(function() {
		closeDialog(dialogid);
	});
	$(dialogid).show();
	$(dialogid).scrollTop(0);
}
function closeDialog(dialogid) {
	$(dialogid).hide();
	removeOverlay();
}
function closeSponsorForm() {
	$('#contact-errors').html('');
	$('#contact-form')[0].reset();
	closeDialog('#sponsor-form');	
}
function showTab(tabid) {
	$('.tab').each(function() {
		var tid = $(this).attr('id');
		$(this).removeClass(tid+'-on');
		$(this).removeClass('tab-on');
		$('#'+tid+'-content').hide();
	});
	$('#'+tabid).addClass(tabid+'-on');
	$('#'+tabid).addClass('tab-on');
	$('#'+tabid+'-content').show();
	$('#'+tabid+'-content').scrollTop(0);
}
$(document).ready(function() {
	$('.tab').click(function(evt) {
		$('.tab').each(function() {
			var tid = $(this).attr('id');
			$(this).removeClass(tid+'-on');
			$(this).removeClass('tab-on');
			$('#'+tid+'-content').hide();
		});
		var tid = $(this).attr('id');
		$(this).addClass(tid+'-on');
		$(this).addClass('tab-on');
		$('#'+tid+'-content').show();
		$('#'+tid+'-content').scrollTop(0);
	});
	$('#itinerary-link').click(function(evt) {
		openDialog('#itinerary');
		evt.preventDefault();
	});
	$('#close-itinerary-link').click(function(evt) {
		closeDialog('#itinerary');
		evt.preventDefault();
	});
	$('.show-tab4-link').click(function(evt){
		showTab('tab4');
		evt.preventDefault();
	});
	$('#sponsorship-form-link').click(function(evt){
		openDialog('#sponsor-form');
		evt.preventDefault();
	});
	$('#addiction-link').click(function(evt){
		openDialog('#addiction-problem');
		evt.preventDefault();
	});
});
