
$(document).ready(function(){
		
showMainAreaMap();
getMarinaLocators('#map');	
activateOverlay();
getRaceLocators('#map');
activateClubSearch();
activateClassSearch();
checkForAlertMessage();
slideshow()

showAnchoragesAreaMap()
getAnchorageLocators('#anchorages');	




$('#mapReturn').click(function(){
	
	
	$('#area1').hide(); 


	showMainAreaMap();
	//unBindMarinaLocators();
	getMarinaLocators('#map');
	activateOverlay();
	
	$('#mapReturn').hide();	
	
})// close the click function here	


fadeItem();	
linkToNewWindow();	


$('table.usefulContacts tr:even').addClass('zebra');
	
	
});// close the ready function here	


function checkForAlertMessage()	{
	
	if(alertMessage != "") {
		
		alert(alertMessage)	
	
	}		
		
}


function reloadCAPTCHA() {
	
	document.getElementById('CAPTCHA').src='CAPTCHA/CAPTCHA_image.asp?'+Date();
}


function fadeItem() {
	
$('.fadeMe').mouseover(function(){
	
	$(this).fadeTo('fast', .7);	
	
});

$('.fadeMe').mouseout(function(){
	
	$(this).fadeTo('fast', 1);	
	
});

	
}



function showMainAreaMap() {
	
	
	
// intially hide the marina info div - just in case it's showing
$('#marinaDetailsHolder').hide();

$('#map').hide();

$('#map').show();

//$('#raceDetails').empty();
}

function showAnchoragesAreaMap() {
	
// intially hide the anchorage info div - just in case it's showing
$('#anchorageDetailsHolder').hide();

}
	
function getMarinaLocators(mapId){	


//get the coords for each marinaLocator elem - reposition them - add a click event to call the function
//which displays the appropriate marina info div

$(mapId).children('a.marinaLocator').each(function(){
		
		var coords = ''
		coords = $(this).attr('rel').split('-');
		

		$(this).css({left: coords[0] + 'px', top: coords[1] + 'px'})
		.hide()
		.delay(1000).fadeIn('slow')
		
		var itemId = $(this).attr('id');
		var marinaRef = itemId.substr((itemId.indexOf("_")+1))

		$('#'+itemId).bind('click', function() {
					
			showMarinaDetails(marinaRef)
		
						
		
		});//close click function

		});//close each function

}



function getAnchorageLocators(mapId){	


//get the coords for each anchorageLocator elem - reposition them - add a click event to call the function
//which displays the appropriate anchorage info div

$('#anchorages p').children('a.anchorageLocator').each(function(){
		
		var coords = ''
		coords = $(this).attr('rel').split('-');
		
		$(this).parent().css({left: coords[0] + 'px', top: coords[1] + 'px'})
				

		.hide()
		.delay(1000).fadeIn('slow')
			
		var itemId = $(this).attr('id');
		var anchorageRef = itemId.substr((itemId.indexOf("_")+1))

		$('#'+itemId).bind('click', function() {
					
			showAnchorageDetails(anchorageRef)
						
		
		});//close click function

		});//close each function
		
		

		

}




function getRaceLocators(mapId){	


//get the coords for each raceLocator elem - reposition them - add a click event to call the function
//which displays the appropriate race info in a div


$(mapId).children('a.raceLocator').each(function(){
		
		var coords = ''
		coords = $(this).attr('rel').split('-');
		
		$(this).css({left: coords[0] + 'px', top: coords[1] + 'px'})
		.hide()
		.delay(1000).fadeIn('slow')
		.css({width:coords[2] + 'px', height:coords[3] + 'px'})
		.fadeTo('slow', '0.5')
		
		var itemId = '#' + $(this).attr('id').toLowerCase();					
		var raceAreaRef = itemId.substr((itemId.indexOf("_")+1));
		
				
		$(itemId).bind('click', function() {
						
		$('#raceDetails').empty();
		
		$('#raceDetails').css({
			'height':'354px',
			'margin-top':'10px',
			'margin-bottom':'10px'
		});
		
		$.ajax({
		
			type: 'GET',
			url: 'getRaceInfo.asp',
			data: { id: raceAreaRef },
			success: function(data){ $('#raceDetails').html(data); }	
		
		});	//close ajax call	
		
		
		$('#marinaDetailsHolder').fadeOut('slow');
    	
		
		
	
		});//close click function

		
		});//close each function

}


function activateClubSearch() {
	
	$('#clubId').change(function(){
		
		$('#raceDetails').empty();

		$.ajax({
		
			type: 'GET',
			url: 'getRacesByClub.asp',
			data: { id: $(this).val() },
			success: function(data){ $('#raceDetails').html(data); }	
		
		});	//close ajax call	
	
		$('#raceDetails').css({
			'height':'344px',
			'margin-top':'20px',
			'margin-bottom':'10px'
		});	
	});
	
}



function activateClassSearch() {
	
	$('#eventType').change(function(){
		
		$('#raceDetails').empty();

		$.ajax({
		
			type: 'GET',
			url: 'getRacesByEvent.asp',
			data: { id: $(this).val() },
			success: function(data){ $('#raceDetails').html(data); }	
		
		});	//close ajax call	
	
		$('#raceDetails').css({
			'height':'344px',
			'margin-top':'20px',
			'margin-bottom':'10px'
		});	
	});
	
}




function unBindMarinaLocators(){
	
$('#mapHolder div').children('a.marinaLocator').each(function(){
		
		
		var itemId = '#' + $(this).attr('id').toLowerCase();
						
		$(itemId).unbind('click')	
	
	});

}


function activateOverlay(){


$('#area1_overlay').fadeTo('slow', '.5');

$('#area1_overlay').click(function(){
	
	$(this).hide();
	$('#marinaDetailsHolder').hide();

	$('#area1').fadeIn('slow');
	$('#map').children('a.marinaLocator').hide();
		
	$(this).parent().fadeTo('slow', '1.0');
	
	$('#mapReturn').slideDown(2000).fadeTo('slow', .7);
	
	$('#map').hide();	

	getRaceLocators('#area1');
	getMarinaLocators('#area1')
	});//close click function
		
}



//the function to determine which marina info to display - create a click function to close the div

function showMarinaDetails(marinaRef) {

	
		$('#marinaDetailsHolder').fadeOut('slow');
	
		
	setTimeout(function(){
				
			$('#marinaDetailsHolder div').empty()

			$.ajax({
		
			type: 'GET',
			url: 'getMarina.asp',
			data: { id: marinaRef},
			success: function(data){$('#marinaDetailsHolder div').html(data)}	
		
		})
		

		
		
	$('#marinaDetailsHolder').css({'margin-top':'100px'});
	$('#marinaDetailsHolder').fadeIn(800);
		
	 }, 600);	//close ajax call
	 
	 	
	$('#marinaDetailsHolder h2.close').click(function(){
    $(this).parent().fadeOut('slow');
      
	 });	
  

}


//the function to determine which anchorage info to display - create a click function to close the div

function showAnchorageDetails(anchorageRef) {

	
		$('#anchorageDetailsHolder').fadeOut('slow');
		$('#anchorages img').fadeTo('fast', 1);

		
	setTimeout(function(){
				
			$('#anchorageDetailsHolder div').empty()

			$.ajax({
		
			type: 'GET',
			url: 'getAnchorage.asp',
			data: { id: anchorageRef},
			success: function(data){$('#anchorageDetailsHolder div').html(data)}	
		
		})
		
	
	$('#anchorageDetailsHolder').css('top', $('#anchorages').scrollTop()+30);
	$('#anchorages img').fadeTo('fast', 0.7);
	
	if($('#anchorage_'+anchorageRef).parent().position().left < 350) {
		
		$('#anchorageDetailsHolder').css('left', $('#anchorage_'+anchorageRef).parent().position().left);
		}
		
	else {
		
		$('#anchorageDetailsHolder').css('left', ($('#anchorage_'+anchorageRef).parent().position().left)-350+"px");
		
	}
	

	
	$('#anchorageDetailsHolder').fadeIn(800);
		
	 }, 600);	//close ajax call
	 
	 	
	$('#anchorageDetailsHolder h2.close').click(function(){
    $(this).parent().fadeOut('slow');
  	$('#anchorages img').fadeTo('fast', 1);
    
	 });
	 

  

}


function slideshow(){
	
	//alert("startshow")
		
	var current = $('#slideshowHolder .show');
	var next = current.next().length ? current.next() : current.parent().children(':first');
	
	current.fadeOut(1000).removeClass('show');
	next.fadeIn(1000).addClass('show');
	
	
	setTimeout(slideshow, 6000);
	
}

