/**
 * Path to the marker image
 */
var _marker_image2 = 'http://projects.wdf.cz/google-mapplets/united-islands/img/ico.png';

/**
 * Path to the source XML file
 */
// DEV addr:
//var _source_xml = 'http://google.mapplet.dev5/united-islands/source.xml';

// STAGE addr:
var _source_xml2 = '/assets/xml/gmap/source2.xml';

/**
 * Powered by Inmite (http://www.inmite.eu)
 */
var map2;

/**
 * Do post-init routines
 */
var marker_icon2    = null;
var marker_options2 = null;
function after_init2() {
	// Setup marker icon
	marker_icon2 = new GIcon();
	marker_icon2.image = _marker_image2;
	marker_icon2.iconSize = new GSize(32, 31);
	marker_icon2.iconAnchor = new GPoint(13,13);
	marker_icon2.infoWindowAnchor = new GPoint(13, 0);
	
	// Setup marker options -- basicly, add there the icon
	marker_options2 = { icon: marker_icon2 };
}

/**
 * Put marker on the map // global function so we have variables in correct scope
 */
function putMarker2(lng, lat, title, desc) {
    var html   = '<h1 style="font-size: 24px; color: #D93A1F; padding: 0; text-align: left; font-family: Arial, Tahoma, sans-serif; background: none; margin: 17px 0 0 0;">' + title + '</h1>' + desc;
    var point  = new GLatLng(lat, lng);
	marker_options2['title'] = title;
    var marker = new GMarker(point, marker_options2);
    GEvent.addListener(marker, "click", function() {
        map2.openInfoWindowHtml(point, html);
    });
    map2.addOverlay(marker);      
}

/**
 * Initialize map and populate it with data
 */
function initialize2() {
    if (GBrowserIsCompatible()) {              
        // Prepare map
        map2 = new GMap2(document.getElementById("map2"));
        map2.enableScrollWheelZoom();
        map2.enableContinuousZoom();

        // Set up controls
        map2.addControl(new GMapTypeControl());
        map2.addControl(new GLargeMapControl());
        map2.addControl(new GOverviewMapControl());

        // Restrict zoom levels
        var mt2 = map2.getMapTypes();
        for (var i=0; i < mt2.length; i++) {
            mt2[i].getMinimumResolution = function() {return 1;};
            mt2[i].getMaximumResolution = function() {return 16;};
        }

        // Set the scroll & zoom
    	map2.setCenter(new GLatLng(50.083252,14.426945), 13); // <- this is prague
        
        // after init
        after_init2();

        // Now, get the source XML data and parse them. Therefore,
        // we *will* show it on out map
        var xml2 = LoadXML2(_source_xml2, populate2);
    }
}

/**
 * Populate the map with specified xml parser
 * 
 */
function populate2(xml) {
    // And parse all of the nodes
    var points = xml.getElementsByTagName("point");
    for(var i = 0; i < points.length; i++) {
        var title = points[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;
        var desc  = points[i].getElementsByTagName("desc")[0].childNodes[0].nodeValue;
        var lng   = points.item(i).getAttribute("lng");
        var lat   = points.item(i).getAttribute("lat");
        
    	// And append the node into map
        putMarker2(lng, lat, title, desc);
	}
}


