if (Garmin == undefined) var Garmin = {};
if (Garmin.Foto == undefined) Garmin.Foto = {};


/** PanoramioPhoto extends AbstractPhoto to wrap Panoramio photo metadata.
 * @class Garmin.Photo.PanoramioPhoto
 *
 * @constructor 
 * @param {json} raw JSON object returned by specific photo service
 */
Garmin.Foto.PanoramioPhoto = Class.create();
Garmin.Foto.PanoramioPhoto.prototype = Object.extend(new Garmin.Foto.AbstractPhoto(), {

	initialize: function(json) {        
		this._init(json);
		this.icon = null;
	},
	
	/** Create an icon for map display
	 * TODO this method should not be Google Map aware and should be elsewere.
	 */ 
	getIcon: function() {
		if (!this.icon) {
	 		var icon = new GIcon();
			icon.image = $("imagePath").innerHTML + "/icon_move_2.png";
			icon.shadow = this.getImageUrl("thumbnail", this.getPhotoID());
			icon.iconSize = new GSize(34, 34);
			icon.shadowSize = new GSize(34, 34);
			icon.iconAnchor = new GPoint(0, 0);
			icon.infoWindowAnchor = new GPoint(15, 0);
			icon.dragCrossAnchor = new GPoint(10,-10);
			this.icon = icon;
		}
		return this.icon;
	},
	
	FILE_PREFIX: "Panoramio_",
				
	getPhotoID: function() { return ''+this.json.photo_id; },

	getTitle: function() { return this.json.photo_title; },
	
	setTitle: function(title) { this.json.photo_title = title; },
 
	getLat: function() { return this.json.latitude; },
	
	getLng: function() { return this.json.longitude; },
 
	setLat: function(lat) { this.json.latitude = lat; },

	setLng: function(lng) { this.json.longitude = lng; },

	getWidth: function() { return this.json.width; },
 
	getHeight: function() { return this.json.height; },
	
	getOwnerName: function() { return this.json.owner_name; },

	getOwnerURL: function() { return this.json.owner_url; },
 
	getPhotoPageURL: function() { return this.json.photo_url; },

	photoURL: function(options) { return this.json.photo_file_url; },
	
	iconURL: function() { return this.getImageUrl("thumbnail", this.getPhotoID()); },
	
	/** Currently used to retrieve thumbnail img.  "thumbnail" should be passed in for size param. */
	getImageUrl: function (size) { return "http://static" + ((this.json.photo_id % 4) + 1) + ".bareka.com/photos/" + size + "/" + this.getPhotoID() + ".jpg"; },
	
	uniqueFileName: function() {
		return this.FILE_PREFIX + this.getPhotoID() + ".jpg";
	}
	
});
			
