var map;
document.entryData = [];
var geocoder = new GClientGeocoder();
function initmap() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
//map.setCenter(new GLatLng(42.55308, -24.960937), 1);
map.setCenter(new GLatLng(2, 10), 1);
}
}
function centermap(centername) {
map.centername = centername;
}
function downloadCallback(data, responseCode) {
if (responseCode == 200) {
eval("var obj="+data);
handleData(obj);
} else {
//TODO: fail gracefully
}
}
function loadData(url) {
GDownloadUrl(url, downloadCallback);
}
function handleData(data) {
for (i in data['places']) {
var index = data['places'][i]['location']['point'][0]+":"+data['places'][i]['location']['point'][1];
if (document.entryData[index]) {
document.entryData[index].entries = document.entryData[index].entries.concat(data['places'][i]['entries']);
} else {
document.entryData[index] = {
name: data['places'][i]['location']['name'],
entries: data['places'][i]['entries'],
current: 0
};
}
if (map.centername == data['places'][i]['location']['name']) {
map.setCenter(new GLatLng(data['places'][i]['location']["point"][0],data['places'][i]['location']["point"][1]), 6);
}
createMarker(new GLatLng(data['places'][i]['location']["point"][0],data['places'][i]['location']["point"][1]),document.entryData[index]);
}
}
function nextEntry(name) {
var entry = document.entryData[name];
entry.current = entry.current + 1;
if (!entry.entries[entry.current]) {
entry.current = entry.current - 1;
}
updateEntry(entry);
}
function previousEntry(name) {
var entry = document.entryData[name];
entry.current = entry.current - 1;
if (entry.current == -1) {
entry.current = 0;
}
updateEntry(entry);
}
function getEntryLabel(entry) {
var index = 0;
var label = "";
while(entry.entries[index]) {
label = label + "» "+entry.entries[index].text+"
";
index = index + 1;
}
//var label = "< ";
//label = label + (entry.current+1)+" of "+(entry.entries.length);
//label = label + "> ";
//label = label + "
"+""+entry.name+"
"+entry.entries[entry.current].text;
//return label;
return label;
}
function updateEntry(entry) {
var label = getEntryLabel(entry);
document.getElementById(entry.name+"_marker").innerHTML = label;
entry.marker.redraw(true);
}
function createMarker(point,entry) {
var marker = new GMarker(point);
marker.entry = entry;
entry.marker = marker;
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml("