GM_Styles();
function GM_Styles() {
	// Set up some styles
	document.writeln('		<style type="text/css">');
	document.writeln('			.gv_tooltip { background-color:#ffffff; filter:alpha(opacity=100); -moz-opacity:1.0; border:1px solid #666666; padding:2px; text-align:left; font:10px Verdana,sans-serif; color:black; white-space:nowrap; }');
	document.writeln('			.gv_tooltip img.gv_marker_thumbnail { display:block; padding-top:3px; }');
	document.writeln('			.gv_tooltip img.gv_marker_photo { display:none; }');
	document.writeln('		</style>');
}


function GM_Initialize_Marker_Tooltip(map) {
	var mtt = document.createElement('div');
	mtt.id = 'gm_marker_tooltip';
	mtt.style.visibility = 'hidden';
	map.getPane(G_MAP_FLOAT_PANE).appendChild(mtt);
	return (mtt);
}

function GM_Create_Marker_Tooltip(map,marker) {
	// copied almost verbatim from http://www.econym.demon.co.uk/googlemaps/tooltips4.htm
	if (!marker || !marker.tooltip) { return false; }
	document.getElementById('gm_marker_tooltip').innerHTML = marker.tooltip;
	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var height=document.getElementById('gm_marker_tooltip').clientHeight;
	offset.x += -1; offset.y += 4; // a little adjustment
	height = 18; // makes all tooltips hover near the icon, even if they're tall and have thumbnails or whatnot (they expand downward instead of upward)
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x -point.x -anchor.x +width, offset.y -point.y -anchor.y -height*0.75)); 
	pos.apply(document.getElementById('gm_marker_tooltip'));
	document.getElementById('gm_marker_tooltip').style.visibility = 'visible';
}

function GM_Hide_Marker_Tooltip() {
	document.getElementById('gm_marker_tooltip').style.visibility = 'hidden';
}

function createMarker(map, longitude, latitude, infoWindowContent, name, index, status) {
	eval('point' + index + '= new GPoint(longitude,latitude);');
	eval('var thisPoint = point' + index +';');
	
	eval('centerPoint' + index + '= new GLatLng(longitude,latitude);');
	eval('var thisCenterPoint = centerPoint' + index +';');
	
	eval('icon' + index + '= freecross_' + status + ';');
	eval('var thisIcon = icon' + index +';');
	
	thisIcon.image = "/tl_files/googleMaps/images/freecross_" + status + "_google.png";
	
	var markerOptions = {icon:thisIcon};
	
	eval('marker' + index + '= new GMarker(thisPoint, markerOptions);');
	eval('var thisMarker = marker' + index +';');
	
	GEvent.addListener(thisMarker, 'click', function() {
		map.setZoom(7);
		thisMarker.openExtInfoWindow(
			map,
			"freecross_infoWindow",
			infoWindowContent,
			{beakOffset: 3, paddingX: 26, paddingY: 5}
		);
		WSopenClose('eventListItem'+index);
	});
	
	GEvent.addListener(thisMarker, 'listclick', function() {
		map.setZoom(7);
		thisMarker.openExtInfoWindow(
			map,
			"freecross_infoWindow",
			infoWindowContent,
			{beakOffset: 3, paddingX: 26, paddingY: 5}
		);
	});
	
	if (!document.getElementById('gm_marker_tooltip')) { gm_marker_tooltip = GM_Initialize_Marker_Tooltip(map); } // initialize it if it hasn't been done yet
	var tooltip_html = name;
	thisMarker.tooltip = '<div class=\"gv_tooltip\">' + tooltip_html + '</div>';
	
	GEvent.addListener(thisMarker,'mouseover', 
		function() { 
			GM_Create_Marker_Tooltip(map,thisMarker);
			if(document.getElementById('eventListItem'+index)){
				document.getElementById('eventListItem'+index).addClass('active');
			}
		}
	);
	
	GEvent.addListener(thisMarker,'mouseout', 
		function() { 
			GM_Hide_Marker_Tooltip();
			if(document.getElementById('eventListItem'+index) && !$('eventListItem'+index).hasClass('open')){
				document.getElementById('eventListItem'+index).removeClass('active');	
			}
		}
	);
	
	map.addOverlay(thisMarker);
}

function handleErrors(){
   if (map.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + map.getStatus().code);
   else if (map.getStatus().code == G_GEO_SERVER_ERROR)
     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + map.getStatus().code);
   
   else if (map.getStatus().code == G_GEO_MISSING_QUERY)
     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + map.getStatus().code);
     
   else if (map.getStatus().code == G_GEO_BAD_KEY)
     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + map.getStatus().code);

   else if (map.getStatus().code == G_GEO_BAD_REQUEST)
     alert("A directions request could not be successfully parsed.\n Error code: " + map.getStatus().code);
    
   else alert("An unknown error occurred.");
}

function isset(varname)  {
  if(typeof( window[ varname ] ) != "undefined") return true;
  else return false;
}

function WSopenClose(elementId) {
	$$('#tour-dates li').each(
		function(el, i ){
				if (el.getProperty('id') == elementId) {
					wsAC.display(i);
				}
				else {
					//Active und Open zustand von allen Elementen entfernen
					$$('#tour-dates li').removeClass('active');
					$$('#tour-dates li').removeClass('open');
					
					//Dem Aktuellen Element active / open zustand geben
					$(elementId).addClass('active');
					$(elementId).addClass('open');
				}
			
		}
	);
}

function listElementMouseOver(id){
	eval('thisMarker = marker' + id +';');
	GM_Create_Marker_Tooltip(map,thisMarker); 
	$('eventListItem' + id).style.cursor = 'hand'; 
	$('eventListItem' + id).style.cursor = 'pointer';
}

function listElementMouseOut(id){
	GM_Hide_Marker_Tooltip(); 
	$('eventListItem' + id).style.cursor = 'default';
}

function listElementClick(id){
	eval('thisMarker = marker' + id +';');
	GEvent.trigger(thisMarker,'listclick');
}

function mapLoadCheck() {
	if (map.isLoaded()) {
		//This is so fragile, it's scary
		var map_ctl = $('#map div.gmnoprint img[src$="mapcontrols2.png"]');
	    if (map_ctl.get(0)) {
	    	clearInterval(mapLoadCheckInt);
	    	map_ctl.attr('src', 'mapcontrols2_custom.png');
	    	$('#map_overlay').fadeOut();
	    }
	}
}; 