  

var baseIcon = new GIcon();
baseIcon.iconSize=new GSize(32,32);
baseIcon.shadowSize=new GSize(56,32);
baseIcon.iconAnchor=new GPoint(16,32);
baseIcon.infoWindowAnchor=new GPoint(16,0);
var martini = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon27.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon27s.png");
var plane   = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon56.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon56s.png");
var pushpin = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal5/icon14.png", null, "http://maps.google.com/mapfiles/kml/pal5/icon14s.png");
var startIcon = new GIcon(baseIcon, sDir + "/images/start.png", null, "http://maps.google.com/mapfiles/kml/pal5/icon14s.png");
var stopIcon = new GIcon(baseIcon, sDir + "/images/stop.png", null, "http://maps.google.com/mapfiles/kml/pal5/icon14s.png");
	

var side_bar_html = "";
var gmarkers = [];

var map;
var lastlinkid;
var bounds;
var viewPOIs = false;
var line;
var mgr;
var latlngArr=[];
var globalPOI = [];
var cruiseID;
var poiID = -1;
var l = new language();

var iconBlue = new GIcon(); 
iconBlue.image = sDir + '/images/mm_20_blue.png';
iconBlue.shadow = sDir + '/images/mm_20_shadow.png';
iconBlue.iconSize = new GSize(12, 20);
iconBlue.shadowSize = new GSize(22, 20);
iconBlue.iconAnchor = new GPoint(6, 20);
iconBlue.infoWindowAnchor = new GPoint(5, 1);

var iconBrown = new GIcon(); 
iconBrown.image = sDir + '/images/mm_20_brown.png';
iconBrown.shadow = sDir + '/images/mm_20_shadow.png';
iconBrown.iconSize = new GSize(12, 20);
iconBrown.shadowSize = new GSize(22, 20);
iconBrown.iconAnchor = new GPoint(6, 20);
iconBrown.infoWindowAnchor = new GPoint(5, 1);
	
var iconRed = new GIcon(); 
iconRed.image = sDir + '/images/mm_20_red.png';
iconRed.shadow = sDir + '/images/mm_20_shadow.png';
iconRed.iconSize = new GSize(12, 20);
iconRed.shadowSize = new GSize(22, 20);
iconRed.iconAnchor = new GPoint(6, 20);
iconRed.infoWindowAnchor = new GPoint(5, 1);

var iconYellow = new GIcon(); 
iconYellow.image = sDir + '/images/mm_20_yellow.png';
iconYellow.shadow = sDir + '/images/mm_20_shadow.png';
iconYellow.iconSize = new GSize(12, 20);
iconYellow.shadowSize = new GSize(22, 20);
iconYellow.iconAnchor = new GPoint(6, 20);
iconYellow.infoWindowAnchor = new GPoint(5, 1);

var iconGreen = new GIcon(); 
iconGreen.image = sDir + '/images/mm_20_green.png';
iconGreen.shadow = sDir + '/images/mm_20_shadow.png';
iconGreen.iconSize = new GSize(12, 20);
iconGreen.shadowSize = new GSize(22, 20);
iconGreen.iconAnchor = new GPoint(6, 20);
iconGreen.infoWindowAnchor = new GPoint(5, 1);


var customIcons = [];
customIcons["beautifulAnchorage"] = iconBlue;
customIcons["beautifulHarbour"] = iconBrown;
customIcons["nauticalDangerousSpot"] = iconRed;
customIcons["perfectRestaurantBar"] = iconYellow;
customIcons["dontMissToSeeThis"] = iconGreen;
var markerGroups = { "beautifulAnchorage": [], "beautifulHarbour": [], "nauticalDangerousSpot": [], "perfectRestaurantBar": [], "dontMissToSeeThis": []};

function showPoiOnPage(cruiseId, pid) {
	//alert(id);
	var loc = "http://www.mysailinglog.com/page/turn/cruiseId/"+cruiseId;
	window.location = loc;
}
function initialize(cid,pid) {
    if(GBrowserIsCompatible()) {
    	map = new GMap2(document.getElementById('map'));
      
    	var customUI = map.getDefaultUI();
        // Remove MapType.G_HYBRID_MAP
        customUI.maptypes.hybrid = false;
        map.setUI(customUI);
        map.setMapType(G_PHYSICAL_MAP);
        
    	if (_zoom!=false && _lat!=false && _lng!=false) {
			map.setCenter(new GLatLng(_lat, _lng));
			map.setZoom(_zoom);
	    } else {
			//map.setCenter(new GLatLng(39.91, 116.38), 2);
			map.setCenter(new GLatLng(33.98, -2.18), 2);
		}
      
    	//map.addControl(new GLargeMapControl());
    	//map.addControl(new GMapTypeControl(),new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 30)));
      
	  if (cid) {

			showLatestPoi2(cid, pid); 
		}
		else
		{
		var ret = readURL();
			if (ret)
			{
				
				if (ret['task'] == "showTurn") {
					showPoiOnPage(ret['id'], ret['pid']); 
			        }
			        else if (ret['task'] == "bc")
			        {
			        	getTurnsByCountry(ret['i']);
			        }
			        else if (ret['task'] == "bd")
			        {
			        	getTurnsByDistrict(ret['i']);
			        }
			}
	        else
	        {
		      	//moveMap(48,30,-51,12);
		     	getTurns();
	      	}
		}
     // getTurns();
      
  	
	function specialPointControl() {
	}
	
	// To "subclass" the GControl, we set the prototype object to
	// an instance of the GControl object
	specialPointControl.prototype = new GControl();
	
	specialPointControl.prototype.initialize = function(map) {
		var _container = document.createElement("div");
		//_container.style.width = "180px";
		//_container.style.height = "180px";
		//_container.style.cssFloat = "left";
		//_container.style.backgroundColor = "yellow";
		
		// Schöner Ankerplätze = 1
			var _special1Div = document.createElement("div");
			this.setButtonStyle_(_special1Div);
			_container.appendChild(_special1Div);
			_special1Div.innerHTML = '<img src="' + sDir + '/images/mm_20_blue.png" style="float: right; margin-left: 3px;" /> <div style="padding-top: 3px;"><input type="checkbox" id="spec1" onclick="return false" style="float: left" /> <label style="float: left; margin-left: 4px;">' + _label1 + '</label></div>';
			
			var _special1DivOff = document.createElement("div");
			this.setButtonStyle_(_special1DivOff);
			_special1DivOff.style.display = "none";
			_container.appendChild(_special1DivOff);
			_special1DivOff.innerHTML = '<img src="' + sDir + '/images/mm_20_blue.png" style="float: right; margin-left: 3px;" /> <div style="padding-top: 3px;"><input type="checkbox" checked="checked" onclick="return false" style="float: left" /> <label style="float: left; margin-left: 4px;">' + _label1 + '</label></div>';
			
			GEvent.addDomListener(_special1Div, "click", function() {
				_special1Div.style.display = "none";
				_special1DivOff.style.display = "block";
				document.getElementById('spec1').checked = false;				
				if (markerGroups["beautifulAnchorage"].length==0) {
					getSpecialWaypoints("beautifulAnchorage");
				} else {
					toggleSpecialWaypoints("beautifulAnchorage");
				}
			});
	
			GEvent.addDomListener(_special1DivOff, "click", function() {
				_special1Div.style.display = "block";
				_special1DivOff.style.display = "none";
				document.getElementById('spec1').checked = false;
				toggleSpecialWaypoints("beautifulAnchorage");
			});
		
		// Schöner Hafen = 2
			var _special2Div = document.createElement("div");
			this.setButtonStyle_(_special2Div);
			_container.appendChild(_special2Div);
			_special2Div.innerHTML = '<img src="' + sDir + '/images/mm_20_brown.png" style="float: right; margin-left: 3px;" /> <div style="padding-top: 3px;"><input type="checkbox" id="spec2" onclick="return false" style="float: left" /> <label style="float: left; margin-left: 4px;">' + _label2 + '</label></div>';
			
			var _special2DivOff = document.createElement("div");
			this.setButtonStyle_(_special2DivOff);
			_special2DivOff.style.display = "none";
			_container.appendChild(_special2DivOff);
			_special2DivOff.innerHTML = '<img src="' + sDir + '/images/mm_20_brown.png" style="float: right; margin-left: 3px;" /> <div style="padding-top: 3px;"><input type="checkbox" checked="checked" onclick="return false" style="float: left" /> <label style="float: left; margin-left: 4px;">' + _label2 + '</label></div>';
			
			GEvent.addDomListener(_special2Div, "click", function() {
				_special2Div.style.display = "none";
				_special2DivOff.style.display = "block";
				document.getElementById('spec2').checked = false;				
				if (markerGroups["beautifulHarbour"].length==0) {
					getSpecialWaypoints("beautifulHarbour");
				} else {
					toggleSpecialWaypoints("beautifulHarbour");
				}
			});
	
			GEvent.addDomListener(_special2DivOff, "click", function() {
				_special2Div.style.display = "block";
				_special2DivOff.style.display = "none";
				document.getElementById('spec2').checked = false;
				toggleSpecialWaypoints("beautifulHarbour");
			});
	
			
		// Nautische Gefahrenstellen = 3
			var _special3Div = document.createElement("div");
			this.setButtonStyle_(_special3Div);
			_container.appendChild(_special3Div);
			_special3Div.innerHTML = '<img src="' + sDir + '/images/mm_20_red.png" style="float: right; margin-left: 3px;" /> <div style="padding-top: 3px;"><input type="checkbox" id="spec3" onclick="return false" style="float: left" /> <label style="float: left; margin-left: 4px;">' + _label3 + '</label></div>';
			
			var _special3DivOff = document.createElement("div");
			this.setButtonStyle_(_special3DivOff);
			_special3DivOff.style.display = "none";
			_container.appendChild(_special3DivOff);
			_special3DivOff.innerHTML = '<img src="' + sDir + '/images/mm_20_red.png" style="float: right; margin-left: 3px;" /> <div style="padding-top: 3px;"><input type="checkbox" checked="checked" onclick="return false" style="float: left" /> <label style="float: left; margin-left: 4px;">' + _label3 + '</label></div>';
			
			GEvent.addDomListener(_special3Div, "click", function() {
				_special3Div.style.display = "none";
				_special3DivOff.style.display = "block";
				document.getElementById('spec3').checked = false;				
				if (markerGroups["nauticalDangerousSpot"].length==0) {
					getSpecialWaypoints("nauticalDangerousSpot");
				} else {
					toggleSpecialWaypoints("nauticalDangerousSpot");
				}
			});
	
			GEvent.addDomListener(_special3DivOff, "click", function() {
				_special3Div.style.display = "block";
				_special3DivOff.style.display = "none";
				document.getElementById('spec3').checked = false;
				toggleSpecialWaypoints("nauticalDangerousSpot");
			});
		
		// Geniale Gastronomie = 4
			var _special4Div = document.createElement("div");
			this.setButtonStyle_(_special4Div);
			_container.appendChild(_special4Div);
			_special4Div.innerHTML = '<img src="' + sDir + '/images/mm_20_yellow.png" style="float: right; margin-left: 3px;" /> <div style="padding-top: 3px;"><input type="checkbox" id="spec4" onclick="return false" style="float: left" /> <label style="float: left; margin-left: 4px;">' + _label4 + '</label></div>';
			
			var _special4DivOff = document.createElement("div");
			this.setButtonStyle_(_special4DivOff);
			_special4DivOff.style.display = "none";
			_container.appendChild(_special4DivOff);
			_special4DivOff.innerHTML = '<img src="' + sDir + '/images/mm_20_yellow.png" style="float: right; margin-left: 3px;" /> <div style="padding-top: 3px;"><input type="checkbox" checked="checked" onclick="return false" style="float: left" /> <label style="float: left; margin-left: 4px;">' + _label4 + '</label></div>';
			
			GEvent.addDomListener(_special4Div, "click", function() {
				_special4Div.style.display = "none";
				_special4DivOff.style.display = "block";
				document.getElementById('spec4').checked = false;				
				if (markerGroups["perfectRestaurantBar"].length==0) {
					getSpecialWaypoints("perfectRestaurantBar");
				} else {
					toggleSpecialWaypoints("perfectRestaurantBar");
				}
			});
	
			GEvent.addDomListener(_special4DivOff, "click", function() {
				_special4Div.style.display = "block";
				_special4DivOff.style.display = "none";
				document.getElementById('spec4').checked = false;
				toggleSpecialWaypoints("perfectRestaurantBar");
			});
			
		// Sehenswürdigkeit = 6
			var _special6Div = document.createElement("div");
			this.setButtonStyle_(_special6Div);
			_container.appendChild(_special6Div);
			_special6Div.innerHTML = '<img src="' + sDir + '/images/mm_20_green.png" style="float: right; margin-left: 3px;" /> <div style="padding-top: 3px;"><input type="checkbox" id="spec6" onclick="return false" style="float: left" /> <label style="float: left; margin-left: 4px;">' + _label6 + '</label></div>';
			
			var _special6DivOff = document.createElement("div");
			this.setButtonStyle_(_special6DivOff);
			_special6DivOff.style.display = "none";
			_container.appendChild(_special6DivOff);
			_special6DivOff.innerHTML = '<img src="' + sDir + '/images/mm_20_green.png" style="float: right; margin-left: 3px;" /> <div style="padding-top: 3px;"><input type="checkbox" checked="checked" onclick="return false" style="float: left" /> <label style="left: right; margin-left: 4px;">' + _label6 + '</label></div>';
			
			GEvent.addDomListener(_special6Div, "click", function() {
				_special6Div.style.display = "none";
				_special6DivOff.style.display = "block";
				document.getElementById('spec6').checked = false;				
				if (markerGroups["dontMissToSeeThis"].length==0) {
					getSpecialWaypoints("dontMissToSeeThis");
				} else {
					toggleSpecialWaypoints("dontMissToSeeThis");
				}
			});
	
			GEvent.addDomListener(_special6DivOff, "click", function() {
				_special6Div.style.display = "block";
				_special6DivOff.style.display = "none";
				document.getElementById('spec6').checked = false;
				toggleSpecialWaypoints("dontMissToSeeThis");
			});
		
		// alle div's einhängen
		map.getContainer().appendChild(_container);
		
		return _container;
	};
	
	// Sets the proper CSS for the given button element.
	specialPointControl.prototype.setButtonStyle_ = function(button) {
	  button.style.textDecoration = "none";
	  button.style.color = "#000000";
	  button.style.backgroundColor = "white";
	  button.style.font = "small Arial";
	  button.style.fontSize = "11px";
	  button.style.border = "1px solid black";
	  button.style.padding = "2px";
	  button.style.marginLeft = "3px";
	  button.style.marginBottom = "1px";
	  button.style.textAlign = "left";
	  button.style.cursor = "pointer";
	  //button.style.cssFloat = "left";
	  button.style.width = "140px";
	  button.style.height = "20px";
	};
	
	//	//37	  
	
	specialPointControl.prototype.getDefaultPosition = function() {
		return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(7, 2));
	};
	map.addControl(new specialPointControl());
	 
	// Inhalt des Info-Fensters neu laden, wenn's geöffnet wurde
	GEvent.addListener(map, "infowindowopen", function() { 
		var infoWindow = map.getInfoWindow().getContentContainers();
		_turnId = jQuery("#info").attr("name");
		_poiId = jQuery("#info").attr("alt");

		//jQuery("#info").html(_turnId + " " + _poiId);
		//jQuery("#info").html($_getJSON)
		_zoom = map.getZoom();
		_lat = map.getCenter().lat();
		_lng = map.getCenter().lng();
		
		jQuery.get(sDir + "/ajax/getspecialwaypointsdetail/turnId/" + _turnId + "/poiId/" + _poiId + "/",{"zoom": _zoom, "lat": _lat, "lng": _lng},function(data) {
			//jQuery("#tochange").html('<b>' + data.name + '</b><br/><a href="' + data.link + '" target="view">Ansehen</a>');
			jQuery("#tochange").html(data);
		});
		
	});
	
	if (_spec1) document.getElementById('spec1').click();
	if (_spec2) document.getElementById('spec2').click();
	if (_spec3) document.getElementById('spec3').click();
	if (_spec4) document.getElementById('spec4').click();
	if (_spec6) document.getElementById('spec6').click();
	
    }
}

//Daten vom angeforderte Specialwaypoint laden
function getSpecialWaypoints(_waypointtype) {
    
    switch(_waypointtype) {
    	case "beautifulAnchorage"		: _type = 1; break;
    	case "beautifulHarbour"			: _type = 2; break;
    	case "nauticalDangerousSpot"	: _type = 3; break;
    	case "perfectRestaurantBar"		: _type = 4; break;
    	case "dontMissToSeeThis"		: _type = 6; break;
    }
    
    var data = new Request.JSON({  
    	url: sDir + "/ajax/getspecialwaypoints/type/" + _type + "/",   
    	onSuccess: function(_specialwaypoints){
    		//alert(_specialwaypoints);
    		
    		for (var i=0;i<_specialwaypoints.length-1;i++)
	    	{
	    		//alert(_specialwaypoints[i].poiLat + " " + _specialwaypoints[i].poiLon);
	    		
    			var latlng = new GLatLng(_specialwaypoints[i].poiLat, _specialwaypoints[i].poiLon);
	    		var marker = createMarker(latlng, _specialwaypoints[i].turnId, _specialwaypoints[i].id, _waypointtype);
	    		map.addOverlay(marker);
	    		
	    	}
    	}
    }).get($('signup'));
    
}

function createMarker(point, id, poiId, type) {
    var marker = new GMarker(point, customIcons[type]);
    markerGroups[type].push(marker);
    var html = '<div id="info" name="' + id + '" alt="' + poiId + '"><div id="tochange" style="width: 410px;height: 270px"></div></div>';
    GEvent.addListener(marker, 'click', function() {
    	marker.openInfoWindowHtml(html,{maxWidth:400});
    });
    return marker;
}


function toggleSpecialWaypoints(_waypointtype) {
	var _lastaction = "";
	for (var i = 0; i < markerGroups[_waypointtype].length; i++) {
	  var marker = markerGroups[_waypointtype][i];
	  if (marker.isHidden()) {
	    marker.show();
	    _lastaction = "show";
	  } else {
	    marker.hide();
	    _lastaction = "hide";
	  }
	} 
	jQuery.get(sDir + "/ajax/setspecialwaypointmarker/type/" + _waypointtype + "/checkbox/" + _lastaction + "/",function() {});
}

function loadMap(cid,pid) {

    if (GBrowserIsCompatible()) {
//     	alert('<? echo $zones[name]; ?>');
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(47.98, 28.18),15);
//        map.setZoom(6);
// 		map.enableScrollWheelZoom();	  
		map.addControl(new GLargeMapControl3D());
		map.addMapType(G_PHYSICAL_MAP);
		var hControl = new GHierarchicalMapTypeControl();
		hControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
		map.addControl(hControl);
		map.disableScrollWheelZoom();
      	
        bounds = new GLatLngBounds();
      	mgr = new MarkerManager(map);     	
      	var mcOptions = { gridSize: 50, maxZoom: 3};
		mc = new MarkerClusterer(map, startmarkers, mcOptions);		
	    //  mgr.refresh();
        //Anzeige fï¿½r direkte link
		if (cid) {

			showLatestPoi2(cid, pid); 
		}
		else
		{
		var ret = readURL();
			if (ret)
			{
				
				if (ret['task'] == "showTurn") {
			    		showLatestPoi(ret['id'], ret['pid']); 
			        }
			        else if (ret['task'] == "bc")
			        {
			        	getTurnsByCountry(ret['i']);
			        }
			        else if (ret['task'] == "bd")
			        {
			        	getTurnsByDistrict(ret['i']);
			        }
			}
	        else
	        {
		      	//moveMap(48,30,-51,12);
		     	getTurns();
	      	}
		}
	}
}


function getTurns() {
    var dude = new Request.JSON({  
        url: sDir + "/ajax/getturns/",   
        onSuccess: function(turns){  
    	var startmarkers = [];
       	var markers = [];
       	var standardIcon = new GIcon(baseIcon, sDir + "/images/normal.png", null, "http://maps.google.com/mapfiles/kml/pal5/icon14s.png");

	    	for (var i=0;i<turns.length-1;i++)
	    	{
	    		var latlng = new GLatLng(turns[i].poiLat, turns[i].poiLon);
	    		var marker = createTurnMarker(latlng, turns[i], standardIcon);
	    		// var marker = new GMarker(latlng, {icon: icon});

	    		//bounds.extend(latlng);
	    		startmarkers.push(marker);
	    	}
	    	

	    	//&&mc = new MarkerClusterer(map, startmarkers);		
			//viewTurns(turns);
		      var icon = new GIcon(G_DEFAULT_ICON);
		      icon.image = "http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png";

		      for (var i = 0; i < 100; ++i) {
		        var latlng = new GLatLng(data.photos[i].latitude, data.photos[i].longitude);
		        var marker = new GMarker(latlng, {icon: icon});
		        markers.push(marker);
		      }
		      var markerCluster = new MarkerClusterer(map, startmarkers);
			       
         }  
     }).get($('signup'));  
}

function getTurn(cruiseID) {
    var dude = new Request.JSON({

        url: sDir + "/ajax/getturn/cruiseId/" + cruiseID,   
        onSuccess: function(turn){  
			mc.clearMarkers();
			mgr.clearMarkers();
			gmarkers = [];
			bounds = new GLatLngBounds();
			
			viewTurn(turn);
			document.getElementById("displaySwitcher").href = sDir + '/page/turn/cruiseId/' + cruiseID;
			
			mgr.addMarkers(gmarkers,1);	
			mgr.refresh();
			map.setZoom(map.getBoundsZoomLevel(bounds));
			map.setCenter(bounds.getCenter());
			viewPOIs = true;
         }  
     }).get($('signup'));  
}
function getTurnShowShowPOI(cruiseID, poiID) {
    var dude = new Request.JSON({

        url: sDir + "/ajax/getturn/cruiseId/" + cruiseID,   
        onSuccess: function(turn){  
			mc.clearMarkers();
			mgr.clearMarkers();
			gmarkers = [];
			bounds = new GLatLngBounds();
			
			viewTurn(turn);
			
			mgr.addMarkers(gmarkers,1);	
			mgr.refresh();
			map.setZoom(map.getBoundsZoomLevel(bounds));
			map.setCenter(bounds.getCenter());
			viewPOIs = true;
         }  
     }).get($('signup'));  
}



function showFullTurn() {
	map.setZoom(map.getBoundsZoomLevel(bounds));
	map.setCenter(bounds.getCenter());
	
}

function getTurnsByUser(userID) {
    var dude = new Request.JSON({  
        url: sDir + "/ajax/getturnsbyuser/userId/" + userID,   
        onSuccess: function(turns){  
			viewTurns(turns);
			document.getElementById("displaySwitcher").href = sDir + '/page/turns/userId/' + userID;
         }  
     }).get($('signup'));  
}

function getTurnsByCountry(country) {
    var dude = new Request.JSON({  
        url: sDir + "/ajax/getturnsbycountry/country/" + country,   
        onSuccess: function(turns){  
			viewTurns(turns);
			document.getElementById("displaySwitcher").href = sDir + '/page/turns/countryId/' + country;
			//$('blogviewmenu').set('html', '<div style="display:inline;line-height:44px;"><img src="my-my-global/images/arrow-right.png" height="22px"  /></div><a href="' + sDir + '/blogview/turns/countryId/' + country + '" style="text-decoration: none; z-index: 10; color: rgb(255, 255, 255); position: relative; top: -6px; padding-left: 4px;">Listendarstellung</a>');
         }  
     }).get($('signup'));  
}
function getTurnsByDistrict(districtId) {
    var dude = new Request.JSON({  
        url: sDir + "/ajax/getturnsbydistrict/districtId/" + districtId,   
        onSuccess: function(turns){  
			viewTurns(turns);
			document.getElementById("displaySwitcher").href = sDir + '/page/turns/districtId/' + districtId;
			//$('blogviewmenu').set('html', '<div style="display:inline;line-height:44px;"><img src="my-my-global/images/arrow-right.png" height="22px"  /></div><a href="' + sDir + '/blogview/turns/districtId/' + districtId + '" style="text-decoration: none; z-index: 10; color: rgb(255, 255, 255); position: relative; top: -6px; padding-left: 4px;">Listendarstellung</a>');
         }  
     }).get($('signup'));  
}

function viewTurns(turns) {
	if (line != null)
		map.removeOverlay(line);

	mc.clearMarkers();
	mgr.clearMarkers();
	startmarkers = [];
	bounds = new GLatLngBounds();
	
	

}

function moveMap(N, E, S, W) {

	if (viewPOIs === true) {
		map.removeOverlay(line);
		mgr.clearMarkers();
		mc.clearMarkers();
		mc = new MarkerClusterer(map, startmarkers);		
		viewPOIs = false;
		//alert('alert');
	}
        bounds = new GLatLngBounds();
	var latlng1 = new GLatLng(N,S);
	var latlng2 = new GLatLng(E,W);	
	
		bounds.extend(latlng1);
		bounds.extend(latlng2);
	map.setZoom(4);
	map.setCenter(bounds.getCenter());
}

function myclick(i) {
	GEvent.trigger(gmarkers[i], "click");
}

function createTurnMarker(posn, turn, icon) {
//var imgPath = '../../userfiles/images/' + poi.userID + '/' + poi.cruiseID + '-' + poi.poiID;
	var html = '<div class="popUpWindow"><h1>' + turn.cruiseName + '</h1>';
	//if (url != "") { html += '<a href="' + url + '" rel="milkbox"><img height="200" width="200" src="' + url + '" /></a><br/>' };
	if (turn.poiCommentText != "" && turn.poiCommentText != null) { html += '<p>' + turn.poiCommentText + '</p>' };
	if (turn.cruiseStartDate != "" && turn.cruiseStartDate != null) { html += '<p>start: ' + turn.cruiseStartDate + '</p>' };
	if (turn.cruiseEndDate != "" && turn.cruiseEndDate != null) { html += '<p>end: ' + turn.cruiseEndDate + '</p>' };
//	if (turn.poiImage != 0 && poi.poiImage != null) { html += '<div class="Display"><a rel="lightbox" onclick="Slimbox.open(\'' + imgPath + '.jpg' + '\',\'Caption\');return false;" href="' + imgPath + '.jpg' + '"><img width="' + poi.poiImgW + 'px;" height="' + poi.poiImgH + 'px;" src="' + imgPath + '-tn.jpg' + '"/></a></div>' };
	
	html += '<a class="viewTurn" href="javascript:getTurn(' + turn.id + ')">'+l.view_trip+'</a>';
	html += '</div>';
	var marker = new GMarker(posn, {title: turn.cruiseName, icon: icon, draggable:false }); 
	//  GEvent.addListener(marker, 'click', function() { mgr.removeMarker(marker) } ); 
	GEvent.addListener(marker, 'click', function() { window.location=sDir + '/page/turn/cruiseId/' + turn.id; } ); 
	return marker;
}

function createPoiMarker(posn, icon, poi) {

	var imgPath = iDir + '/' + poi.userID + '/' + poi.cruiseID + '-' + poi.poiID;
	var html = '<div class="popUpWindow">';
	if (poi.poiDate !== 0 && poi.poiDate !== null) { html += '<p class="date">' + poi.poiDate + '</p>' ;}
	html += '<h3 class="poiName main">' + poi.poiName + '</h3>';
	if (!(poi.poiImgW && poi.poiImgH)) { poi.poiImgW = 125; poi.poiImgH = 125; } 
//	if (poi.poiImage != 0 && poi.poiImage != null) { html += '<div class="Display"><a rel="lightbox" onclick="Slimbox.open(\'' + imgPath + '-medium.jpg' + '\',\'myLog\');return false;" href="' + imgPath + '-medium.jpg' + '"><img width="' + poi.poiImgW + 'px;" height="' + poi.poiImgH + 'px;" src="' + imgPath + '-tn.jpg' + '"/></a></div>' };
	if (poi.poiImage != 0 && poi.poiImage != null) { html += '<div class="Display poi_img"><img class="poiimg" width="176" height="176" src="' + imgPath + '-tn.jpg' + '"/></div>' };
	if (poi.poiWeather !== 0 && poi.poiWeather !== null && poi.poiWeather !=="") { html2 += '<p>Wetter: ' + poi.poiWeather + '</p>' ;}
	if (poi.poiSituation !== 0 && poi.poiSituation !== null && poi.poiSituation !== "") { html2 += '<p>Situation: ' + poi.poiSituation + '</p>'; }
	html += '<p class="cruiseName">'+l.trip+': ' + poi.cruiseName + '</p>';
	html += '</div>';

	var html2 = '<div class="popUpWindow">';
	//html2 += '<p>' + imgPath + '</p>';
//	if (poi.poiSituationAction !== 0 && poi.poiSituationAction !== null) { html2 += '<p>Situation Action:' + poi.poiSituationAction + '</p>'; }

	html2 += '<p>';
	if (poi.poiLongitude !== 0 && poi.poiLongitude !== null) { html2 +=  poi.poiLon2 + ' - ' + poi.poiLat2 + '<br/>' ;}
	if (poi.poiDirection !== "" && poi.poiDirection !== null) { if  (poi.poiDirection == 0){html2 += 'CoG: n.a. '; } else { html2 += 'CoG: ' + poi.poiDirection + 'Â° * ' ;}}
	if (poi.poiSpeed !== "" && poi.poiSpeed !== null) {if (poi.poiSpeed <= 0) {html2 += '* SoG: n.a.';} else { html2 += '* SoG: ' + parseFloat(poi.poiSpeed).toFixed(1) + ' kn'; }}
	html2 += '</p>';

	html2 += '<p><i class="black">'+l.last_waypoint+'</i><br/>';
	if (poi.poiDistance !== "" && poi.poiDistance !== null) { html2 += parseFloat(poi.poiDistance).toFixed(1) + ' nm'; }
	if (poi.poiDateDiff !== "" && poi.poiDateDiff !== null) { html2 += ' * ' + poi.poiDateDiff + 'h '; }
	html2 += '</p>';

	if (poi.poiWeather !== "" && poi.poiWeather !== null) { 
		html2 += '<p><i class="black">'+l.weather+'</i><br/>';
		if (poi.poiWeather !== "" && poi.poiWeather !== null) { html2 +=  poi.poiWeather; }
		html2 += '</p>';
	}

	if (poi.poiSituation !== "" && poi.poiSituation !== null) { 
		html2 += '<p><i class="black">'+l.situation+'</i><br/>';
		if (poi.poiSituation !== "" && poi.poiSituation !== null) { html2 +=  poi.poiSituation; }
		html2 += '</p>';
	}

	if (poi.poiCommentText !== "" && poi.poiCommentText !== null) { html2 += '<p style="width:275px">' + poi.poiCommentText + '</p>'; }
	html2 += '</div>';
	if (poiID) {
		if (poiID==poi.poiID) {
			html += '<a class="viewTurn" href="javascript:showFullTurn()">'+l.view_trip+'</a>';
			globalPOI['html'] = html;
			globalPOI['html2'] = html2;
		}
	}
//	html += '<a href="#"><img src="images/boat_icon.png" /></a><br/>';
	var marker = new GMarker(posn, {title: poi.poiName, icon: icon, draggable:false }); 
	GEvent.addListener(marker, 'click', function() { 
	       marker.openInfoWindowTabsHtml([new GInfoWindowTab("main",html), new GInfoWindowTab("info",html2)]);
	       //		marker.updateInfoWindow(html);
	} ); 
	return marker;
}

/*
/*
	ANZEIGE EINES EINZELNEN TURNS
*/

function viewTurn(turn) {

	var latlngArr=[];
	if (line != null)
		map.removeOverlay(line);

	for (var i=0; i< turn.length;i++)
	{
		var poi = turn[i];
		var latlng = new GLatLng(turn[i].poiLat, turn[i].poiLon);

		icon = standardIcon;
		
		if (i==0) {
			icon = startIcon;
			poi.poiName += " (<i>start</i>)";
		}
		if (i == (turn.length-1)) {
			icon = stopIcon;
			poi.poiName += " (<i>end</i>)";
		}
		

		var marker = createPoiMarker(latlng, icon, poi);
		latlngArr.push(latlng);
		bounds.extend(latlng);
		gmarkers.push(marker);
		side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '<\/a><br>';
		
	}
	//line.remove();
	line = new GPolyline(latlngArr,'#487DDA', 3, 1);
	map.addOverlay(line);
		//map.setCenter(33,44);
	//alert(turn.length);
	//alert(line);
}
function showLatestPoi(cruiseID, lpoiID) {


	var startmarkers = [];
	bounds = new GLatLngBounds();
var dude = new Request.JSON({

    url: sDir + "/ajax/getturn/cruiseId/" + cruiseID,   
    onSuccess: function(turn){  		
		gmarkers = [];
     	mgr = new MarkerManager(map);     	

		poiID = lpoiID;
	
		viewTurnLatestPoi(turn);			
		mgr.addMarkers(gmarkers,1);	
		mgr.refresh();

		document.getElementById("displaySwitcher").href = sDir + '/page/turn/cruiseId/' + cruiseID;
		if (poiID) {
			map.setCenter(latlngArr[globalPOI['id']] ,17);

			gmarkers[globalPOI['id']].openInfoWindowTabsHtml([new GInfoWindowTab("main",globalPOI['html']), new GInfoWindowTab("info",globalPOI['html2'])]);
		}
		else
		{
			map.setZoom(map.getBoundsZoomLevel(bounds));
			map.setCenter(bounds.getCenter());
			
		}

//		viewPOIs = true;
		//$('blogviewmenu').set('html', '<div style="display:inline;line-height:44px;"><img src="my-my-global/images/arrow-right.png" height="22px"  /></div><a href="' + sDir + '/blogview/turn/cruiseId/' + cruiseID + '" style="text-decoration: none; z-index: 10; color: rgb(255, 255, 255); position: relative; top: -6px; padding-left: 4px;">Listendarstellung</a>');
		poiID=null;
    }  
 }).get($('signup'));  
}
function showLatestPoi2(cruiseID, lpoiID) {
	mc.clearMarkers();
	mgr.clearMarkers();
	startmarkers = [];
	bounds = new GLatLngBounds();
var dude = new Request.JSON({

    url: sDir + "/ajax/getturn/cruiseId/" + cruiseID,   
    onSuccess: function(turn){  
		gmarkers = [];
		poiID = lpoiID;

		viewTurnLatestPoi(turn);			
		mgr.addMarkers(gmarkers,1);	
		mgr.refresh();

		
		if (poiID) {
			//map.setCenter(latlngArr[globalPOI['id']] ,10);
			map.setZoom(map.getBoundsZoomLevel(bounds));
			map.setCenter(bounds.getCenter());
			gmarkers[globalPOI['id']].openInfoWindowTabsHtml([new GInfoWindowTab("main",globalPOI['html']), new GInfoWindowTab("info",globalPOI['html2'])]);
		}
		else
		{
			map.setZoom(map.getBoundsZoomLevel(bounds));
			map.setCenter(bounds.getCenter());
			
		}
//		viewPOIs = true;
		//$('blogviewmenu').set('html', '<div style="display:inline;line-height:44px;"><img src="my-my-global/images/arrow-right.png" height="22px"  /></div><a href="' + sDir + '/blogview/turn/cruiseId/' + cruiseID + '" style="text-decoration: none; z-index: 10; color: rgb(255, 255, 255); position: relative; top: -6px; padding-left: 4px;">Listendarstellung</a>');
		poiID=null;
    }  
 }).get($('signup'));  
}

function viewTurnLatestPoi(turn) {
//alert('uh');
	latlngArr=[];
	if (line != null) {
		map.removeOverlay(line);
	}

	for (var i=0; i< turn.length;i++)
	{
		var poi = turn[i];
		var latlng = new GLatLng(turn[i].poiLat, turn[i].poiLon);
		icon = standardIcon;
		
		if (i==0) {
			icon = startIcon;
			poi.poiName += " (<i>start</i>)";
		}
		if (i == (turn.length-1)) {
			icon = stopIcon;
			poi.poiName += " (<i>end</i>)";
		}
		

		var marker = createPoiMarker(latlng, icon, poi);
		if (poi.poiID == poiID) { globalPOI['id'] = i;}
		latlngArr.push(latlng);
		bounds.extend(latlng);
		gmarkers.push(marker);
		
		
	}
	//line.remove();
	line = new GPolyline(latlngArr,'#487DDA', 3, 1);
	map.addOverlay(line);
		//map.setCenter(33,44);
	//alert(turn.length);
}





/*
GET DATA FOR FILTER
*/
function getLatestFilter() {
   var dude = new Request.JSON({  
        url: sDir + "/ajax.php?task=latest",   
        onSuccess: function(latest){  
			var ul=document.getElementById('ul_latest');

			while(ul.hasChildNodes()){
				ul.removeChild(ul.lastChild);		
			}
			for (i=0; i< latest.length; i++)
			{
				var li=document.createElement('li');
				var chk=document.createElement('input');
				var type=document.createAttribute('type');
				type.nodeValue='checkbox';
				chk.setAttributeNode(type);
				
				var val=document.createAttribute('value');
				val.nodeValue=latest[i].id;
				chk.setAttributeNode(val);
								
				li.appendChild(chk);
				
				var link=document.createElement('a');
				var href = document.createAttribute('href');
				href.nodeValue = 'javascript:getTurn('+latest[i].id+')';
				link.setAttributeNode(href);
				var title = document.createAttribute('title');
				title.nodeValue = latest[i].cruiseDate;
				link.setAttributeNode(title);
				link.appendChild(document.createTextNode(latest[i].cruiseName ));

				li.appendChild(link);

				ul.appendChild(li);
				myAccordion.display(4);
				myAccordion.display(0);
			}
			//alert(users.length);
			
         }  
     }).get($('signup'));  
}

function getUsersFilter() {
   var dude = new Request.JSON({  
        url: sDir + "/ajax.php?task=getUsersFilter",   
        onSuccess: function(users){  
			var ul=document.getElementById('ul_user');

			while(ul.hasChildNodes()){
				ul.removeChild(ul.lastChild);		
			}
			
			for (i=0; i< users.length; i++)
			{
				var li=document.createElement('li');
				var chk=document.createElement('input');
				var type=document.createAttribute('type');
				type.nodeValue='checkbox';
				chk.setAttributeNode(type);
				
				var val=document.createAttribute('value');
				val.nodeValue=users[i].id;
				chk.setAttributeNode(val);
								
				li.appendChild(chk);
				
				//Userlink
				var link=document.createElement('a');
				var href = document.createAttribute('href');
				href.nodeValue = 'javascript:getTurnsByUser('+users[i].id+')';
				link.setAttributeNode(href);

				link.appendChild(document.createTextNode(users[i].name));

				li.appendChild(link);

				ul.appendChild(li);
				//myAccordion.display(3);
				//myAccordion.display(0);
			}
			//alert(users.length);
			
         }  
     }).get($('signup'));  
}

function getTurnsFilter(userid) {
   var dude = new Request.JSON({  
        url: sDir + "/ajax.php?task=4",   
        onSuccess: function(turns){  
			var ul=document.getElementById('ul_turns');

			while(ul.hasChildNodes()){
				ul.removeChild(ul.lastChild);		
			}
			
			for (i=0; i<= turns.length; i++)
			{
				var li=document.createElement('li');
				var chk=document.createElement('input');
				var type=document.createAttribute('type');
				type.nodeValue='checkbox';
				chk.setAttributeNode(type);
				
				var val=document.createAttribute('value');
				val.nodeValue=turns[i].id;
				chk.setAttributeNode(val);
				
				li.appendChild(chk);
				var link=document.createElement('a');
				var href = document.createAttribute('href');
				href.nodeValue = 'javascript:getTurn('+turns[i].id+')';
				link.setAttributeNode(href);
				link.appendChild(document.createTextNode(turns[i].cruiseName));
				//li.appendChild(link);<a href="#"></a>
				//li.
				li.appendChild(link);
				ul.appendChild(li);
				myAccordion.display(4);
				myAccordion.display(2);
			}
			
         }  
     }).get($('signup'));  
}




//Startmarker zu testzwecken schnell anlegen
function addturns() {
       GEvent.addListener(map, "click", function(overlay, point) {   
		  	if(overlay)
			{
				map.openInfoWindowHtml(overlay.getPoint(), "Latitude=" + overlay.getPoint().lat() + "<br/>" + "Longitude=" + overlay.getPoint().lng());
			}
			else
			{
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml("Latitude=" + point.lat() + "<br/>" + "Longitude=" + point.lng());
				
				var json = new Request.JSON({  
					url: sDir + "/ajax.php?task=2&lat=" + point.lat() + "&lon=" + point.lng(),   
					onSuccess: function(response){  
			
						alert(response);

					 }  
				 }).get($('signup'));  
			}
        
        });
}
function readURL() {
  //alert('aler');

	query = window.location.search;
	sammlung = new Array();


	if (query !== '')
	{
	  query = query.substr(1, query.length - 1);
	  query = query.replace(/%26/,'&');
	  teile = query.split('&');
	
	  for (i = 0; i < teile.length; i++)
	  {
	  teile[i] = teile[i].split('=');
	  sammlung[teile[i][0]] = teile[i][1];
	  	if (teile[i][0] == "visited") {
	  		return false;
	  	}
	  }
		return sammlung;	
	}
}




