var FlickrObj;
var flickrVars = new FlickrVars();
var Flickr = new FlickrC();

var flickrMarker = new Array();
function FlickrC() { }
FlickrC.prototype.update = function () {
      flickrAddress  = "/apis/getflickr.php";
      $('flickrLoading').style.visibility="visible";
      new Ajax.Request(flickrAddress+"?mode=tree&bbox="+flickrVars.southWest.lng() + "," + flickrVars.southWest.lat() +
      "," + flickrVars.northEast.lng() + "," + flickrVars.northEast.lat(), {
      method: 'get',
      onSuccess: function(transport) { FlickrObj = transport.responseText.evalJSON();
      if (FlickrObj.total>0){
        FlickrC.prototype.hide();
         flickrVars.markers = [];
        for (id in FlickrObj.photos) {
          FlickrC.prototype.generateMarkers(FlickrObj.photos[id])
        }
      }
      $('flickrLoading').style.visibility="hidden";
      }});

    }

FlickrC.prototype.generateMarkers = function (el) {


        var point = new GLatLng(el.coordinates.latitude, el.coordinates.longitude);
        icon = new GIcon();
        icon.image = el.square;
        icon.iconSize = new GSize(40, 40);
        icon.shadowSize = new GSize(22, 22);
        icon.iconAnchor = new GPoint(9, 9);
        icon.infoWindowAnchor = new GPoint(9, 0);
        flickrMarker = new GMarker(point, icon);
        el.html = "<div class='flickr_marker custom_marker'><div class='logo'><img src='http://l.yimg.com/g/images/flickr_logo_gamma.gif.v35314.14' alt=''></div><p><a href='http://flickr.com/photos/"+el.owner+"/"+el.id+"/' title='"+ el.title
          +"'><img src='"+el.thumbnail+"' alt=''></a></p><p>Owner: <a href='http://flickr.com/"+el.owner+"/' title = '"+el.owner+"'>"+
          el.owner + "</a> ["+el.title+"]</p></div>";
        map.addOverlay(flickrMarker);
        GEvent.addListener(flickrMarker, "click", function() {
        this.openInfoWindowHtml( el.html );
      });
      flickrVars.markers.push(flickrMarker);

}
FlickrC.prototype.show = function () {
      var center = map.getCenter();
      var bounds = map.getBounds();
      flickrVars.northEast = bounds.getNorthEast();
      flickrVars.southWest = bounds.getSouthWest();

      flickrVars.lat = center.lat();
      flickrVars.lon = center.lng();
      this.update();
    }

FlickrC.prototype.hide = function () {
      flickrVars.markers.each(function(el){map.removeOverlay(el)})
    }

function FlickrVars() {
  this.accuracy=4;
  this.lat;
  this.lon;
  this.perpage;
  this.page;
  this.markers = new Array();
}