function WikiLayerCallback(json, wikiLayer) {
  for (var i = 0; i < json.geonames.length; i++) {
    var geonames = json.geonames[i];
    if (!wikiLayer.ids[geonames.title]) {
      var marker = this.createMarker(geonames, wikiLayer.markerIcon);
      wikiLayer.mgr.addMarker(marker, 0);
      wikiLayer.ids[geonames.title] = "exists";
    }
  }
}

WikiLayerCallback.prototype.formImgUrl = function(photoId) {
 url = "http://maps.google.com/mapfiles/kml/pal5/";	
  return  url ;
}
 
WikiLayerCallback.prototype.formPageUrl = function(photoId) {
  return 'http://www.Wiki.com/photo/' + photoId;
}

/* WikiLayerCallback.prototype.createMarker = function(photo, baseIcon) {
  var markerIcon = new GIcon(baseIcon);
  markerIcon.image = this.formImgUrl(photo.thumbnailImg);
  var marker = new GMarker(new GLatLng(photo.lat, photo.lng), {icon: markerIcon, title: photo.title});
  if (photo.title.length > 33) {
    photo.title = photo.title.substring(0, 33) + "&#8230;";
  } */
  
 WikiLayerCallback.prototype.createMarker = function(photo, baseIcon) {
  var markerIcon = new GIcon();
  markerIcon.image = this.formImgUrl(photo.thumbnailImg) + "icon22.png";
  markerIcon.shadow =this.formImgUrl(photo.thumbnailImg) + "icon22s.png";
  markerIcon.iconSize=new GSize(32,32);
  markerIcon.shadowSize=new GSize(56,32);
  markerIcon.iconAnchor=new GPoint(16,32);
  markerIcon.infoWindowAnchor=new GPoint(16,0);
  var marker = new GMarker(new GLatLng(photo.lat, photo.lng), {icon: markerIcon, title: photo.title});
  if (photo.title.length > 33) {
    photo.title = photo.title.substring(0, 33) + "&#8230;";
  } 
  
 /* var html = "<div id='infowin' style='height:320px; width:240px;'>" +
            "<p><a href='http://de.wikipedia.org/' target='_blank'>" + 
             "<img src='http://www.Wiki.com/img/logo-small.gif' border='0' width='119px' height='25px' alt='Wiki logo' /><\/a></p>" +
             "<a id='photo_infowin' target='_blank' href='" + photo.thumbnailIMG + "'>" +                
             "<img border='0' width='" + photo.width + "' height='" + photo.height + "' src='" + photo.photo_file_url + "'/><\/a>" +
             "<div style='overflow: hidden; width: 240px;'>" +
             "<p><a target='_blank' class='photo_title' href='" + photo.ThumbnailIMG +
             "'><strong>" + photo.title + "<\/strong><\/a></p>" +
             "<p><a target='_blank' href='" + photo.wikipediaUrl + "'>" +
             photo.summary + "<\/a></p><\/div>" +
             "<\/div>"; */
			 
 var html = "<div id='infowin' style='height:160px; width:120px;'>" +
            "<p><a href='http://de.wikipedia.org/' target='_blank'>" + 
             "<img src='Wikipedia.png' border='0' width='80px' height='15px' alt='Wiki logo' /><\/a></p>" +
             "<div style='overflow: hidden; width: 240px;'>" +
             "<p><strong>" + photo.title + "<\/strong></p>" +
             "<p><a target='_blank' href=http://" + photo.wikipediaUrl + ">" +
             photo.summary + "<\/a></p><\/div>" +
             "<\/div>";			 

  marker.html = html;

  GEvent.addListener(marker, "click", function() {
    map.openInfoWindow(marker.getLatLng(), marker.html, {noCloseOnClick: true});
  });
 
  return marker;
}


function WikiLayer(map, opt_opts) {
  var me = this;
  me.ids = {};
  me.mgr = new MarkerManager(map, {maxZoom: 19});

  var icon = new GIcon();
 /* icon.image = "http://www.panoramio.com/img/panoramio-marker.png"; 
  icon.shadow = "";  
  icon.iconSize = new GSize(24, 24); 
  icon.shadowSize = new GSize(22, 22); 
  icon.iconAnchor = new GPoint(9, 9);  
  icon.infoWindowAnchor = new GPoint(9, 0); 
*/
  me.markerIcon = icon;
  me.enabled = false;

  GEvent.addListener(map, "moveend", function() {
    if (me.enabled) {
      var bounds = map.getBounds();
      var southWest = bounds.getSouthWest();
      var northEast = bounds.getNorthEast();
      me.load(me, {north: northEast.lat(), south: southWest.lat(), east: northEast.lng(), west: southWest.lng()});
    }
  });
}

WikiLayer.prototype.enable = function() {
  this.enabled = true;
  GEvent.trigger(map, "moveend");
}

WikiLayer.prototype.disable = function() {
  this.enabled = false;
  this.mgr.clearMarkers();
  this.ids = {};
}

WikiLayer.prototype.getEnabled = function() {
  return this.enabled;
}

WikiLayer.prototype.load = function(wikiLayer, userOptions) {
  var options = {
    north: "90",
    south: "45",
    east: "0",
    west: "10",
    lang: "de",
    maxRows: "30"
  };
 
  for (optionName in userOptions) {
    if (userOptions.hasOwnProperty(optionName)) {
      options[optionName] = userOptions[optionName];
    }
  }
 
  var url = "http://ws.geonames.org/wikipediaBoundingBoxJSON?";
  var uniqueID = "";
 
  for (optionName in options) {
    if (options.hasOwnProperty(optionName)) {
      var optionVal = "" + options[optionName] + "";
      url += optionName + "=" + optionVal + "&";
      uniqueID += optionVal.replace(/[^\w]+/g,"");
    }
  }
  var callbackName = "WikiLayerCallback.loader" + uniqueID; //ask dion
  eval(callbackName + " = function(json) { var pa = new WikiLayerCallback(json, wikiLayer);}");
 
  var script = document.createElement('script');
  script.setAttribute('src', url + 'callback=' + callbackName);
  script.setAttribute('id', 'jsonScript');
  script.setAttribute('type', 'text/javascript');
  document.documentElement.firstChild.appendChild(script);
}



