<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="flickr photo browser" 
             description="Displays geotagged images from flickr.com"
             author="Rafael Zwiegincew"
             author_email="zwieciu@gmail.com"
             height="100"
	     thumbnail="http://www.planyo.com/photo-browser/thumb-small.png"
	     screenshot="http://www.planyo.com/photo-browser/thumb.png">
<Require feature="sharedmap"/>
</ModulePrefs>
<Content type="html"><![CDATA[
all images are copyrighted and come from <a href='http://www.flickr.com/'>flickr</a>
<script>

var map = new GMap2();
GEvent.addListener(map, "moveend", function() {

    onMoveEnd(map);

});
onMoveEnd(map);

function onMoveEnd(map) {
var bounds=map.getBoundsAsync(function(bounds) {
  var left=bounds.getSouthWest().lng();
  var right=bounds.getNorthEast().lng();
  var top=bounds.getNorthEast().lat();
  var bottom=bounds.getSouthWest().lat();
  var per_page=100;

  var url="http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=82e3352f48b47f1bffddca00055f8e05&min_taken_date=2001-01-01&bbox="+left+","+bottom+","+right+","+top+"&extras=owner_name,geo&sort=interestingness-desc&per_page="+per_page;
  _IG_FetchXmlContent(url, function(response) {

    var photos = response.getElementsByTagName("photo");

    for (var i = 0; i < photos.length; i++) {
      var photo = photos.item(i);
      var lat  = photo.getAttribute("latitude");
      var lng  = photo.getAttribute("longitude");
      var id = photo.getAttribute("id");
      var secret = photo.getAttribute("secret");
      var server_id = photo.getAttribute("server");
      var farm = photo.getAttribute("farm");
      var author_name = photo.getAttribute("ownername");
      var author_url = "http://www.flickr.com/people/"+photo.getAttribute("owner");
      var title = photo.getAttribute("title");
      var point = new GLatLng(lat, lng);

      var image = "http://farm"+farm+".static.flickr.com/"+server_id+"/"+id+"_"+secret+"_t.jpg";
      var image_url = "http://www.flickr.com/photos/" + photo.getAttribute("owner")+"/"+id;
      var marker = createMarker(point, image, image_url,author_name, author_url, title)
      map.addOverlay(marker);
    }

  });

});
}

// Creates a marker at the given point with the given name
function createMarker(pnt, image, image_url, author_name, author_url, title) {
  var new_marker = new GMarker(pnt);
  GEvent.addListener(new_marker, "click", function() {
    var html_code = "<a href='"+image_url+"'><img src='" + image + "' /></a><br/><small>photo by <a href='" +author_url + "'>" + author_name + "</a></small>";
    new_marker.openInfoWindowHtml(html_code);
  });
  return new_marker;
}

</script>
]]></Content>
</Module>
