/* google maps */

markers = new Array();
var marker_here = null;

glIcon = new GIcon();
glIcon.shadow = "/grafiken/maps_sh.png";
glIcon.iconSize = new GSize(32, 32);
glIcon.shadowSize = new GSize(49, 32);
glIcon.iconAnchor = new GPoint(5, 34);
glIcon.infoWindowAnchor = new GPoint(9, 2);
glIcon.infoShadowAnchor = new GPoint(18, 25);
glIcon.image = "/grafiken/maps_here.png";

function show_mini_info(i,name,place_id,static_url) {

  if ( marker_here != null ) return;

  var m = markers[i];

  marker_here = new GMarker(m.point,glIcon);
  marker_here.index = i;

  GEvent.addListener(marker_here, "mouseout", quickclose );   
  
  if(place_id != 0)
  {
  	GEvent.addListener(marker_here, "click", function() { document.location=""+static_url; });
    GEvent.addListener(marker_here, "click", function() { quickinfo(i); });
  }

  map.addOverlay(marker_here);

  map.removeOverlay( markers[i] );

  // label
  var text = "<div id=\"map_label\" onmouseover=\"quickclose();\"><div class=\"namelabel\">"+name+"</div></div>";
	
  // first div
  var div1 = document.createElement("div");
  div1.className="map_label_inner";
  document.body.appendChild(div1);

  // second div
  var div2=document.createElement('div');
  div2.className="map_label_wrap";
  div2.innerHTML = text;
  div1.appendChild(div2);

  // pixel relative to map world
  var p = map.fromLatLngToDivPixel(m.point);

  // map world relative to map container
  var dragObject = map.getPane(G_MAP_MAP_PANE).parentNode;
  var x = p.x + parseInt(dragObject.style.left);
  var y = p.y + parseInt(dragObject.style.top);

  // map container relative to the page
  y += map.getContainer().offsetTop;
  x += map.getContainer().offsetLeft;

  // Apply those values 
  div1.style.left = (x+26)+"px";
  div1.style.top = (y-31)+"px";
}

function quickclose() {
  if ( marker_here != null ) {
	map.addOverlay( markers[ marker_here.index ] );
	map.removeOverlay( marker_here );
	marker_here = null;
  }

  var el = $('quickinfo');
  if ( el != null ) {
	el.parentNode.removeChild( el );
  }
  
  var el = $('map_label');
  if ( el != null ) {
	el.parentNode.removeChild( el );
  }
}

function show_mini_map(map_id,marker_id,place_id,lat,lon,name,static_url) {

  if (GBrowserIsCompatible()) {
	map = new GMap2($(map_id));
	var nav = new GSmallMapControl();
	map.addControl(nav);
	map.setCenter(new GLatLng(lat,lon), 15);

	var icon = new GIcon(glIcon);
	icon.image = "grafiken/marker_"+marker_id+".png";

	var point = new GLatLng( lat, lon );
	  
	markers[0] = new GMarker(point, icon);
	markers[0].point = point;
	
	GEvent.addListener(markers[0], "click", function() { document.location=""+static_url; });
	GEvent.addListener(markers[0], "mouseover", function() { show_mini_info(0,name,place_id,static_url); });  
	
	map.addOverlay(markers[0]);	
  }
  
}
