
/* 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'] = 'Ajaccio (Port Tino Rossi)<br><ul><li>Moorings</li></ul>';
harbours[0]['google_x'] = Number(41.91840533332896);
harbours[0]['google_y'] = Number(8.741598129272461);
harbours[0]['google_z'] = Number(16);
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'] = 'Antibes<br><ul><li>L\\\'ile Bleue</li></ul>';
harbours[1]['google_x'] = Number(43.58604864427797);
harbours[1]['google_y'] = Number(7.127723693847656);
harbours[1]['google_z'] = Number(14);
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'] = 'Bastia';
harbours[2]['google_x'] = Number(42.70501968389624);
harbours[2]['google_y'] = Number(9.452533721923828);
harbours[2]['google_z'] = Number(13);
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'] = 'Bonifacio<br><ul><li>L\\\'ile Bleue</li></ul>';
harbours[3]['google_x'] = Number(41.38865810163064);
harbours[3]['google_y'] = Number(9.16358470916748);
harbours[3]['google_z'] = Number(15);
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'] = 'Bormes les Mimosas<br><ul><li>Kiriacoulis</li></ul>';
harbours[4]['google_x'] = Number(43.13631817264695);
harbours[4]['google_y'] = Number(6.376190185546875);
harbours[4]['google_z'] = Number(14);
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'] = 'Calvi';
harbours[5]['google_x'] = Number(42.56464980756867);
harbours[5]['google_y'] = Number(8.758506774902344);
harbours[5]['google_z'] = Number(14);
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'] = 'Fréjus';
harbours[6]['google_x'] = Number();
harbours[6]['google_y'] = Number();
harbours[6]['google_z'] = Number(0);
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'] = 'Golfe Juan<br><ul><li>Seaways Yachting</li></ul>';
harbours[7]['google_x'] = Number(43.56577762313728);
harbours[7]['google_y'] = Number(7.078886032104492);
harbours[7]['google_z'] = Number(14);
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'] = 'Hyères<br><ul><li>Cote d\\\'Azur Charter</li></ul>';
harbours[8]['google_x'] = Number(43.08719407237443);
harbours[8]['google_y'] = Number(6.079216003417969);
harbours[8]['google_z'] = Number(13);
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'] = 'La Trinité-sur-Mer<br><ul><li>SPI Location</li></ul>';
harbours[9]['google_x'] = Number(47.5904781884402);
harbours[9]['google_y'] = Number( -3.0267333984375);
harbours[9]['google_z'] = Number(14);
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'] = 'Lorient<br><ul><li>SPI Location</li></ul>';
harbours[10]['google_x'] = Number(47.723967166629585);
harbours[10]['google_y'] = Number(-3.3597564697265625);
harbours[10]['google_z'] = Number(13);
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'] = 'Macinaggio (Marina)<br><ul><li>Dream Yacht Charter</li></ul>';
harbours[11]['google_x'] = Number(42.958683884926984);
harbours[11]['google_y'] = Number(9.451675415039062);
harbours[11]['google_z'] = Number(13);
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'] = 'Nizza (Port de Nice)<br><ul><li>Moorings</li></ul>';
harbours[12]['google_x'] = Number(43.69561764062765);
harbours[12]['google_y'] = Number(7.28419303894043);
harbours[12]['google_z'] = Number(15);
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;
harbours[13] = new Object();
harbours[13]['name'] = 'Port Grimaud';
harbours[13]['google_x'] = Number(43.26963591357691);
harbours[13]['google_y'] = Number(6.574909687042236);
harbours[13]['google_z'] = Number(18);
harbours[13]['type_id'] = '0';
harbours[13]['dim_x'] = 10;
harbours[13]['dim_y'] = 10;
harbours[13]['anchor_x'] = 1;
harbours[13]['anchor_y'] = 1;
harbours[13]['shown'] = true;
harbours[14] = new Object();
harbours[14]['name'] = 'Port Pin Rolland<br><ul><li>Dream Yacht Charter</li></ul>';
harbours[14]['google_x'] = Number(43.07866853173014);
harbours[14]['google_y'] = Number(5.925235748291016);
harbours[14]['google_z'] = Number(13);
harbours[14]['type_id'] = '0';
harbours[14]['dim_x'] = 10;
harbours[14]['dim_y'] = 10;
harbours[14]['anchor_x'] = 1;
harbours[14]['anchor_y'] = 1;
harbours[14]['shown'] = true;
harbours[15] = new Object();
harbours[15]['name'] = 'Propriano';
harbours[15]['google_x'] = Number(41.67663017666532);
harbours[15]['google_y'] = Number(8.902144432067871);
harbours[15]['google_z'] = Number(15);
harbours[15]['type_id'] = '0';
harbours[15]['dim_x'] = 10;
harbours[15]['dim_y'] = 10;
harbours[15]['anchor_x'] = 1;
harbours[15]['anchor_y'] = 1;
harbours[15]['shown'] = true;
harbours[16] = new Object();
harbours[16]['name'] = 'St. Raphael<br><ul><li>Seaways Yachting</li></ul>';
harbours[16]['google_x'] = Number(43.415273206886745);
harbours[16]['google_y'] = Number(6.775732040405273);
harbours[16]['google_z'] = Number(15);
harbours[16]['type_id'] = '0';
harbours[16]['dim_x'] = 10;
harbours[16]['dim_y'] = 10;
harbours[16]['anchor_x'] = 1;
harbours[16]['anchor_y'] = 1;
harbours[16]['shown'] = true;
locations[0] = new Object();
locations[0]['name'] = 'Lorient (LRE)';
locations[0]['google_x'] = Number(47.758944987504144);
locations[0]['google_y'] = Number(-3.4431838989257812);
locations[0]['google_z'] = Number(13);
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'] = 'Toulon-Hyeres (TLN)';
locations[1]['google_x'] = Number(43.09615714801092);
locations[1]['google_y'] = Number(6.150197982788086);
locations[1]['google_z'] = Number(14);
locations[1]['type_id'] = '2';
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'] = 'Marseille (MRS)';
locations[2]['google_x'] = Number(43.43758920543926);
locations[2]['google_y'] = Number(5.2095794677734375);
locations[2]['google_z'] = Number(13);
locations[2]['type_id'] = '2';
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'] = 'Nizza (NCE)';
locations[3]['google_x'] = Number(43.659675697356455);
locations[3]['google_y'] = Number(7.215614318847656);
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'] = 'Ajaccio (AJA)';
locations[4]['google_x'] = Number(41.92028936301539);
locations[4]['google_y'] = Number(8.798246383666992);
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'] = 'Bastia (BIA)';
locations[5]['google_x'] = Number(42.553459651448016);
locations[5]['google_y'] = Number(9.481973648071289);
locations[5]['google_z'] = Number(14);
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'] = 'Calvi (CLY)';
locations[6]['google_x'] = Number(42.529681813107544);
locations[6]['google_y'] = Number(8.792495727539062);
locations[6]['google_z'] = Number(13);
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;
			
		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();
        } );
	}
}