/**
 * native.js
 */

var mynative = {
	
	init: function() {

		$('.vans-photos span.alt').fadeOut('fast');
		
		$('.vans-photos a').hover(function() {
			$(this).find('.alt').fadeIn('fast');
		}, function() {
			$(this).find('.alt').fadeOut('fast');
		});
		
		mynative.init_van_popups();
		
		mynative.init_availability();
		
	}
	
	,init_van_popups: function() {
		
		$('area').click(function() {
			var id = $(this).attr('id');
			return true;
		});
		
	}
	
	,init_availability: function() {
		$('.bookingtable td').each(function() {
			if( !$(this).hasClass('firstcell') ) {
				if( $(this).html() != '' && $(this).html() != '<span>&nbsp;</span>' && $(this).html() != '&nbsp;' ) {
					$(this).addClass('booked').html('&nbsp;');
				}
			}
		});
	}
	
	,table_headers: function() {

		var tbar = false;
		var topheight = 500;
		
		$('.bookingtable').before('<table class="bookingtable" id="bookingtable_copy" border="0" width="800" style="width:800px;"><thead><tr class="firstline"><th>&nbsp;</th><th colspan="12">Vans</th></tr><tr class="firstline"><th width="16%">Date</th><th colspan="2" width="14%">Jimi</th><th colspan="2" width="14%">Ella</th><th colspan="2" width="14%">Ringo</th><th colspan="2" width="14%">Molly</th><th colspan="2" width="14%">Lucy</th><th colspan="2" width="14%">Eric</th></tr><tr><th class="firstcell" nowrap="nowrap">&nbsp;</th><th>(am)</th><th>(pm)</th><th class="alt">(am)</th><th class="alt">(pm)</th><th>(am)</th><th>(pm)</th><th class="alt">(am)</th><th class="alt">(pm)</th><th>(am)</th><th>(pm)</th><th class="alt">(am)</th><th class="alt">(pm)</th></tr></thead></table>');

		$('#bookingtable_copy').css({
			position: 'fixed'
			,top:0
		}).hide();
		
		$(window).scroll(function() {
			if( $(this).scrollTop() >= topheight ) {
				if( !tbar ) {
					$('#bookingtable_copy').css('top', '-70px').show().animate({'top':0}, 'slow');
					tbar = true;
				}
			}
			if( $(this).scrollTop() < topheight ) {
				if( tbar ) {
					$('#bookingtable_copy').fadeOut('fast');
					tbar = false;
				}
			}
		});

	}
	
};

$(document).ready(mynative.init);
