function submitCalendar(){
	$("form.change_calendar").submit();
};


$.ajaxHistory.initialize();
$(document).ready(function() {
	// do stuff when DOM is ready

	// collect all tab sections
	var tab_sections = [];
	$.each($('#content > div'), function() {
		var id = $(this).attr('id');
		if ( id.substring(id.length-1) == '_' ) {
			tab_sections.push( '#' + id );
		}
	});

	// initialize view state
	$('.hideMe').hide();
	show_tab(location.hash+'_');


	// switch tabs on click
	$('a').click(function(){
		show_tab($(this).attr('href')+'_');
	});

	function show_tab(hash) {
		// if there is no location hash, show the first tab
		if (hash == '_') {
			$.each(tab_sections, function() {
				$('div' + this).hide();
			});

			$('div'+tab_sections[0]).show();
			$(".contentFoot").hide().show(); // prevent ie from mucking up the rendering of bottom corners
			return false;
		}
		// if there's a div to switch to
		else if ($.inArray(hash, tab_sections) != -1) {
			$.each(tab_sections, function() {
				$('div' + this).hide();
			});

			if ($('div'+hash).attr('display') != 'none') $('div'+hash).show();
			$(".contentFoot").hide().show(); // prevent ie from mucking up the rendering of bottom corners
			return false;
		}
		// nothing to do otherwise
	}

	
	// slideshow for individual boats
	$('#boatSlideshow').cycle({ 
    	fx:    'fade', 
   		speed:  2000,
   		pause:  4
   	});

	$('#boatSlideshowBig').cycle({ 
    	fx:    'fade', 
   		speed:  2000,
   		pause:  4
   	});


	// ----------------------------- calendar ----------------------------- //
	
	$("#showsubmit").hide();
	
	var changed = false;
	
	$("form.change_calendar select").change(function(){
		changed = true;
		if (undefined!==window.calendar_submit) window.clearTimeout(calendar_submit);
		window.calendar_submit = setTimeout("submitCalendar()", 1500)
	}).focus(function(){
		if (changed) {
			if (undefined!==window.calendar_submit) window.clearTimeout(calendar_submit);
			window.calendar_submit = setTimeout("submitCalendar()", 2500)
		}
	}).blur(function(){
		if (changed) {
			if (undefined!==window.calendar_submit) window.clearTimeout(calendar_submit);
			window.calendar_submit = setTimeout("submitCalendar()", 1500)
		}
	});

});
