
//Create an icon for the clusters
var iconCluster = new GIcon();
iconCluster.image = "http://www.upps.at/main/googlemap/icons/cluster.png";
iconCluster.shadow = "http://www.upps.at/main/googlemap/icons/cluster_shadow.png";
iconCluster.iconSize = new GSize(22, 22);
iconCluster.shadowSize = new GSize(22, 20);
iconCluster.iconAnchor = new GPoint(13, 25);
iconCluster.infoWindowAnchor = new GPoint(13, 1);
iconCluster.infoShadowAnchor = new GPoint(26, 13);

var iconClusterb = new GIcon();
iconClusterb.image = "http://www.upps.at/main/googlemap/icons/clusterb.png";
iconClusterb.shadow = "http://www.upps.at/main/googlemap/icons/cluster_shadow.png";
iconClusterb.iconSize = new GSize(27, 27);
iconClusterb.shadowSize = new GSize(22, 20);
iconClusterb.iconAnchor = new GPoint(13, 25);
iconClusterb.infoWindowAnchor = new GPoint(13, 1);
iconClusterb.infoShadowAnchor = new GPoint(26, 13);

//create an icon for the pins
var iconSingle = new GIcon();
iconSingle.image = "http://www.upps.at/main/googlemap/icons/single.png";
iconSingle.shadow = "http://www.upps.at/main/googlemap/icons/single_shadow.png";
iconSingle.iconSize = new GSize(17, 17);
iconSingle.shadowSize = new GSize(15, 15);
iconSingle.iconAnchor = new GPoint(6, 20);
iconSingle.infoWindowAnchor = new GPoint(6, 1);
iconSingle.infoShadowAnchor = new GPoint(13, 13);



function changeBodyClass(from, to) {
document.body.className = document.body.className.replace(from, to);
return false;
}

		var pointnew1 = pointnew1;
	var pointnew2 = pointnew2;

function init() {
			var pointnew1 = pointnew1;
	var pointnew2 = pointnew2;
	
  
	map = new GMap2(document.getElementById("map"),
	{googleBarOptions:{ 
               showOnLoad:true, 
               linkTarget:G_GOOGLEBAR_LINK_TARGET_PARENT, 
               suppressInitialResultSelection:true,
               resultList:G_GOOGLEBAR_RESULT_LIST_SUPPRESS 
             } 
           } 
	
	);
	map.addControl(new GLargeMapControl3D ());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
	map.addMapType(G_PHYSICAL_MAP); 

	updateMarkers();

  changeBodyClass('loading', 'standby');
    
  
 	GEvent.addListener(map,'moveend',function() {
 		
 	if (map.getInfoWindow().isHidden()) {
		updateMarkers();
	}
		
	});



	
}


function updateMarkers() {

   var zoom = map.getZoom();
   
   if(zoom < 5){
   		map.clearOverlays();  
   		
   		//map.clearMap();
   	//	GEvent.clearListeners();
   		//GEvent.removeListener(marker);
   		
   		var request = GXmlHttp.create();
			request.open('GET', 'server.php?'+getVars, true);
			request.onreadystatechange = function() {
			if (request.readyState == 4) {
				var jscript = request.responseText;
			
				eval(jscript);
	   		
	   		
	   		//create country markers
	   		for (j in pointsl) {
	   			
	   			var point = new GLatLng(pointsl[j].lat,pointsl[j].lng);
					var name=pointsl[j].name;
					var lang=pointsl[j].lang;
					var landid=pointsl[j].id;
	   		  //var html =  landid;
	   		  var clustsize =name;
										
					var html = "map_search.php?land_id="+landid+"&lang="+lang+"";		
					var marker = createMarker(html,clustsize,point,'3');
					
	   			map.addOverlay(marker);
	   		}
	   		//return marker; //map.addOverlay(marker);
   		}
   	}
			request.send(null);
   		return;
   }
   
 //} else {
	//remove the existing points
	map.clearOverlays();
	//create the boundry for the data to provide
	//initial filtering
	var bounds = map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	var getVars = 'ne=' + northEast.toUrlValue()
	+ '&sw=' + southWest.toUrlValue()+ '&zoom=' + zoom



	//retrieve the points
	var request = GXmlHttp.create();
	request.open('GET', 'server_map.php?'+getVars, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			var jscript = request.responseText;
		
		
			eval(jscript);
			

			
			//create each point from the list
			for (i in points) {
				var point = new GLatLng(points[i].lat,points[i].lng);
				var name=points[i].name;
				var logo=points[i].logo;
				var clustsize=points[i].size;
				var id=points[i].id;
				var landid=points[i].landid;
				var landtmp=landid;
				var lang=points[i].lang;
				var openurl="<a rel=\"shadowbox;width=750;options={overlayColor:\'#2C2C2C\'}\" onclick=\"Shadowbox.open(this);return false;\" href=\"hotel_detail.php?z=15&hotel_id="+id+"&cook_land="+landid+"&lang="+lang+"\">"+name+"</a>";
				var img="<img src=http://www.upps.at/add/image/"+logo+" width=100 border=0>";
			
				var html = "<div style=\"font-family: Arial,Verdana,Georgia;font-size:12px;\">";
      	html += "<strong>" + openurl + "</strong>";
		  	html += "<BR><BR><table><tr><td><a rel=\"shadowbox;width=750;options={overlayColor:\'#2C2C2C\'}\" onclick=\"Shadowbox.open(this);return false;\" href=\"hotel_detail.php?z=15&hotel_id="+id+"&cook_land="+landid+"&lang="+lang+"\">"+img+"</a></td><td>";
				html += "&nbsp;<a rel=\"shadowbox;width=750;options={overlayColor:\'#2C2C2C\'}\" onclick=\"Shadowbox.open(this);return false;\" href=\"hotel_detail.php?z=15&hotel_id="+id+"&cook_land="+landid+"&lang="+lang+"\">&rarr; "+beschr+"</a></td></tr></table>";

				html += "</div>";

				var marker = createMarker(html,clustsize,point,points[i].type);
				map.addOverlay(marker);			
			}
			for (j in pointsl) {
	   			
	   			var point = new GLatLng(pointsl[j].lat,pointsl[j].lng);
					var name=pointsl[j].name;
					var lang=pointsl[j].lang;
					var landid=pointsl[j].id;
	   		  //var html =  landid;
	   		  var clustsize =name;
					
					if (landtmp != 	landid){		
						var html = "map_search.php?land_id="+landid+"&lang="+lang+"";
						var marker = createMarker(html,clustsize,point,'3');
					}

					
					
	   			map.addOverlay(marker);
	   	}
			
		}
	}
	request.send(null);
}
//}

 
 
 

//create the ToolTip overlay object
function ToolTip(marker,html,width) {
this.html_ = html;
this.width_ = (width ? width + 'px' : 'auto');
this.marker_ = marker;
}
ToolTip.prototype = new GOverlay();
ToolTip.prototype.initialize = function(map) {
var div = document.createElement("div");
div.style.display = 'none';
map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
this.map_ = map;
this.container_ = div;
}
ToolTip.prototype.remove = function() {
this.container_.parentNode.removeChild(this.container_);
}

ToolTip.prototype.copy = function() {
return new ToolTip(this.html_);
}
ToolTip.prototype.redraw = function(force) {
if (!force) return;
var pixelLocation = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
this.container_.innerHTML = this.html_;
this.container_.style.position = 'absolute';
this.container_.style.left = pixelLocation.x + "px";
this.container_.style.top = pixelLocation.y + "px";
this.container_.style.width = this.width_;
this.container_.style.font = 'bold 10px/10px verdana, arial, sans';
this.container_.style.border = '1px solid black';
this.container_.style.background = '#99FF66';
this.container_.style.padding = '4px';
//one line to desired width
this.container_.style.whiteSpace = 'nowrap';
if(this.width_ != 'auto') this.container_.style.overflow = 'hidden';
this.container_.style.display = 'block';
}
GMarker.prototype.ToolTipInstance = null;
GMarker.prototype.openToolTip = function(content) {
//don't show the tool tip if there is a custom info window
if(this.ToolTipInstance == null) {
this.ToolTipInstance = new ToolTip(this,content)
map.addOverlay(this.ToolTipInstance);
}
}
GMarker.prototype.closeToolTip = function() {
if(this.ToolTipInstance != null) {
map.removeOverlay(this.ToolTipInstance);
this.ToolTipInstance = null;
}
}
 
 
 
 
 
 
 
 
function createMarker(html,clustsize,point,type) {
	//create the marker with the appropriate icon
	var htm = html;
	var clustersize=clustsize;
	
	
	
	if(type=='2') {
			var marker = new GMarker(point,iconCluster);
			//GEvent.addListener(marker,'click',function() {map.zoomIn();});
			GEvent.addListener(marker,'click',function() {map.zoomIn();map.panTo(marker.getLatLng());
			map.closeInfoWindow(); 
			});

			GEvent.addListener(marker,'mouseover',function() {marker.openToolTip(clustersize+' Results ');});
			GEvent.addListener(marker,'mouseout',function() {marker.closeToolTip();});
		} 
		else if (type=='3'){
			var marker = new GMarker(point,iconClusterb);
			//GEvent.addListener(marker,'click',function() {map.zoomIn();});
			//GEvent.addListener(marker,'click',function() {map.zoomIn();map.panTo(marker.getLatLng());
			GEvent.addListener(marker, "click", function() {
				map.closeInfoWindow();
	     	window.location.href=html; 
	     });
	    GEvent.addListener(marker,'mouseover',function() {marker.openToolTip(clustersize);});
			GEvent.addListener(marker,'mouseout',function() {marker.closeToolTip();});
		}
		else {
			var marker = new GMarker(point,iconSingle);
			GEvent.addListener(marker,'click',function() {
			//	map.setCenter(point, 13);	 
				marker.openInfoWindowHtml(htm);		
			});	
		}
	







	
	return marker;
}


//window.onload = init;

function tes(pointnew1,pointnew2,na){
	
	
	var pointnew1 = pointnew1;
	
	var pointnew2 = pointnew2;
	
	
	//var pointnew2 = $_GET['pointnew2'];
	
	if(pointnew1){
		
		//map.setCenter(new GLatLng(pointnew1, pointnew2),13);
		var pointnewx = new GLatLng(pointnew1,pointnew2);
		var na = na;
		
		map.setCenter(pointnewx, 14); 
		map.openInfoWindowHtml(pointnewx, na, {
			//noCloseOnClick: true
 		pixelOffset:new GSize(0,-16)
 		}); 
	}
	
	
	
}






var geocoder = null;
var curlat=0, curlng=0;
var curZoom=0;


curlat=centerLatitude; curlng=centerLongitude; curZoom=8;



function showLocation(address) {
	if(address != ""){
	geocoder = new GClientGeocoder();
	if (geocoder) {
		geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
				alert("= No City!");
			} else {
				map.setCenter(point, 11);

				curZoom=map.getZoom();
				//var marker = new GMarker(point);
			//	map.addOverlay(marker);
				//marker.openInfoWindowHtml(address);
			}
		}
		);
	}
	}
}



function tesx(){
		init();
		tes();
		if (address_st != ""){
			showLocation(address_st);
		}
}

window.onload = tesx;

