/*
 * util.js
 *
 * modified version; originally found at openstreemap.de
 */

var projmerc = new OpenLayers.Projection("EPSG:900913");
var proj4326 = new OpenLayers.Projection("EPSG:4326");

function makeIcon(url, x, y) {
    var size = new OpenLayers.Size(x, y);
    var offset = new OpenLayers.Pixel(-(size.w/2), -(size.h/2));
    return new OpenLayers.Icon(url, size, offset);
}

var icon = makeIcon('fileadmin/templates/images/house.png', 32, 32);

function addMarker(layer, lon, lat, popupContentHTML) {
    var lonlat = new OpenLayers.LonLat(lon, lat);
    lonlat.transform(proj4326, projmerc);
    var feature = new OpenLayers.Feature(layer, lonlat); 
    feature.closeBox = true;
    feature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {maxSize: new OpenLayers.Size(300, 180) } );
    feature.data.popupContentHTML = popupContentHTML;
    feature.data.overflow = "hidden";
            
    var marker = new OpenLayers.Marker(lonlat, icon.clone());
    marker.feature = feature;

    var markerClick = function(evt) {
        if (this.popup == null) {
            this.popup = this.createPopup(this.closeBox);
            map.addPopup(this.popup);
            this.popup.show();
        } else {
            this.popup.toggle();
        }
        OpenLayers.Event.stop(evt);
    };
    marker.events.register("mousedown", feature, markerClick);
    
    var markerHover = function(evt) {
    	this.icon.imageDiv.style.cursor = 'pointer';
			OpenLayers.Event.stop(evt);
    };
    marker.events.register("mouseover", marker, markerHover);

    layer.addMarker(marker);
}


