﻿$(document).ready(function() {
	var map = new GMap2(document.getElementById('google-map'));
	map.setCenter(new GLatLng(-25.335448, 135.745076), 4); //Sydney
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	SetupPins();
	initTabs();
	function SetupPins() {
			
			$.each($('#location-json').children(), function(i, val) {

				var latlng = $("em", this).hide().text().split(",");
				var point = new GLatLng(latlng[0], latlng[1]);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(val, { maxWidth: 200 });
				});

			});
		
	}


	function initTabs() {
	
		
	
		$('.locations a').bind('click', function(e) {
			e.preventDefault();
			var thref = $(this).attr("href").replace(/#/, '');
			$('#tabMenu a').removeClass('active');
			$(this).addClass('active');
			$('#tabContent div.content').removeClass('active');
			$('#' + thref).addClass('active');

			if (thref == 'australia') {
				map.setCenter(new GLatLng(-25.335448, 135.745076), 3); //Sydney
			}
			if (thref == 'asia') {
				map.setCenter(new GLatLng(3.326986, 102.414551), 6); //Malaysia
			}
			if (thref == 'nz') {
				map.setCenter(new GLatLng(-41.607228, 175.166016), 4); //New Zealand
			}
		});

		var t = setInterval(function() {
			if (LoadCountry != undefined) {
				if ($(".CultureButton[value*=New]").attr("disabled") == true)
					$("#mapNav li a[href=#nz]").trigger('click').focus();
				clearInterval(t);
				t = null;
			}
		}, 10);

	}

});

