/**
 * CLASS ImmoMap
 * 
 * @param lat
 * @param lng
 * @param zoom
 * @return
 */
function ImmoMap(lat, lng, zoom) {
	
    /*
     * class fields
     */	
    this.map = new GMap2(document.getElementById("map"));
    this.map.setCenter(new GLatLng(lat, lng), zoom);
    this.map.addControl(new GLargeMapControl());
    
    /*
     * listener for infoWindowClosure
     */
    GEvent.addListener(this.map, "infowindowclose", function() {
	    var fadeIn = new YAHOO.util.Anim("labelControl", { opacity: { to: 1 } }, 0.5);
	    fadeIn.animate();
	    
	    fadeIn = new YAHOO.util.Anim("areaDescriptions", { opacity: { to: 1 } }, 0.5);
	    fadeIn.animate();
	    
	    document.getElementById("labelControl").style.display = "inline";
	    document.getElementById("areaDescriptions").style.display = "inline";
    });
    
    /*
     * reference to global map
     */
    map = this.map;

    /**
     * Add a spot to the map
     */
    this.addSpot = function(lat, lng, caption, id, image) {
        spotIcon = new GIcon();
	    spotIcon.image = contextPath + 'static/images/regio/cat_icons/' + image + '.gif';
	    spotIcon.iconSize = new GSize(32, 32);
	    spotIcon.iconAnchor = new GPoint(9, 34);
	    spotIcon.infoWindowAnchor = new GPoint(9, 2);
	
	    spotOptions = { icon:spotIcon, title:caption };
	    
	    point = new GLatLng(lat, lng);
	    
	    var spot = new GMarker(point, spotOptions);
	    GEvent.addListener(spot, "click", function() {
	    	showHotspot(id);
	    });
	    
	    this.map.addOverlay(spot);
	    
	    return spot;
    }
    
    /**
     * Add an immo object to the map
     */
    this.addImmoObject = function(lat, lng, caption, id) {
    	markerIcon = new GIcon();
    	markerIcon.image = contextPath + 'static/images/regio/objekt.gif';
    	markerIcon.iconSize = new GSize(32, 32);
    	markerIcon.iconAnchor = new GPoint(9, 34);
    	markerIcon.infoWindowAnchor = new GPoint(9, 2);
	
	    markerOptions = { icon:markerIcon, title:caption };
    	
    	point = new GLatLng(lat, lng);
    	
    	var marker = new GMarker(point, markerOptions);
	    GEvent.addListener(marker, "click", function() {
	    	showImmoObject(id);
	    });
	    this.map.addOverlay(marker);
	    
	    return marker;
    }
    
    /**
     * Add makler to the map
     */
    this.addMakler = function(lat, lng, name, street, zip, city, id) {
    	markerIcon = new GIcon();
    	markerIcon.image = contextPath + 'static/images/regio/makler.gif';
    	markerIcon.iconSize = new GSize(27, 27);
    	markerIcon.iconAnchor = new GPoint(9, 34);
    	markerIcon.infoWindowAnchor = new GPoint(9, 2);    	
	
	    markerOptions = { icon:markerIcon, title:name };
    	
    	point = new GLatLng(lat, lng);
    	
    	var marker = new GMarker(point, markerOptions);
	    GEvent.addListener(marker, "click", function() {
	    	marker.openInfoWindowHtml(getMaklerContent(name, street, zip, city, id), {maxWidth: 350});
	    });
	    this.map.addOverlay(marker);
    }
}
