var cat = 'NiederlandeOrteAlt';
var catName = 'Urban Areas (2001)';
var google_ad_client = "pub-7251478393613561";
var google_ad_channel = "2764227782";
var google_ad_searchchannel = "9414679865";
var years = 9;

function StartPos (name, x,y, zoom) {
  this.name = name;
  this.x = x;
  this.y = y;
  this.zoom = zoom;
}

var starts = new Array (
  new StartPos('Netherlands', 5.4,52.2, 8),
  new StartPos('Drenthe', 6.65,52.9, 10),
  new StartPos('Flevoland', 5.55,52.5, 10),
  new StartPos('Friesland', 5.58,53.1, 10),
  new StartPos('Gelderland', 6.1,52.15, 10),
  new StartPos('Groningen', 6.65,53.2, 10),
  new StartPos('Limburg', 5.95,51.18, 10),
  new StartPos('Noord-Brabant', 5.2,51.55, 10),
  new StartPos('Noord-Holland', 4.83,52.65, 10),
  new StartPos('Overijssel', 6.5,52.45, 10),
  new StartPos('Utrecht', 5.2,52.1, 10),
  new StartPos('Zeeland', 3.8,51.5, 10),
  new StartPos('Zuid-Holland', 4.5,52, 10)
)

document.writeln('<script src="genbymap.js" type="text/javascript"></script>');

function setStartCenter() {
  map.setCenter(new GLatLng(52.2,5.4), 8);
}

function getSizeImgName (pop) {
  var img = 'http://www.bymap.org/';
  if (pop >= 5000000)
    img += 'G5000.gif';
  else if (pop >= 1000000)
    img += 'G1000.gif';
  else if (pop >= 500000)
    img += 'G500.gif';
  else if (pop >= 250000)
    img += 'G250.gif';
  else if (pop >= 100000)
    img += 'G100.gif';
  else if (pop >= 50000)
    img += 'G50.gif';
  else if (pop >= 20000)
    img += 'G20.gif';
  else if (pop >= 10000)
    img += 'G10.gif';
  else if (pop >= 5000)
    img += 'G5.gif';
  else if (pop >= 1000)
    img += 'G1.gif';
  else
    img += 'G0.gif';
  return img;
}

function getDensityImgName (density) {
  var img = 'http://www.bymap.org/';
  if (density == 0)
    img += 'D0.gif';
  else if (density >= 8000)
    img += 'D1.gif';
  else if (density >= 4000)
    img += 'D2.gif';
  else if (density >= 2000)
    img += 'D3.gif';
  else if (density >= 1000)
    img += 'D4.gif';
  else if (density >= 500)
    img += 'D5.gif';
  else if (density >= 250)
    img += 'D6.gif';
  else if (density >= 125)
    img += 'D7.gif';
  else 
    img += 'D8.gif';
  return img;
}

function getChangeImgName (incr) {
  var img = 'http://www.bymap.org/';
  if (incr == null)
    img += 'C0.gif';
  else if (incr > 0.75)
    img += 'C1.gif';
  else if (incr > 0.2)
    img += 'C2.gif';
  else if (incr > -0.15)
    img += 'C3.gif';
  else if (incr > -0.5)
    img += 'C4.gif';
  else
    img += 'C5.gif';
  return img;
}

function createCityMarker(point, name, admin, status, pop, date, oldpop, olddate, area, wiki) {
  wiki = decodeURI(wiki);
  var text = '<strong>' + name + '</strong> ' + status + ' ' + admin;
  text += '<br/><br/>Population: <img src="' + getSizeImgName(pop) + '" width="13px" height="13px" alt=""> ' + pop + ' inhabitants <span style="font-size: 2.3mm;">(' + date + ')</span>';
  var incr = null;
  if (oldpop > 0) {
    text += '<br/>Comparison: <img src="' + getSizeImgName(oldpop) + '" width="13px" height="13px" alt=""> ' + oldpop + ' inhabitants <span style="font-size: 2.3mm;">(' + olddate + ')</span>';
    incr = Math.round(10000.0*(Math.exp(Math.log(pop/oldpop)/years)-1.0)) / 100;
    if (incr >= 0)
      text += '<br/>Population Increase: <img src="' + getChangeImgName(incr) + '" width="13px" height="13px" alt=""> +' + incr + '% per year';
    else
      text += '<br/>Population Decrease: <img src="' + getChangeImgName(incr) + '" width="13px" height="13px" alt=""> ' + incr + '% per year';
  }
  var density = 0;
  if (area > 0) {
    density = Math.round(1000*pop/area)/10;
    text += '<br/>Density: <img src="' + getDensityImgName(density) + '" width="13px" height="13px" alt=""> ' + density + ' pers./sq.km = ' + Math.round(3861*pop/area)/10 + ' pers./sq.mile';
  }
  var searchtext = name;
  text += '<br/><br/>Infos: <a href="javascript:showwiki(\'' + wiki + '\')">Wikipedia</a><br/>';
  text += 'Google: <a href="javascript:showgoogle(\'' + searchtext + '\',\'hotels\')">Hotels</a> ';
  text += ' <a href="javascript:showgoogle(\'' + searchtext + '\',\'sights\')">Sights</a> ';
  text += ' <a href="javascript:showgoogle(\'' + searchtext + '\',\'maps\')">Maps</a> ';
  var img = 'http://www.bymap.org/';
  if (display == 'change')
    img = getChangeImgName (incr)
  else if (display == 'density')
    img = getDensityImgName (density);
  else
    img = getSizeImgName (pop);
  return new WMarker(point,name,admin,status,text,img,20,20);
}

function computeWikiCall (m) {
  return 'http://en.wikipedia.org/wiki/Special:Search?go=Article&search='+m.getAttribute("name");
}

function computeZoom (pop) {
  if (pop > 200000)
    return 10;
  else if (pop > 50000)
    return 11;
  else if (pop > 10000)
    return 12;
  else
    return 13;
}

