// do tohoto objektu se ukládají místa k zobrazení na mapě
function Place(lat, lng, name, img, desc, url) {
    var imgPath = '';
    this.lat = lat;
    this.lng = lng;
    this.name = name;
    this.img = imgPath + img;
    this.desc = desc;
    this.url = url;
    this.windowHtml = '';
    this.marker = '';
}

// seznam míst
var places = new Array(
    new Place(48.798101, 15.988712, 'The Happy Star hotel', '/img/gmap/mapa-hotel.gif', 'The Happy Star hotel is located here close to the border with Austria.', ''),
    new Place(48.857939, 16.049824, 'Znojmo', '/img/gmap/mapa-znojmo.gif', 'Znojmo with 36&nbsp;000 inhabitants and one of the oldest towns in the Czech Republic is 8&nbsp;km from the hotel.', '/hotel-neighborhood/znojmo/'),
    new Place(48.850032, 15.927773, 'The Podyjí National Park', '/img/gmap/mapa-podyji.gif', 'The Podyji National Park with lots of canyons, rocks and the meandering Dyje river which begins right at the hotel.', '/hotel-neighborhood/podyji/'),
    new Place(48.795896, 16.007423, 'Šatov', '/img/gmap/mapa-vino.gif', 'Šatov with its wine cellars is only 2&nbsp;kilometers from the hotel. We can organize for you wine tasting there or in any other place.', '/hotel-neighborhood/wine-region/'),
    new Place(48.913306, 15.80409, 'Vranov dam', '/img/gmap/mapa-vranovska-prehrada.gif', 'Vranov dam built in 1930s and 35&nbsp;km from the hotel which serves mainly as a holiday spot', '/hotel-neighborhood/vranov/'),
    new Place(48.894688, 15.811343, 'Vranov nad Dyjí Castle', '/img/gmap/mapa-zamek-vranov.gif', 'Vranov castle was built in 1100.', '/hotel-neighborhood/vranov/'),
    new Place(48.784021, 15.974464, 'Mitterretzbach', '', 'Mitterretzbach is located in Austria right at the border crossing point Hnanice. Retz town is after Mitterretzbach.', ''),
    new Place(48.189895, 16.373749, 'Vienna', '/img/gmap/viden.gif', 'Driving to Vienna (90&nbsp;km)takes only 1 hour from the Happy Star hotel. Vienna is charming around Christmas time, where Christmas markets take place.', ''),
    new Place(49.197859, 16.621971, 'Brno', '', 'Brno is 70&nbsp;kilometros (1hour drive) from the hotel.', ''),
    new Place(48.782607, 16.202989, 'Water mill in Slup', '/img/gmap/mlyn.gif', 'Historical landmark', ''),
    new Place(48.854776, 15.772419, 'Riegersburg', '/img/gmap/riegersburg.gif', 'Castle in baroque style in Austria.', ''),
    new Place(48.757377, 16.064844, 'Hatě', '/img/gmap/hate.gif', 'Hatě is the border crossing point with shopping mall, close to the Happy Star hotel', '')
);

var placesHtml = '<p><strong>Show on map:</strong> <a onclick="openMapWindow(0); return false;" href="#">Hotel Happy Star</a>, <a onclick="openMapWindow(1); return false;" href="#">Znojmo</a>, <a onclick="openMapWindow(2); return false;" href="#">Národní park Podyjí</a>, <a onclick="openMapWindow(3); return false;" href="#">Šatov</a>, <a onclick="openMapWindow(4); return false;" href="#">Vranovská přehrada</a>, <a onclick="openMapWindow(5); return false;" href="#">Zámek Vranov nad Dyjí</a>, <a onclick="openMapWindow(11); return false;" href="#">Hatě</a>, <a onclick="openMapWindow(6); return false;" href="#">Mitterretzbach</a>, <a onclick="openMapWindow(7); return false;" href="#">Vídeň</a>, <a onclick="openMapWindow(8); return false;" href="#">Brno</a>, <a onclick="openMapWindow(9); return false;" href="#">Vodní mlýn ve Slupi</a>, <a onclick="openMapWindow(10); return false;" href="#">Riegersburg</a></p>';

function createMarker(u) {
    var point = new GLatLng(places[u].lat, places[u].lng);
    var marker = new GMarker(point);
    var html = '<p><strong>' + places[u].name + '</strong></p>';
    if (places[u].img != '') {
        html += '<table style="border: none; font-size: 100%;"><tr><td style="vertical-align: top; height: 80px; width: 100px;"><img src="' + places[u].img + '" alt="" style="margin-right: 10px;" /></td><td style="vertical-align: top;">' + places[u].desc;
        if (places[u].url != '') html += '<br /><br /><a href="' + places[u].url + '">More information »</a>';
        html += '</td></tr></table>';
    }
    else {
        html += '<p>' + places[u].desc;
        if (places[u].url != '') html += '<br /><br /><a href="' + places[u].url + '">More information »</a>';
        html += '</p>';
    }
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html, { maxWidth: 300 });
    });
    places[u].windowHtml = html;
    places[u].marker = marker; // ukládáme pro vyvolávání v odkazech
    return marker;
}

function openMapWindow(u) {
    places[u].marker.openInfoWindowHtml(places[u].windowHtml, { maxWidth: 300 });
}

// spouští se při nahrání stránky
function load() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GScaleControl());
        map.setCenter(new GLatLng(48.848451, 15.939789), 11);

        for (var i = 0; i < places.length; i++) {
            map.addOverlay(createMarker(i));
        }
        
        document.getElementById("map-markers").innerHTML = placesHtml;
    }
}

addDOMLoadEvent(load);

