var Flickr = {
	photostreamUrl: 'http://www.flickr.com/photos/viddo',
	
	API: {
		userId: '28313311@N07',
		apiBaseUrl: 'http://api.flickr.com/services/rest/',
		apiKey: '0ac48d9e0b886cf54994fa04d786abc1',
		
		getPublicPhotosUrl: function() {
			return this.getUrl('flickr.people.getPublicPhotos', '&per_page=50&extras=description,date_upload,date_taken');
		},
		
		getUrl: function(method, additionalQueryString) {
			if (typeof additionalQueryString === 'undefined') {
				additionalQueryString = '';
			}
			//this.apiBaseUrl + '?&method='+ method +'&api_key=' + this.apiKey + '&user_id='+ this.userId +'&format=json&jsoncallback=?
			return this.apiBaseUrl + '?&method='+ method +'&api_key=' + this.apiKey + '&user_id='+ this.userId +'&format=json' + additionalQueryString +'&jsoncallback=?';
		}
	},
	
	getImgSrc: function(farmId, serverId, id, secret, size) {
		//http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpg
		if (/[mstb]/.test(size)) {
			return 'http://farm'+ farmId +'.static.flickr.com/'+ serverId +'/'+ id +'_'+ secret +'_'+ size +'.jpg';
		} else {
			return 'http://farm'+ farmId +'.static.flickr.com/'+ serverId +'/'+ id +'_'+ secret +'.jpg';
		}
	},
	
	getImgHref: function(userId, photoId) {
		return 'http://www.flickr.com/photos/'+ userId +'/'+ photoId;
	},
	
	getBigSrc: function(src) {
		// Get current flickr photo src and replace the size var with b to get the large one.
		src = src.replace(/_[mst](\.\w{3,4})$/, "$1");
		return '<img src="'+ src +'" />';
	}
};

ImageOverlay = {
	id: '#imageOverlay',
	container: undefined,
	
	render: function(html) {
		if (typeof this.container === 'undefined') {
			this.container = $(this.id);
		}
		// Inject but hide image to begin with.
		var image = $(html);
		ImageOverlay.container.html(image ).children().hide();
		
		// Set temporary width/height to show spinner.
		ImageOverlay.container.css({ width: '52px', height: '52px' }).show();
		
		// Show image when ready.
		image.load(function() {
			image.show();
			ImageOverlay.container.css({ width: '', height: '' })
		});
		
		
	},
	
	reset: function() {
		this.container.hide();
	}
};