function bashotelmap() {
	// public methods: buildmap, reset, basSetCenter
	// public vars: myloc, domap, res_array
	this.myloc = new Array();
	this.domap = 0;
	this.res_array;
	this.uniqueArray = new Array();
	this.uninames = new Array();

	this.centerloc = new Array();
	this.centerloc["latitude"]  = 0;
	this.centerloc["longitude"] = 0;
	this.RadiusEnabled =0;

    this.was;
    this.wie;
	this.cap;

	var radiusMarker;
	var	radius = 0;

	var displayedItem = 150;
	var centerMarker;
	var minLat = 0 * 1; var minLong = 0 * 1;
	var maxLat = 0 * 1; var maxLong = 0 * 1;
	var map;
	var	bounds = new GLatLngBounds();

    this.reduce= function (was,wie,cap) {
      this.was = was;
      this.wie = wie;
      this.cap = cap;
      if ( was == "Distance" && wie == "max" ) {
		  radius=cap;
          if ( radiusMarker ) { radiusMarker.hide(); }
          this.ShowRadius(radius ,radiusMarker);
      }
    }

	this.DisableRadius = function () {
		basgeo.ShowRadius(0,0);
		basgeo.RadiusEnabled = 0;
	}

	this.EnableRadius = function () {
		basgeo.RadiusEnabled = 1;
		basgeo.ShowRadius(radius,0);
	}

    this.setRadius = function (value) {
      radius=value;
    }

    this.calcit = function ()
    {
      var sz = map.getSize();
      var bnds = map.getBounds();
      var pxDiag = Math.sqrt((sz.width*sz.width) + (sz.height*sz.height));
      var mDiagKm = bnds.getNorthEast().distanceFrom(bnds.getSouthWest()) / 1000.0;
      var pxPerKm = pxDiag/mDiagKm;
      return(pxPerKm);
    }

      this.ShowRadius = function(radius, marker) {

		if ( ! basgeo.centerloc ) {
			basgeo.centerloc["latitude"] = basgeo.myloc["longitude"];
			basgeo.centerloc["longitude"] = basgeo.myloc["longitude"];
		}
        var lat  = basgeo.centerloc["latitude"];
        var lon = basgeo.centerloc["longitude"];
        var baseIcon = new GIcon();
        var km = radius * 2;
        var pixel= this.calcit();
        if ( this.RadiusEnabled ) {
			baseIcon.shadow = "/img/hotels/radi.png";
			baseIcon.shadowSize =new GSize(km*pixel,km*pixel);
			baseIcon.iconAnchor = new GPoint(km*pixel/2,km*pixel/2)
			baseIcon.infoWindowAnchor = new GPoint(1000,1000);
			if (radiusMarker) radiusMarker.hide();
			radiusMarker =   new GMarker(new GPoint(lon, lat),  baseIcon);
			map.addOverlay(radiusMarker);
		}
    }


	this.buildmap = function (){
		if ( ! GBrowserIsCompatible() ) {
			return ("Browser ist inkompatibel!");
		}
		if ( this.domap > 0 ) {
			this.initmapobject();
			this.unify();
   			this.uniqueArray.each(this.buildmarkers);
   		    bounds2zoom();
			bounds2center();
            this.ShowRadius(radius,radiusMarker);
            GEvent.addListener(map, 'zoomend', function() {
            if ( basgeo.RadiusEnabled )  basgeo.ShowRadius(radius ,radiusMarker);
            } );
        }
	}

	this.initmapobject = function() {
		map = new GMap2(document.getElementById("map"));
		this.centerloc["latitude"]  = this.myloc["latitude"];
		this.centerloc["longitude"] = this.myloc["longitude"];
	    map.enableDoubleClickZoom();
	    map.enableContinuousZoom();
	    map.enableScrollWheelZoom();
		map.addControl(new GSmallMapControl());
	    map.addControl(new GOverviewMapControl(new GSize(150,90)));
		var intervall = window.setInterval(function(){
				var omap = document.getElementById("map_overview");
                if ( omap ) {
                  var hider = omap.lastChild;
                   if ( hider.__e_.click[0] ) {
                     hider.__e_.click[0].remove();
                   }
                hider.innerHTML = "";
                omap.firstChild.style.top = "0px";
                omap.firstChild.style.left = "0px";
                omap.firstChild.style.border ="0px";
                omap.firstChild.firstChild.style.top = "0px";
                omap.firstChild.firstChild.style.left = "0px";
                omap.firstChild.firstChild.style.border ="0px";
                omap.firstChild.firstChild.style.width = "150px";
                omap.firstChild.firstChild.style.height = "90px";
                window.clearInterval(intervall);
              }
        },250);

		map.addControl(new GScaleControl(200));

	    if ( centerMarker != null ) {
	    	map.removeOverlay(centerMarker);
	    }
        this.defaultCenter();

    } // end of initmapobject

	this.defaultCenter = function() {
      this.ll2center(this.myloc["latitude"], this.myloc["longitude"]);
	  reduce_it('Distance','max',radius);
	}

	this.reset = function(){
		if ( map ) {
			map.clearOverlays();
		}

		this.res_array = new Array();
		this.uniqueArray = new Array();
		bounds = new GLatLngBounds();
        //radius = 50; // initial
		this.domap = 0;
		displayedItem = 150;
		basgeo.centerloc["latitude"]  = this.myloc["latitude"];
		basgeo.centerloc["longitude"] = this.myloc["longitude"];
	}

	function bounds2zoom() {
		map.setZoom(map.getBoundsZoomLevel(bounds));
	}

	function bounds2center() {
		map.setCenter(bounds.getCenter());
	}

	this.unify = function(){
        var u2 = new Array();
		for (i in this.res_array) {
	    	if (typeof(this.res_array[i])!="object") {continue;};
	    	u2.push(this.uniqueArray[i]);
		}
        this.uniqueArray=this.res_array
	}

	this.ll2center = function(lat, lng) {
		var currentPoint = new GLatLng(lat, lng);
		if (centerMarker != null) {
			map.removeOverlay(centerMarker);
		}
		basgeo.centerloc["latitude"]  = lat;
		basgeo.centerloc["longitude"] = lng;
        bounds = new GLatLngBounds(currentPoint );
        map.setCenter(currentPoint,12);
        bounds.extend(currentPoint);
        map.setCenter(bounds.getCenter()-1);
	var count = 0;
        basgeo.res_array.each(function(item) {
          if ( item["Marker"] )    {
              if ( ! item["Marker"].isHidden() ) {
                  var point = new GLatLng(item["Latitude"], item["Longitude"]);
				  if ( item["Distance"] > 0)
                  if ( point && item["Distance"] < 51  ) {
					//console.debug("distanz="+item["Distanz"]);
					bounds.extend(point);
					count += 1;
                  }
              }
          }
        }); // end of each
	var zoom = map.getBoundsZoomLevel(bounds);
	if ( count  < 3 ) count = 2;
	else count = 1;
	zoom = zoom - count;
        map.setZoom(zoom);
	}; ll2center = this.ll2center;

	this.address2center = function() {
	    	if (! this.geocoder) { this.geocoder = new GClientGeocoder(); }
	    	var address = document.getElementsByName("customPoint")[0].value;
			address = address + ", " + basgeo.myloc["city"];
			this.geocoder.getLocations(address, this.handleResponse);
			return false;
	}


	this.handleResponse = function(response){
		if (!response || response.Status.code != 200) {
    		alert("Leider konnten wir die Addresse nicht lokalisieren");
        }
        else    {
              place = response.Placemark[0];
              ll2center(place.Point.coordinates[1], place.Point.coordinates[0]);
              point2 = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
              marker = new GMarker(point2);
              map.addOverlay(marker);
              marker.hide();
              marker.openInfoWindowHtml(place.address);
			  reduce_it('Distance','max',radius);
			  //basgeo.uniqueArray.each(this.buildmarkers);

          }
      }

	this.buildmarkers = function(items){
        imgserver = "http://www.billigflieger.de/";
        var item = items;
        if ( item.IsDuplicate || ! item["Latitude"]  || ! item["Longitude"] ){ return ;	}
        var point = new GLatLng(item["Latitude"], item["Longitude"]);
  		bounds.extend(point);
  		var Icon = new GIcon();
     	Icon.image = item["Icon"];
     	Icon.iconSize = new GSize(38, 30);
     	Icon.iconAnchor = new GPoint(0, 30);
     	Icon.imageMap=[9,0,6,1,4,2,2,4,0,8,0,12,1,14,2,16,5,
        	   	19,7,23,8,26,9,30,9,34,11,34,11,30,12,26,13,24,14,21,
      			16,18,18,16,20,12,20,8,18,4,16,2,15,1,13,0];
  		items["Marker"] = new GMarker(point, Icon);
        map.addOverlay(items["Marker"]);
		GEvent.addListener(item["Marker"], "mouseover", function() {
			tmp = imgserver + 'img/hotels/'+ item["Stars"] + '/' + item["CompareEinzelpreis"] + '.gif';

			//item["Marker"].origZIndex = item["Marker"].style.zIndex;
			//item["Marker"].style.zIndex=10000;

			item["Marker"].setImage(tmp);

			document.getElementById("hotelImage").lastChild.src= item["Thumbnail"];
			document.getElementById("hotelImage").lastChild.width=150;
			document.getElementById("hotelImage").lastChild.height=130;
			document.getElementById("hotelName").innerHTML=		item["Hotel"];
			tmp= '<img src="/img/diverse/hotel/Sterne'  + '_0' + item["Stars"] + '.gif" width="75" height="14"><br> \n';
			document.getElementById("hotelStars").innerHTML=tmp;
			document.getElementById("hotelAddress").innerHTML=	item["Address"];
			document.getElementById("hotelPriceVia").innerHTML=	item["PricePerPerson"] + ' &euro; <span class="small">via '
						+ item["Provider"] + "</span>" ;
		})

		GEvent.addListener(item["Marker"], "mouseout", function() {
			item["Marker"].hide();
			item["Marker"].setImage(item["Icon"]);
			item["Marker"].show();
			//item["Marker"].style.zIndex=item["Marker"].origZIndex;

		} )

		GEvent.addListener(item["Marker"], "click", function() {
		    window.open(item["Link"]);
		})
  		map.addOverlay(item["Marker"]);
   		if (item["id"] < displayedItem)  {
  			document.getElementById("hotelImage").lastChild.src= item["Thumbnail"];
            document.getElementById("hotelImage").lastChild.width=150;
            document.getElementById("hotelImage").lastChild.height=130;
            imgserver = "http://www.billigflieger.de";
            tmp= '<img src="/img/diverse/hotel/Sterne'  + '_0' + item["Stars"] + '.gif" width="75" height="14"><br> \n';
		    document.getElementById("hotelName").innerHTML=		item["Hotel"];
            document.getElementById("hotelStars").innerHTML=tmp;
		    document.getElementById("hotelAddress").innerHTML=	item["Address"];
		    document.getElementById("hotelPriceVia").innerHTML=	item["PricePerPerson"] + ' &euro; <span class="small">via '
						+ item["Provider"] + "</span>" ;
			displayedItem = item["id"];
  		}
    } // buildmarkers
}// end of object
var basgeo = new bashotelmap();

