
/* Scripts for Argos Yachtcharter GmbH
 * Copyright © 2002-2008 Inceoeren IT Consulting. All rights reserved. 
 */
 
var map;
 
function mapZoom( a )
{
	map.setZoom( map.getZoom() + a );
}

function mapLoad( x, y, z, maptitle)
{
	if( GBrowserIsCompatible() )
	{
		map = new GMap2( document.getElementById( "googleMap" ) );
		
		document.getElementById( "googleMap" ).style.backgroundColor="white";
		document.getElementById( "googleMapLabelDetail" ).innerHTML = maptitle;
		
		map.setCenter( new GLatLng( x, y ), z );
		map.setMapType( G_HYBRID_MAP );
		//map.addControl( new GSmallMapControl() );
		map.addControl( new GMapTypeControl() );
		map.addControl( new GScaleControl(50) );
		map.enableScrollWheelZoom();
		
		var tooltip = document.createElement( "div" );
		document.getElementById( "googleMap" ).appendChild( tooltip );
		tooltip.style.visibility="hidden";
		
        function markerIcon( type_id, dim_x, dim_y, anchor_x, anchor_y )
        {
        	var icon = new GIcon();
			icon.image = "http://www.argos-yachting.de/images/marker_"+type_id+".png";
			icon.iconSize = new GSize( dim_x, dim_y );
			icon.iconAnchor = new GPoint( anchor_x, anchor_y );
			icon.infoWindowAnchor = new GPoint( 5, 1 );
			return icon;
        }
                
        function createMarker( coords, zoom, type_id, dim_x, dim_y, anchor_x, anchor_y, html )
        {
        	var marker = new GMarker( coords, markerIcon( type_id, dim_x, dim_y, anchor_x, anchor_y ) );
        	
        	marker.tooltip = '<div class="googleMapTooltip"><p>'+html+'</p></div>';
        	
			GEvent.addListener( marker, "click", function()
			{
				tooltip.style.visibility="hidden"
				map.setCenter( coords );
				map.setZoom( zoom );
			} );
			
			GEvent.addListener( marker, "mouseover", function()
			{
				showTooltip( marker );
			} );
			
			GEvent.addListener( marker, "mouseout", function()
			{
				tooltip.style.visibility="hidden"
			} );

			return marker;
		}
				
		// initialize variables
		var gmarkers = new Array();
		var oceans = new Array();
		var harbours = new Array();
		var locations = new Array();
		
		harbours[0] = new Object();
harbours[0]['name'] = 'Antigua (English Harbour)<br><ul><li>Sunsail</li></ul>';
harbours[0]['google_x'] = Number(17.002620210523283);
harbours[0]['google_y'] = Number(-61.7636775970459);
harbours[0]['google_z'] = Number(13);
harbours[0]['type_id'] = '0';
harbours[0]['dim_x'] = 10;
harbours[0]['dim_y'] = 10;
harbours[0]['anchor_x'] = 1;
harbours[0]['anchor_y'] = 1;
harbours[0]['shown'] = true;
harbours[1] = new Object();
harbours[1]['name'] = 'Antigua (Jolly Harbour)';
harbours[1]['google_x'] = Number(17.065851509797152);
harbours[1]['google_y'] = Number(-61.88393712043762);
harbours[1]['google_z'] = Number(17);
harbours[1]['type_id'] = '0';
harbours[1]['dim_x'] = 10;
harbours[1]['dim_y'] = 10;
harbours[1]['anchor_x'] = 1;
harbours[1]['anchor_y'] = 1;
harbours[1]['shown'] = true;
harbours[2] = new Object();
harbours[2]['name'] = 'Canouan Island (Grand Bay)<br><ul><li>Moorings</li></ul>';
harbours[2]['google_x'] = Number(12.705362206083702);
harbours[2]['google_y'] = Number(-61.32736802101135);
harbours[2]['google_z'] = Number(17);
harbours[2]['type_id'] = '0';
harbours[2]['dim_x'] = 10;
harbours[2]['dim_y'] = 10;
harbours[2]['anchor_x'] = 1;
harbours[2]['anchor_y'] = 1;
harbours[2]['shown'] = true;
harbours[3] = new Object();
harbours[3]['name'] = 'Grenada (Port Louis Marina)';
harbours[3]['google_x'] = Number(12.043706533845453);
harbours[3]['google_y'] = Number(-61.74896836280823);
harbours[3]['google_z'] = Number(18);
harbours[3]['type_id'] = '0';
harbours[3]['dim_x'] = 10;
harbours[3]['dim_y'] = 10;
harbours[3]['anchor_x'] = 1;
harbours[3]['anchor_y'] = 1;
harbours[3]['shown'] = true;
harbours[4] = new Object();
harbours[4]['name'] = 'Guadeloupe (Pointe-à-Pitre, Lagon Bleue)<br><ul><li>Star Voyage</li><li>Sunsail</li></ul>';
harbours[4]['google_x'] = Number(16.220989653825622);
harbours[4]['google_y'] = Number(-61.5234375);
harbours[4]['google_z'] = Number(17);
harbours[4]['type_id'] = '0';
harbours[4]['dim_x'] = 10;
harbours[4]['dim_y'] = 10;
harbours[4]['anchor_x'] = 1;
harbours[4]['anchor_y'] = 1;
harbours[4]['shown'] = true;
harbours[5] = new Object();
harbours[5]['name'] = 'Guadeloupe (Pointe-a-Pitre, Marina Bas du Fort)<br><ul><li>Dream Yacht Charter</li><li>Sparkling Charter</li><li>VPM</li></ul>';
harbours[5]['google_x'] = Number(16.219382576407924);
harbours[5]['google_y'] = Number(-61.52900576591492);
harbours[5]['google_z'] = Number(17);
harbours[5]['type_id'] = '0';
harbours[5]['dim_x'] = 10;
harbours[5]['dim_y'] = 10;
harbours[5]['anchor_x'] = 1;
harbours[5]['anchor_y'] = 1;
harbours[5]['shown'] = true;
harbours[6] = new Object();
harbours[6]['name'] = 'Martinique (Le Marin)<br><ul><li>Dream Yacht Charter</li><li>Kiriacoulis</li><li>Sparkling Charter</li><li>Star Voyage</li><li>Sunsail</li><li>VPM</li></ul>';
harbours[6]['google_x'] = Number(14.468424872388153);
harbours[6]['google_y'] = Number(-60.867347717285156);
harbours[6]['google_z'] = Number(14);
harbours[6]['type_id'] = '0';
harbours[6]['dim_x'] = 10;
harbours[6]['dim_y'] = 10;
harbours[6]['anchor_x'] = 1;
harbours[6]['anchor_y'] = 1;
harbours[6]['shown'] = true;
harbours[7] = new Object();
harbours[7]['name'] = 'St. Lucia (Rodney Bay)<br><ul><li>Kiriacoulis</li></ul>';
harbours[7]['google_x'] = Number(14.075475598566268);
harbours[7]['google_y'] = Number(-60.94895124435425);
harbours[7]['google_z'] = Number(16);
harbours[7]['type_id'] = '0';
harbours[7]['dim_x'] = 10;
harbours[7]['dim_y'] = 10;
harbours[7]['anchor_x'] = 1;
harbours[7]['anchor_y'] = 1;
harbours[7]['shown'] = true;
harbours[8] = new Object();
harbours[8]['name'] = 'St. Lucia (Marigot Bay Marina)<br><ul><li>Moorings</li></ul>';
harbours[8]['google_x'] = Number(13.965356497720693);
harbours[8]['google_y'] = Number(-61.023656129837036);
harbours[8]['google_z'] = Number(17);
harbours[8]['type_id'] = '0';
harbours[8]['dim_x'] = 10;
harbours[8]['dim_y'] = 10;
harbours[8]['anchor_x'] = 1;
harbours[8]['anchor_y'] = 1;
harbours[8]['shown'] = true;
harbours[9] = new Object();
harbours[9]['name'] = 'St. Martin (Oyster Pond)<br><ul><li>Moorings</li><li>Sunsail</li></ul>';
harbours[9]['google_x'] = Number(18.055661701919234);
harbours[9]['google_y'] = Number(-63.01538944244385);
harbours[9]['google_z'] = Number(17);
harbours[9]['type_id'] = '0';
harbours[9]['dim_x'] = 10;
harbours[9]['dim_y'] = 10;
harbours[9]['anchor_x'] = 1;
harbours[9]['anchor_y'] = 1;
harbours[9]['shown'] = true;
harbours[10] = new Object();
harbours[10]['name'] = 'St. Martin (Marina Port La Royale)<br><ul><li>Dream Yacht Charter</li><li>Star Voyage</li></ul>';
harbours[10]['google_x'] = Number(18.064505316173467);
harbours[10]['google_y'] = Number(-63.088088035583496);
harbours[10]['google_z'] = Number(18);
harbours[10]['type_id'] = '0';
harbours[10]['dim_x'] = 10;
harbours[10]['dim_y'] = 10;
harbours[10]['anchor_x'] = 1;
harbours[10]['anchor_y'] = 1;
harbours[10]['shown'] = true;
harbours[11] = new Object();
harbours[11]['name'] = 'St. Martin (Anse Marcel)<br><ul><li>VPM</li></ul>';
harbours[11]['google_x'] = Number(18.112703851669004);
harbours[11]['google_y'] = Number(-63.037179708480835);
harbours[11]['google_z'] = Number(17);
harbours[11]['type_id'] = '0';
harbours[11]['dim_x'] = 10;
harbours[11]['dim_y'] = 10;
harbours[11]['anchor_x'] = 1;
harbours[11]['anchor_y'] = 1;
harbours[11]['shown'] = true;
harbours[12] = new Object();
harbours[12]['name'] = 'St. Vincent (Blue Lagoon)<br><ul><li>Sunsail</li></ul>';
harbours[12]['google_x'] = Number(13.127608571655449);
harbours[12]['google_y'] = Number(-61.190757751464844);
harbours[12]['google_z'] = Number(17);
harbours[12]['type_id'] = '0';
harbours[12]['dim_x'] = 10;
harbours[12]['dim_y'] = 10;
harbours[12]['anchor_x'] = 1;
harbours[12]['anchor_y'] = 1;
harbours[12]['shown'] = true;
locations[0] = new Object();
locations[0]['name'] = 'St. Lucia (SLU)';
locations[0]['google_x'] = Number(14.020604815448804);
locations[0]['google_y'] = Number(-60.991458892822266);
locations[0]['google_z'] = Number(14);
locations[0]['type_id'] = '2';
locations[0]['dim_x'] = 10;
locations[0]['dim_y'] = 10;
locations[0]['anchor_x'] = 1;
locations[0]['anchor_y'] = 1;
locations[0]['shown'] = true;
locations[1] = new Object();
locations[1]['name'] = 'St. Lucia (Soufriere)';
locations[1]['google_x'] = Number(13.85508057251768);
locations[1]['google_y'] = Number(-61.06029510498047);
locations[1]['google_z'] = Number(13);
locations[1]['type_id'] = '1';
locations[1]['dim_x'] = 10;
locations[1]['dim_y'] = 10;
locations[1]['anchor_x'] = 1;
locations[1]['anchor_y'] = 1;
locations[1]['shown'] = true;
locations[2] = new Object();
locations[2]['name'] = 'St. Lucia (Marigot Bay)';
locations[2]['google_x'] = Number(13.967053600403545);
locations[2]['google_y'] = Number(-61.02785110473633);
locations[2]['google_z'] = Number(13);
locations[2]['type_id'] = '1';
locations[2]['dim_x'] = 10;
locations[2]['dim_y'] = 10;
locations[2]['anchor_x'] = 1;
locations[2]['anchor_y'] = 1;
locations[2]['shown'] = true;
locations[3] = new Object();
locations[3]['name'] = 'Martinique (FDF)';
locations[3]['google_x'] = Number(14.58973020451531);
locations[3]['google_y'] = Number(-61.006736755371094);
locations[3]['google_z'] = Number(13);
locations[3]['type_id'] = '2';
locations[3]['dim_x'] = 10;
locations[3]['dim_y'] = 10;
locations[3]['anchor_x'] = 1;
locations[3]['anchor_y'] = 1;
locations[3]['shown'] = true;
locations[4] = new Object();
locations[4]['name'] = 'St. Vincent (SVD)';
locations[4]['google_x'] = Number(13.141922538568567);
locations[4]['google_y'] = Number(-61.21161460876465);
locations[4]['google_z'] = Number(14);
locations[4]['type_id'] = '2';
locations[4]['dim_x'] = 10;
locations[4]['dim_y'] = 10;
locations[4]['anchor_x'] = 1;
locations[4]['anchor_y'] = 1;
locations[4]['shown'] = true;
locations[5] = new Object();
locations[5]['name'] = 'Mustique (MQS)';
locations[5]['google_x'] = Number(12.887365482066444);
locations[5]['google_y'] = Number(-61.18086576461792);
locations[5]['google_z'] = Number(16);
locations[5]['type_id'] = '2';
locations[5]['dim_x'] = 10;
locations[5]['dim_y'] = 10;
locations[5]['anchor_x'] = 1;
locations[5]['anchor_y'] = 1;
locations[5]['shown'] = true;
locations[6] = new Object();
locations[6]['name'] = 'St. Lucia (UVF)';
locations[6]['google_x'] = Number(13.731881239911166);
locations[6]['google_y'] = Number(-60.952491760253906);
locations[6]['google_z'] = Number(14);
locations[6]['type_id'] = '2';
locations[6]['dim_x'] = 10;
locations[6]['dim_y'] = 10;
locations[6]['anchor_x'] = 1;
locations[6]['anchor_y'] = 1;
locations[6]['shown'] = true;
locations[7] = new Object();
locations[7]['name'] = 'Bequia (BQU)';
locations[7]['google_x'] = Number(12.988751301039594);
locations[7]['google_y'] = Number(-61.26169681549072);
locations[7]['google_z'] = Number(15);
locations[7]['type_id'] = '2';
locations[7]['dim_x'] = 10;
locations[7]['dim_y'] = 10;
locations[7]['anchor_x'] = 1;
locations[7]['anchor_y'] = 1;
locations[7]['shown'] = true;
locations[8] = new Object();
locations[8]['name'] = 'Barbados (BGI)';
locations[8]['google_x'] = Number(13.074294775366061);
locations[8]['google_y'] = Number(-59.495859146118164);
locations[8]['google_z'] = Number(14);
locations[8]['type_id'] = '2';
locations[8]['dim_x'] = 10;
locations[8]['dim_y'] = 10;
locations[8]['anchor_x'] = 1;
locations[8]['anchor_y'] = 1;
locations[8]['shown'] = true;
locations[9] = new Object();
locations[9]['name'] = 'Canouan Island (CIW)';
locations[9]['google_x'] = Number(12.698789391836469);
locations[9]['google_y'] = Number(-61.34224891662598);
locations[9]['google_z'] = Number(14);
locations[9]['type_id'] = '2';
locations[9]['dim_x'] = 10;
locations[9]['dim_y'] = 10;
locations[9]['anchor_x'] = 1;
locations[9]['anchor_y'] = 1;
locations[9]['shown'] = true;
locations[10] = new Object();
locations[10]['name'] = 'Carriacou (CRU)';
locations[10]['google_x'] = Number(12.477140636762531);
locations[10]['google_y'] = Number(-61.47301197052002);
locations[10]['google_z'] = Number(16);
locations[10]['type_id'] = '2';
locations[10]['dim_x'] = 10;
locations[10]['dim_y'] = 10;
locations[10]['anchor_x'] = 1;
locations[10]['anchor_y'] = 1;
locations[10]['shown'] = true;
locations[11] = new Object();
locations[11]['name'] = 'Grenada (GND)';
locations[11]['google_x'] = Number(12.003474586376884);
locations[11]['google_y'] = Number(-61.78607940673828);
locations[11]['google_z'] = Number(14);
locations[11]['type_id'] = '2';
locations[11]['dim_x'] = 10;
locations[11]['dim_y'] = 10;
locations[11]['anchor_x'] = 1;
locations[11]['anchor_y'] = 1;
locations[11]['shown'] = true;
locations[12] = new Object();
locations[12]['name'] = 'St. Martin (SXM)';
locations[12]['google_x'] = Number(18.039789001525726);
locations[12]['google_y'] = Number(-63.109588623046875);
locations[12]['google_z'] = Number(14);
locations[12]['type_id'] = '2';
locations[12]['dim_x'] = 10;
locations[12]['dim_y'] = 10;
locations[12]['anchor_x'] = 1;
locations[12]['anchor_y'] = 1;
locations[12]['shown'] = true;
locations[13] = new Object();
locations[13]['name'] = 'St. Barts (SBH)';
locations[13]['google_x'] = Number(17.9038740800199);
locations[13]['google_y'] = Number(-62.8443717956543);
locations[13]['google_z'] = Number(16);
locations[13]['type_id'] = '2';
locations[13]['dim_x'] = 10;
locations[13]['dim_y'] = 10;
locations[13]['anchor_x'] = 1;
locations[13]['anchor_y'] = 1;
locations[13]['shown'] = true;
locations[14] = new Object();
locations[14]['name'] = 'Antigua (ANU)';
locations[14]['google_x'] = Number(17.13816578647873);
locations[14]['google_y'] = Number(-61.78813934326172);
locations[14]['google_z'] = Number(14);
locations[14]['type_id'] = '2';
locations[14]['dim_x'] = 10;
locations[14]['dim_y'] = 10;
locations[14]['anchor_x'] = 1;
locations[14]['anchor_y'] = 1;
locations[14]['shown'] = true;
locations[15] = new Object();
locations[15]['name'] = 'St. Kitts (SKB)';
locations[15]['google_x'] = Number(17.311965613773584);
locations[15]['google_y'] = Number(-62.71871566772461);
locations[15]['google_z'] = Number(14);
locations[15]['type_id'] = '2';
locations[15]['dim_x'] = 10;
locations[15]['dim_y'] = 10;
locations[15]['anchor_x'] = 1;
locations[15]['anchor_y'] = 1;
locations[15]['shown'] = true;
locations[16] = new Object();
locations[16]['name'] = 'Barbuda (BBQ)';
locations[16]['google_x'] = Number(17.606393299438025);
locations[16]['google_y'] = Number(-61.829681396484375);
locations[16]['google_z'] = Number(13);
locations[16]['type_id'] = '2';
locations[16]['dim_x'] = 10;
locations[16]['dim_y'] = 10;
locations[16]['anchor_x'] = 1;
locations[16]['anchor_y'] = 1;
locations[16]['shown'] = true;
locations[17] = new Object();
locations[17]['name'] = 'Guadeloupe (PTP)';
locations[17]['google_x'] = Number(16.264612670838762);
locations[17]['google_y'] = Number(-61.534767150878906);
locations[17]['google_z'] = Number(13);
locations[17]['type_id'] = '2';
locations[17]['dim_x'] = 10;
locations[17]['dim_y'] = 10;
locations[17]['anchor_x'] = 1;
locations[17]['anchor_y'] = 1;
locations[17]['shown'] = true;
locations[18] = new Object();
locations[18]['name'] = 'Dominica (DOM)';
locations[18]['google_x'] = Number(15.54730665055691);
locations[18]['google_y'] = Number(-61.30040645599365);
locations[18]['google_z'] = Number(15);
locations[18]['type_id'] = '2';
locations[18]['dim_x'] = 10;
locations[18]['dim_y'] = 10;
locations[18]['anchor_x'] = 1;
locations[18]['anchor_y'] = 1;
locations[18]['shown'] = true;
			
		function getMarkers( array_name )
		{
			var batch = [];
			
			// loop through all locations and set markers
			for( var i=0; i < array_name.length; i++ )
			{
				if( array_name[i].google_x && array_name[i].google_y )
				{
					var coords = new GLatLng( array_name[i].google_x, array_name[i].google_y );
					batch.push( createMarker( coords, array_name[i].google_z, array_name[i].type_id, array_name[i].dim_x, array_name[i].dim_y, array_name[i].anchor_x, array_name[i].anchor_y, array_name[i].name ) );
				}
			}
			
			return batch;
		}
		
		function setupMarkers() 
		{
			mgr = new GMarkerManager( map );
			
			mgr.addMarkers( getMarkers( oceans ), 0 );
			mgr.addMarkers( getMarkers( harbours ), 6 );
			mgr.addMarkers( getMarkers( locations ), 8, 14 );
						
			mgr.refresh();
		}
		
		window.setTimeout( setupMarkers, 0 );
		
		function showTooltip( marker )
		{
			tooltip.innerHTML = marker.tooltip;
			
			var point=map.getCurrentMapType().getProjection().fromLatLngToPixel( map.getBounds().getSouthWest(),map.getZoom() );
			var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel( marker.getPoint(),map.getZoom() );
			var anchor=marker.getIcon().iconAnchor;
			var width=marker.getIcon().iconSize.width;
			var pos = new GControlPosition( G_ANCHOR_BOTTOM_LEFT, new GSize( offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y ) ); 
			
			pos.apply(tooltip);
			
			tooltip.style.visibility="visible";
		}
		
		GEvent.addListener( map, "wheelup", function(p)
		{
		  if ( map.getZoomLevel() > 0 ) {
		    map.centerAndZoom(
		      p.scaleRelative( map.getCenterLatLng() ),
		      map.getZoomLevel() - 1
		    );
		  }
		} );
		
		GEvent.addListener( map, "wheeldown", function(p)
		{
		  if ( map.getZoomLevel() <= 16 )
		    map.centerAndZoom(
		      p.scaleRelative( map.getCenterLatLng(), -1 ),
		      map.getZoomLevel() + 1
		    );
		} );
		
		GEvent.addDomListener(map.getContainer(), "DOMMouseScroll",
		function(oEvent)
		{
			if( oEvent.preventDefault )
			oEvent.preventDefault();
		} ); 
		
		// things that happen when the map is moved - basically just for debugging and detecting the coordinates for locations
		GEvent.addListener( map, "moveend", function()
		{
			var center = map.getCenter();
			var zoom = map.getZoom();
			document.getElementById("googleMapLabelDetail").innerHTML = center.toString() + ' ' + zoom.toString();
        } );
	}
}