var map;		
map = '';

// CREATE MARKER
function createMarker(point,name,labels,htmls,icon,route)
{
	var marker = new GMarker(point,myicons[icon]);
	// === store the name so that the tooltip function can use it ===
	marker.tooltip = '<div class="tooltip"><nobr>'+name+'</nobr></div>';
	
	// MIT ROUTING FUNKTION ?
	if(route == "yes")
	{
		htmls[(htmls.length)-1] 	+= 	'<br><a href="http://maps.google.com/maps?saddr=&daddr=' + point.toUrlValue() + '" target ="_blank">Route planen</a>';
	}
	
	// KLICK �FFNET INFOS
	GEvent.addListener(marker, "click", function() 
	{
  		// adjust the width so that the info window is large enough for this many tabs
  		if (htmls.length > 2) 
		{
    		htmls[0] = '<div style="width:'+htmls.length*88+'px">' + htmls[0] + '</div>';
		}
						
  		var tabs = [];
		
		// TABS ERZEUGEN
  		for (var i=0; i<htmls.length; i++) 
		{
    		tabs.push(new GInfoWindowTab(labels[i],htmls[i]));
  		}
  		
		if(htmls.length != 0)
		{
			marker.openInfoWindowTabsHtml(tabs);
		}
	});
	
	// OVER �FFNET INFOS
	GEvent.addListener(marker, "mouseover", function() 
	{
  		// adjust the width so that the info window is large enough for this many tabs
  		if (htmls.length > 2) 
		{
    		htmls[0] = '<div style="width:'+htmls.length*88+'px">' + htmls[0] + '</div>';
		}
						
  		var tabs = [];
		
		// TABS ERZEUGEN
  		for (var i=0; i<htmls.length; i++) 
		{
    		tabs.push(new GInfoWindowTab(labels[i],htmls[i]));
  		}
  		
		if(htmls.length != 0)
		{
			marker.openInfoWindowTabsHtml(tabs);
		}
	});
	
	// SIDEBAR INFO
	gmarkers[i] = marker;
	
	// SIDEBAR GENERIEREN
	side_bar_html += '<a href="javascript:myclick(' + i + ')" onmouseover="mymouseover('+i+')" onmouseout="mymouseout()">' + name + '</a><br>';
	
	i++;
	
	// TOOLTIP MOUSEOVER /OUT
	GEvent.addListener(marker,"mouseover", function() 
	{
  		showTooltip(marker);
	}); 
	       
	GEvent.addListener(marker,"mouseout", function() 
	{
		tooltip.style.visibility="hidden"
	}); 
	
	//return marker;
	map.addOverlay(marker);
	
	// SIDEBAR ERZEUGEN
	document.getElementById("side_bar").innerHTML = side_bar_html;
	// ==================================================
}
// ==================================================


// TOOLTIP
function showTooltip(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=tooltip.clientHeight;
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
	pos.apply(tooltip);
	tooltip.style.visibility="visible";
}
// ==================================================


// SIDEBAR MOUSEOVER /OUT
function mymouseover(i) 
{
	//showTooltip(gmarkers[i])
	GEvent.trigger(gmarkers[i], "click");
}

function mymouseout() 
{
	tooltip.style.visibility="hidden";
}
// ==================================================


// SIDEBAR CLICK
function myclick(i) 
{
	GEvent.trigger(gmarkers[i], "click");
}	
// ==================================================	

	

//  OVERVIEW FORMATIEREN
function positionOverview(x,y)
{
    var omap=document.getElementById("map_overview");
    omap.style.left = x+"px";
    omap.style.top = y+"px";
    
    // == restyling ==
    omap.firstChild.style.border = "1px solid red";
    omap.firstChild.firstChild.style.left="4px";
    omap.firstChild.firstChild.style.top="4px";
    omap.firstChild.firstChild.style.width="90px";
    omap.firstChild.firstChild.style.height="90px";
}
//  ======== Cause the overview to be positioned AFTER IE sets its initial position ======== 
	//setTimeout("positionOverview(558,254)",1);
// ==================================================


// PAGESCROLL ABSCHALTEN
function wheelevent(e)
{
	if (!e)
	{
		e = window.event
	}
	if (e.preventDefault)
	{
		e.preventDefault()
	}
	e.returnValue = false;
}


//AUTO ZUR�CKZOOMEN		
function esasZoomOut()
{
	var paragraphs = map.getContainer().getElementsByTagName('p').length;
	if(paragraphs > 6)
	{
		map.zoomOut();
	}
}
// ================================================== 