function showMap(latitude, longitude, zoom)
{
	if (GBrowserIsCompatible())
	{
		var map = new GMap2(document.getElementById("townmap"));
		map.setCenter( new GLatLng(latitude, longitude), zoom );
		//map.setCenter( new GLatLng(longitude, latitude), zoom );
		//map.addControl( new GSmallMapControl() );
		map.addControl( new GLargeMapControl() );
		map.addControl( new GMapTypeControl() );
		map.addControl( new GScaleControl() );
		//map.addControl( new GOverviewMapControl() );

		return map;
	}
}

function show_shMarker(map, latitude, longitude, hausKZ)
{
	if(map && latitude && longitude)
	{
		map.addOverlay( create_shMarker(latitude, longitude, hausKZ) );
	}
}

function create_shPinIcon()
{
	var baseIcon 		= new GIcon();
	baseIcon.image 	= "http://www.silvesterhaus.de/images/icons/sh_google_pin_icon.png";
	baseIcon.shadow	= "http://www.silvesterhaus.de/images/icons/sh_google_pin_icon_shadow.png";
	baseIcon.iconSize = new GSize(77, 66);
	baseIcon.shadowSize = new GSize(77, 66);
	baseIcon.iconAnchor = new GPoint(20, 62);
	baseIcon.infoWindowAnchor = new GPoint(20, 18);
	baseIcon.infoShadowAnchor = new GPoint(45, 33);

	return baseIcon;
}

function create_shMarker(latitude, longitude, hausKZ)
{
      if(hausKZ)
      {
	var shMarker = new GMarker( new GLatLng(latitude, longitude), {icon:create_shPinIcon(), clickable:true, title:hausKZ} );
	
	/*GEvent.addListener(shMarker, "click", function() {
		GDownloadUrl("/angebot_google_map_preview.php?objektKZ=" + hausKZ + "&angebotID=" + angebotID, function(data, response) {
			shMarker.openInfoWindowHtml(data);
		});
	});*/

        GEvent.addListener(shMarker, "click", function() {
		GDownloadUrl("/angebot_google_map_preview.php?objektKZ=" + hausKZ, function(data, response) {
			var xml = GXml.parse(data);
			var angebote = xml.getElementsByTagName("angebot");
			var angeboteTabs = new Array();
			for( var i = 0; i < angebote.length; i++ )
			{
				var node = angebote[i].getElementsByTagName("div")[0];
				if(navigator.userAgent.toLowerCase().indexOf('msie') + 1 )
				{	
					var contentNode = importNodeIE(node, true);				
				} else {
					var contentNode = node;
				}
				
				if(contentNode.nodeType == 1)
				{
					
					angeboteTabs[i] = new GInfoWindowTab(angebote[i].getAttribute("angebotKZ"), contentNode);
				}
			}			

			shMarker.openInfoWindowTabs(angeboteTabs);
		});
	});
      } else {
        var shMarker = new GMarker( new GLatLng(latitude, longitude), {icon:create_shPinIcon(), clickable:false} );
      }

	return shMarker;
}

function importNodeIE (oNode, bDeep) {
	var nodeHTML = oNode.xml||oNode.outerHTML;
	if(!nodeHTML) throw "importNodeIE: nodeHTML is null or undefined";
	if(typeof bDeep == "undefined") throw "importNodeIE: not enough arguments";
	var tmpNode = document.createElement("div");
	tmpNode.innerHTML = nodeHTML;
	return tmpNode.firstChild.cloneNode(bDeep);
}
