

/* Google maps =====================================================================*/

function initialize_map() 
{
	var latlng = new google.maps.LatLng(55.958158,-3.169186);

	var myOptions = 
	{
		zoom: 17,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
			
	var map = new google.maps.Map(document.getElementById("map_canvas"), 				myOptions);
				
	/*var image = new google.maps.MarkerImage('images/map_icon.png',

		new google.maps.Size(93, 91),// The origin for this image is 0,0.		
		new google.maps.Point(0,0)// The anchor for this image is the base of the flagpole at 0,32.
	);*/
					
	/*var marker = new google.maps.Marker(
	{
		position: latlng,
		title:"Hello World!",
		animation: google.maps.Animation.DROP,
		icon: image	
	});	
  
  	// To add the marker to the map, call setMap();
  	marker.setMap(map);  */
}

$(document).ready(function() 
		{			
			initialize_map();
		});
		


/* Carousel controls =====================================================================*/

var map_menu_details = new Array
(
[ "Frances Durack & Paul Roger", "5 Alva Place" ],
[ "Abbeyhill Primary", "Abbey Street" ],
[ "James Gamgee", "28 Regent Place" ],
[ "Lisa Graham & Denis Mallon", "10 Regent Place" ],
[ "Annabell Wolf", "40 Waverley Place" ],
[ "Hannah Reynolds & Emma Aitken", "24 Waverley Place" ],
[ "Gill Smith", "3 Waverley Place" ],
[ "Anne Marie's Teas and Home Baking", "37 Carlyle Place" ],
[ "Mary Drummond, Rona MacLean, ...", "29 Carlyle Place" ],
[ "Mic D Galanos, Seán Ó Cathasaigh, ...", "24 Carlyle Place" ],
[ "Heather Anderson & Caroline Welsh", "2 Carlyle Place" ],
[ "William Mazur", "16 Carlyle Place" ],
[ "Simone Clarke & Martin McKenna", "3f3, 3 Salmond Place" ]
)

var carousel_playlist = new Array() // used to prevent duplicate randomisation
var carousel_delay = 7 // time between transitions (in secs)
var carousel_img_num = new Number();

function get_random_image()
{
	carousel_img_num = Math.round( Math.random() * (map_menu_details.length-1) ) + 1;
	//var carousel_img_num = 8;		
	
	if( carousel_playlist.length == map_menu_details.length )
	{
		carousel_playlist = [];
		//$("#debug").append( "+++++++++++++++++" + "<br/>" );
	}
	
	while ( !check_is_unique(carousel_img_num) ) //check number isn't in playlist already
	{
		// if it is, generate new number
		carousel_img_num = Math.round( Math.random() * (map_menu_details.length-1) ) + 1;
	}
	
	carousel_playlist.push(carousel_img_num);	
	//$("#debug").append( "result: " + carousel_img_num + "<br/>" );
		
	//checks number against all playlist entries so far
	function check_is_unique( input_num ) 
	{
		var is_unique = true;
		
		for (n in carousel_playlist)
		{
			if( input_num == carousel_playlist[n] )
			{
				is_unique = false;
				break;
			}
		}		
		return is_unique;
	}
	
	populate_carousel();
}

function populate_carousel()
{
	$('#map-menu .number').css // reset numbers on map
			({
			'transform': 'scale(0.9, 0.9)',
			'-moz-transform': 'scale(0.9, 0.9)',
			'-ms-transform': 'scale(0.9, 0.9)',
			'-webkit-transform': 'scale(0.9, 0.9)',
			'-o-transform': 'scale(0.9, 0.9)',
			'-moz-transform': 'scale(0.9, 0.9)'
			});
			 
	$('#map-menu #no-' + carousel_img_num ).css // enlarge selected number
		({
		'transform': 'scale(1.1, 1.1)',
		'-moz-transform': 'scale(1.1, 1.1)',
		'-ms-transform': 'scale(1.1, 1.1)',
		'-webkit-transform': 'scale(1.1, 1.1)',
		'-o-transform': 'scale(1.1, 1.1)',
		'-moz-transform': 'scale(1.1, 1.1)'
		});
	
	// fade carousel out
	$('#img-container').animate( { opacity: '0' }, 200, function() 
	{
		$('#img-container img').attr("src", "img/carousel_img_" + carousel_img_num + ".jpg" );
		
		$('#img-container .number').replaceWith( 
			'<div class="number"><span>' + 
			carousel_img_num +
			'</span></div>'
		);
		
		$('#img-container #artist').replaceWith( 
			'<p id="artist"><strong>' + 
			map_menu_details[carousel_img_num-1][0] +
			'</strong></p>'
		);
		
		$('#img-container #address').replaceWith( 
			'<p id="address"><strong>' + 
			map_menu_details[carousel_img_num-1][1] +
			'</strong></p>'
		);
		
		$('#img-container').animate( { opacity: '1' }, 500 ); // fade everything in
		
		
	});	
}
		
$(document).ready( function() 
{
	get_random_image();
	
	var carousel_timer = setInterval( "get_random_image()", carousel_delay * 1000 );
	
	$('#img-container').mousedown( function() 
	{	
		$('html, body').animate(
		{
			scrollTop: $("#artist-details-" + carousel_img_num).offset().top - 50
		}, 1500 );
	});
	
	$('.back-to-top').mousedown( function() 
	{	
		$('html, body').animate(
		{
			scrollTop: 0
		}, 1500 );
	});
	
	$('#location-link').mousedown( function() 
	{	
		$('html, body').animate(
		{
			scrollTop: $("#location").offset().top
		}, 1500 );
	});
	
	$('#buses-link').mousedown( function() 
	{	
		$('html, body').animate(
		{
			scrollTop: $("#buses").offset().top
		}, 1500 );
	});
	
	// clicking map menu, selects carousel image
	$('#map-menu .number').mousedown( function()
	{	
		clearInterval( carousel_timer );
		
		carousel_img_num = $(this).attr( "id" ).substring( 3 );
		
		populate_carousel();
	});
	
	$(window).scroll( function() 
	{
  		//$("#debug").append( $(window).height() + ", " + $(document).height() + "<br/>" );
		var scroll_perc = $(document).scrollTop() / $(document).height();
		var bg_pos = scroll_perc * 500 * -1;
		
		//$("#debug").append( bg_pos + "<br/>" );
		
		$("body").css( "background-position", "center " + bg_pos + "px" );
	});
});
