  var map;
	var markers = [];
	var mc;


  var myPano;   
  var panoClient;
  var nextPanoId;
  
  
  var ne_x;
  var ne_y;

  var sw_x;
  var sw_y;
  

    function showPanoData(panoData) {
      if (panoData.code != 200) {
        GLog.write('showPanoData: Server rejected with code: ' + panoData.code);
        return;
      }
      nextPanoId = panoData.links[0].panoId;
      var displayString = [
        "Panorama ID: " + panoData.location.panoId,
        "LatLng: " + panoData.location.latlng,
        "Copyright: " + panoData.copyright,
        "Description: " + panoData.location.description,
        "Next Pano ID: " + panoData.links[0].panoId
      ].join("<br/>");
      map.openInfoWindowHtml(panoData.location.latlng, displayString);
      
      GLog.write('Viewer moved to' + panoData.location.latlng);
      myPano.setLocationAndPOV(panoData.location.latlng);
    }
    
    function next() {
      // Get the next panoId
      // Note that this is not sophisticated. At the end of the block, it will get stuck
      panoClient.getPanoramaById(nextPanoId, showPanoData);
    }
    
    function handleNoFlash(errorCode) {
      if (errorCode == 603) {
        //alert("Error: Flash doesn't appear to be supported by your browser");
        return;
      }
    } 
    

		function addAddressToMap(response) {
      if (!response || response.Status.code != 200) {
        //alert("Sorry, we were unable to geocode that address");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);
        xajax.$('marker_address').value = place.address;
        xajax.$('marker_country').value = place.AddressDetails.Country.CountryNameCode;
      }
    }

    function showLocation(address) {
      geocoder.getLocations(address, addAddressToMap);
    }

    function createMarker(latlng, number,myHtml,icon) {
      
      if (!markers[number])
      {
      	markers[number] = latlng;
	      var marker = new GMarker(latlng,{'icon':icons[icon]});
	      GEvent.addListener(marker,"click", function() {
	        map.openInfoWindowHtml(latlng, myHtml);
	      });
	      return marker;
	    } else {
	    	return false;
	    }
	}
	 
	
	var edit_marker;

	function getArgs() {
		var args = new Object();
		var query = location.search.substring(1);
		var pairs = query.split("&");
		for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
		}
		return args;
	} 


    

  function initialize() {
      if (GBrowserIsCompatible()) {



          var mapOptions = {
          	enableScrollWheelZoom : false,
          	hierarchicalmaptypecontrol:false,
          	googleBarOptions : {
				      style : "new",
				      adsOptions: {
				        client: "pub-7824563120297571",
				        channel: "iJustHadLunchMapsSearch",
				        adsafe: "high",
				        language: "en"
				      }
				    }


          }
        
				args = getArgs();
				
          

        map = new GMap2(document.getElementById("map_canvas"), mapOptions);
				map.setUIToDefault();
        map.enableGoogleBar();
        map.enableRotation();

				if (args['x'] && args['y'])
				{
					x = args['x'];
					y = args['y'];
					zoom=15;
		      map.setMapType(G_HYBRID_MAP);
				} else {
					y=47.398349;
					x=11.99707;
					zoom=3;
				}



        map.setCenter(new GLatLng(y,x), zoom);
        map.addControl(new GMapTypeControl());

				
				mc = new MarkerClusterer(map);
        GEvent.bind(map, 'singlerightclick', this, function(point,src,overlay){
          	var latlng = this.map.fromContainerPixelToLatLng(point);
          	map.setCenter(latlng,14)
		        xajax_open_new(latlng.x,latlng.y);
 
        });
        
				geocoder = new GClientGeocoder();

				GEvent.addListener(map, "moveend", function() {
			 		var bounds = map.getBounds();
			    var southWest = bounds.getSouthWest();
			    var northEast = bounds.getNorthEast();
			    
			    if (
			    		northEast.x < ne_x || northEast.y > ne_y
							||
			    		southWest.x > sw_x || southWest.y < sw_y
			    
			    )
			    {
			    
		        xajax_load_marker({
		        		sw : { x: southWest.x, y: southWest.y },
		        		ne: { x: northEast.x, y: northEast.y },
		        	
		        });

				    if (northEast.x < ne_x) ne_x = northEast.x;
				    if (northEast.y > ne_y) ne_y = northEast.y;
	
				    if (southWest.x > sw_x) sw_x = southWest.x;
				    if (southWest.y < sw_y) sw_y = southWest.y;
		
		      }
			    
			    		
					
				});
        

		 		var bounds = map.getBounds();
		    var southWest = bounds.getSouthWest();
		    var northEast = bounds.getNorthEast();
				
				ne_x = northEast.x;
				ne_y = northEast.y;

				sw_x = southWest.x;
				sw_y = southWest.y;

        xajax_load_marker({
        		sw : { x: southWest.x, y: southWest.y },
        		ne: { x: northEast.x, y: northEast.y },
        	
        });
      
      }
    }

