$(window).load(function() {

	function initializeMap(){
		$('#searchlocations').hide();
		$('#map').fadeOut(500, function(){
			$('#map').empty().css({
				width: '620px',
				height: '731px',
				backgroundImage: 'url(/images/map/strangfordmap.jpg)',
				position: 'relative'
			});
			$('#map').fadeIn();
			loadBullets('coast', false);
		});
	}

	
	
	function loadBullets(id, back){
		$('#map').load('/history/' + id + '?count=25', {}, function(){
			//add back button
			
			//place bullets
			$(this).children('a.bullet').each(function(){
				var coords = $(this).attr('rel').split('-');
				$(this).css({left: coords[0] + 'px', top: coords[1] + 'px'})
					   .hide()
					   .fadeIn()
					   .click(function(){showPopup($(this).attr('id'));});
			});
		});
	}
	
	function showPopup(id){
		$('#map div.popup').fadeOut(); 
		var boxid = '#' + id + '-box';
		$(boxid).fadeIn();
		$('a.close').click(function(){
			$(this).parent().fadeOut();
		});
	}
	
	

	
	//initialize map
	initializeMap();
	

});