// Create a Map that will be placed in the "map" div.
var map = new YMap(document.getElementById('map'));

// Function to initialize the map and set the callback
function startMap()
{
    // Add the standard controls - map type, zoom, pan
    map.addTypeControl();
    map.addZoomLong();
    map.addPanControl();

    // Specifying the Map starting location and zoom level
    map.drawZoomAndCenter("45.73139, 21.20975", 2);
	// Create a new marker for an address
		var myMarker = new YMarker("45.73128, 21.21126");
		// Create some content to go inside the SmartWindow
		var myMarkerContent = "Laborator Dentar, str. Iris 7, tel.004-0765-239319";
		// When the marker is clicked, show the SmartWindow
		YEvent.Capture(myMarker, EventsList.MouseClick,
			function() {
				myMarker.openSmartWindow(myMarkerContent);
			});
		// Put the marker on the map
		map.addOverlay(myMarker);

    // Add an event for mouse clicks
    YEvent.Capture(map, EventsList.MouseClick, reportPosition);

    // the mouse click calls this function
    // Add a pushpin at the location, and log info in the debug logger (YLog)
    function reportPosition(_e, _c)
    {
        // It is optional to specify the location of the Logger.
        // Do so by sending a YCoordPoint to the initPos function.
        var mapCoordCenter = map.convertLatLonXY(map.getCenterLatLon());
        YLog.initPos(mapCoordCenter)("45.72835, 21.21052"); //call initPos to set the starting
          location

        // Printing to the Logger
        YLog.print("You Made a MouseClick!");
        YLog.print("Latitude:" + _c.Lat);
        YLog.print("Longitude:" + _c.Lon);

        YLog.print("Adding marker at....");
        YLog.print("\nLatitude:" + _c.Lat + "\nLongitude:" + _c.Lon);
        var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon );
        map.addMarker(currentGeoPoint);
    }
}

// call startMap when the window loads
window.onload = startMap;