
/* 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'] = 'Alcudia (Marina Alcudiamar)';
harbours[0]['google_x'] = Number(39.83899085479953);
harbours[0]['google_y'] = Number(3.1335926055908203);
harbours[0]['google_z'] = Number(14);
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'] = 'Ca\\\'n Pastilla (Club Maritimo San Antonio de la Playa)';
harbours[1]['google_x'] = Number(39.5330909456622);
harbours[1]['google_y'] = Number(2.7157044410705566);
harbours[1]['google_z'] = Number(16);
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'] = 'El Arenal (Club Nautico Arenal)';
harbours[2]['google_x'] = Number(39.50081215117537);
harbours[2]['google_y'] = Number(2.747483253479004);
harbours[2]['google_z'] = Number(16);
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'] = 'Ibiza (Marina Botafoch)';
harbours[3]['google_x'] = Number(38.91197328797698);
harbours[3]['google_y'] = Number(1.4477920532226562);
harbours[3]['google_z'] = Number(16);
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'] = 'Ibiza (Marina Ibiza Nueva)';
harbours[4]['google_x'] = Number(38.91394344410544);
harbours[4]['google_y'] = Number(1.4448201656341553);
harbours[4]['google_z'] = Number(16);
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'] = 'Ibiza (Marina Santa Eulalia)';
harbours[5]['google_x'] = Number(38.98376515107418);
harbours[5]['google_y'] = Number(1.5390300750732422);
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'] = 'La Savina (Marina de Formentera)';
harbours[6]['google_x'] = Number(38.733230229568626);
harbours[6]['google_y'] = Number(1.4172577857971191);
harbours[6]['google_z'] = Number(16);
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'] = 'Mahon (Puerto de Mao)';
harbours[7]['google_x'] = Number(39.890072852111125);
harbours[7]['google_y'] = Number(4.27067756652832);
harbours[7]['google_z'] = Number(18);
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'] = 'Palma de Mallorca (Real Club Nautico)';
harbours[8]['google_x'] = Number(39.56687655756278);
harbours[8]['google_y'] = Number(2.634916305541992);
harbours[8]['google_z'] = Number(16);
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'] = 'Palma de Mallorca (Marina Alboran)<br><ul><li>Alboran Charter</li><li>Nautikonrad</li></ul>';
harbours[9]['google_x'] = Number(39.567290089454275);
harbours[9]['google_y'] = Number(2.631847858428955);
harbours[9]['google_z'] = Number(16);
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'] = 'Palma de Mallorca (Contra Muelle Mollet)<br><ul><li>Cruesa</li><li>ECC</li></ul>';
harbours[10]['google_x'] = Number(39.56687655756278);
harbours[10]['google_y'] = Number(2.639615535736084);
harbours[10]['google_z'] = Number(16);
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'] = 'Palma de Mallorca (Muelle de La Lonja)<br><ul><li>Latitud Cero</li><li>Viva Charter</li></ul>';
harbours[11]['google_x'] = Number(39.56776978335867);
harbours[11]['google_y'] = Number(2.642190456390381);
harbours[11]['google_z'] = Number(16);
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'] = 'Palma de Mallorca (Club de Mar)';
harbours[12]['google_x'] = Number();
harbours[12]['google_y'] = Number();
harbours[12]['google_z'] = Number(0);
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'] = 'Porto Colom (Marina Porto Colom)<br><ul><li>Veritas Yachting</li></ul>';
harbours[13]['google_x'] = Number(39.4208120617938);
harbours[13]['google_y'] = Number(3.2636260986328125);
harbours[13]['google_z'] = Number(14);
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'] = 'Puerto Pollensa<br><ul><li>CM Charter Mallorca</li></ul>';
harbours[14]['google_x'] = Number(39.90417278580615);
harbours[14]['google_y'] = Number(3.0847764015197754);
harbours[14]['google_z'] = Number(16);
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'] = 'San Antonio (Club Nautico)';
harbours[15]['google_x'] = Number(38.97802714687125);
harbours[15]['google_y'] = Number(1.3004207611083984);
harbours[15]['google_z'] = Number(14);
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;
locations[0] = new Object();
locations[0]['name'] = 'Palma (PMI)';
locations[0]['google_x'] = Number(39.547735603527485);
locations[0]['google_y'] = Number(2.728557586669922);
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'] = 'Ibiza (IBZ)';
locations[1]['google_x'] = Number(38.87219115474015);
locations[1]['google_y'] = Number(1.371917724609375);
locations[1]['google_z'] = Number(13);
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;
			
		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();
        } );
	}
}