/* user_pano_layer_jk.js is a modified version of Pamela Fox's pano_layer.js
 * Purpose is to access Panoramio JSON GET without GMAP.
 * 
 * Kevin Dixon 
 * 2010.01.26
 * 2010.01.27 removed some unused bits of code and white space
 * 2010.01.27 improved referencing of divs.
 * 2010.02.09 added some html to integrate with a JavaScript Slideshow on pano_get7.html. 

 * Jan Kocbach
 * 2010.02.21 Some changes to make it more similar to Example 2 at 
 * http://www.panoramio.com/api/
 */

function PanoramioLayerCallback(json, panoLayer) {
  this.panoLayer = panoLayer;
  var html = "<div>";
  for (var i = 0; i < json.photos.length; i++) {
    var photo = json.photos[i];
    if (photo.photo_title.length > 40) {photo.photo_title = photo.photo_title.substring(0, 40) + "&#8230;";}

    html +=  "<a id='photo_infowin' target='_blank' href='" + photo.photo_url + "'>" + "<img style='margin-left:3px;margin-right:3px;border:0' src='" + photo.photo_file_url + "' title='"+  photo.photo_title + " &copy; " + photo.owner_name + " (from Panoramio)'></a><br><A HREF='"+photo.photo_url+"'>" + photo.photo_title +"</A> - autor: <A HREF='"+photo.owner_url+"'>"+ photo.owner_name +"</A><br><A HREF='http://www.panoramio.com'><img src='../panoramio.gif' border='0'></A><br><br>";
    thumb=i+1;
  }
  if (json.photos.length>0)
  {
    html+='<br><font color="#777">Photos provided by Panoramio. Photos are under the copyright of their owners.</font>'
  }
  html+="</div>";
  document.getElementById('panophotos').innerHTML=html;
}
function panoLayer(){};
function PanoramioLayer(){};
function readpano()
{
  PanoramioLayerCallback.prototype.formImgUrl = function(photoId, imgType) {return 'http://www.panoramio.com/photos/' + imgType + '/' + photoId + '.jpg';}
  PanoramioLayerCallback.prototype.formPageUrl = function(photoId) {return 'http://www.panoramio.com/photo/' + photoId;}

  PanoramioLayer.prototype.load = function(panoLayer, userOptions) {
    for (optionName in userOptions) {if (userOptions.hasOwnProperty(optionName)) {options[optionName] = userOptions[optionName];}}};

  for (optionName in options) {
    if (options.hasOwnProperty(optionName)) {
      var optionVal = "" + options[optionName] + "";
      url += optionName + "=" + optionVal + "&";
      uniqueID += optionVal.replace(/[^\w]+/g,"");
    }}
  var callbackName = "PanoramioLayerCallback.loader" + uniqueID;
  eval(callbackName + " = function(json) { var pa = new PanoramioLayerCallback(json, panoLayer);}");
  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);
}


