﻿var _flickr_photos = Array();var _flickr_image_current;var _flickr_page = 1;var _flickr_pages = 1;var _flickr_per_page = 1;var _flickr_total = 0;function flickrFetch(o){	var s = 	{		api_key: null,              // [string]    required, see http://www.flickr.com/services/api/misc.api_keys.html		type: null,                 // [string]    allowed values: 'photoset', 'search', default: 'flickr.photos.getRecent'		photoset_id: null,          // [string]    required, for type=='photoset'  		photo_id: null,          	// [string]    required, for type=='photo'  		text: null,			        // [string]    for type=='search' free text search		user_id: null,              // [string]    for type=='search' search by user id		group_id: null,             // [string]    for type=='search' search by group id		tags: null,                 // [string]    for type=='search' comma separated list		tag_mode: 'any',            // [string]    for type=='search' allowed values: 'any' (OR), 'all' (AND)		sort: 'relevance',    		// [string]    for type=='search' allowed values: 'date-posted-asc', 'date-posted-desc', 'date-taken-asc', 'date-taken-desc', 'interestingness-desc', 'interestingness-asc', 'relevance'		thumb_size: 's',            // [string]    allowed values: 's' (75x75), 't' (100x?), 'm' (240x?)		size: null,                 // [string]    allowed values: 'm' (240x?), 'b' (1024x?), 'o' (original), default: (500x?)		per_page: 100,              // [integer]   allowed values: max of 500		page: 1,     	            // [integer]   see paging notes		attr: '',                   // [string]    optional, attributes applied to thumbnail <a> tag		api_url: null,              // [string]    optional, custom url that returns flickr JSON or JSON-P 'photos' or 'photoset'		params: '',                 // [string]    optional, custom arguments, see http://www.flickr.com/services/api/flickr.photos.search.html		api_callback: '?',          // [string]    optional, custom callback in flickr JSON-P response		load_callback: null,        // [function]    optional, custom callback in flickr JSON-P response		callback: null,             // [function]  optional, callback function applied to entire <ul>		callback_param: null        // [object]  optional, callback param to pass to the callback	};		if(o) $.extend(s, o);		return queryFlickr(s);}function queryFlickr(s){	var url = $.flickr.format(s);	_flickr_photos = Array();	$.getJSON(url, function(r)	{		if (r.stat != "ok")		{			var _err = "";						for (i in r)			{				_err += i + ': ' + r[i] + "\n";			}						//alert(_err);		} 		else 		{			if(s.type == 'search' || s.type == 'photoset')			{				if (s.type == 'photoset') r.photos = r.photoset;								_flickr_page = r.photos.page;				_flickr_pages = r.photos.pages;				_flickr_per_page = r.photos.perpage;				_flickr_total = r.photos.total;												//console.log("r.photos.page: %d", r.photos.page);				//console.log("r.photos.pages: %d", r.photos.pages);				//console.log("r.photos.perpage: %d", r.photos.perpage);				//console.log("r.photos.total: %d", r.photos.total);				//console.log("r.photos.photo.length: %d", r.photos.photo.length);								//for (var i=0; i<r.photos.photo.length; i++)				for (var i=0; i<r.photos.photo.length; i++)				{					_flickr_photos.push(r.photos.photo[i]);										if (s.load_callback) s.load_callback(r.photos.photo[i]);						}			}			else if(s.type == 'photo')			{								_flickr_image_current = r.photo;							}						if (s.callback)			{				s.callback(s.callback_param1, s.callback_param2);			}		};	});}$.flickr = {	//http://api.flickr.com/services/rest/?format=json&api_key=508d5015d0032bd169af26461b5ef4a8&method=flickr.photos.search&group_id=874442@N25	format: function(s)	{		if (s.url) return s.url;			var url = 'http://api.flickr.com/services/rest/?format=json&jsoncallback='+s.api_callback+'&api_key='+s.api_key;			switch (s.type)		{			case 'photo':				url += '&method=flickr.photos.getInfo&photo_id=' + s.photo_id;			break;						case 'photoset':				url += '&method=flickr.photosets.getPhotos&photo_id=' + s.photoset_id;			break;					case 'search':				url += '&method=flickr.photos.search&sort=' + s.sort;					if (s.user_id) url += '&user_id=' + s.user_id;				if (s.group_id) url += '&group_id=' + s.group_id;				if (s.tags) url += '&tags=' + s.tags;				if (s.tag_mode) url += '&tag_mode=' + s.tag_mode;				if (s.text) url += '&text=' + s.text;			break;				default:				url += '&method=flickr.photos.getRecent';		};			if (s.size == 'o') url += '&extras=original_format';			url += '&per_page=' + s.per_page + '&page=' + s.page + s.params;		return url;	},		getThumbnail: function(photo)	{		return 'http://farm'+photo['farm']+'.static.flickr.com/'+photo['server']+'/'+photo['id']+'_'+photo['secret']+'_s.jpg';	},		getURL: function(photo, size)	{		var h = 'http://farm'+photo['farm']+'.static.flickr.com/'+photo['server']+'/'+photo['id']+'_';		switch (size)		{			case 'm':				h += photo['secret'] + '_m.jpg';			break;						case 'b':				h += photo['secret'] + '_b.jpg';			break;					case 'o':				if (photo['originalsecret'] && photo['originalformat']) 				{					h += photo['originalsecret'] + '_o.' + photo['originalformat'];				} 				else 				{					h += photo['secret'] + '_b.jpg';				};			break;					default:				h += photo['secret'] + '.jpg';		};	}};