/*!
 * tn3 flickr plugin v1.1.0.26
 * http://tn3gallery.com/
 *
 * License
 * http://tn3gallery.com/license
 *
 * Date: 13 Jul, 2011 20:29:07 +0300
 */
(function(f){var j=f.fn.tn3.External;j.flickr=function(b,e){this.config=f.extend(true,{},j.flickr.config,b);this.extcon=e;this.init()};j.flickr.config={api_key:"",user_id:"",source:"search",photos:{extras:"description",page:1,per_page:20,media:"photos"},albums:{},albumInfo:{},thumbSize:"s",imageSize:"z"};j.flickr.prototype={config:null,extcon:null,init:function(){this.getAlbums()},getAlbums:function(){var b={user_id:this.config.user_id};switch(this.config.source){case "galleries":b.method="flickr.galleries.getList";
break;case "sets":b.method="flickr.photosets.getList";break;default:b={title:this.config.source,adata:{origin:this}};f.extend(b,this.config.albumInfo);this.extcon.setAlbumData([b]);return}b=f.extend(b,this.config.albums);this.request(b)},getImages:function(b,e){var a={};switch(this.config.source){case "galleries":a.method="flickr.galleries.getPhotos";a.gallery_id=b.id;break;case "sets":a.method="flickr.photosets.getPhotos";a.photoset_id=b.id;break;case "favorites":a.method="flickr.favorites.getPublicList";
a.user_id=this.config.user_id;break;case "interestingness":a.method="flickr.interestingness.getList";a.user_id=this.config.user_id;break;case "photostream":a.method="flickr.people.getPublicPhotos";a.user_id=this.config.user_id;break;case "search":a.method="flickr.photos.search";a.user_id=this.config.user_id}a=f.extend(a,this.config.photos);this.request(a,b,e)},request:function(b,e,a){b.api_key=this.config.api_key;b.format="json";f.ajax({url:"http://api.flickr.com/services/rest/?",type:"GET",dataType:"jsonp",
cache:false,context:this,jsonp:"jsoncallback",success:function(c){if(c.stat=="fail"){c="flickr: "+c.message;a===undefined?this.extcon.setAlbumData([],c):this.extcon.setImageData([],a,c)}else{for(var g in c){var d=g;break}switch(d){case "galleries":this.parseGalleries(c);break;case "photos":this.parsePhotos(c,a);break;case "photosets":this.parsePhotosets(c);break;case "photoset":this.parsePhotoset(c,e,a)}}},error:function(){a===undefined?this.extcon.setAlbumData([],"flickr: api call failed"):this.extcon.setImageData.call([],
a,"flickr: api call failed")},data:b})},parsePhotos:function(b,e){var a=[],c=this,g;f.each(b.photos.photo,function(d,h){g={raw:h};f.extend(g,{title:h.title,description:h.description._content,thumb:c.getFlickrURL(h,c.config.thumbSize),img:c.getFlickrURL(h,c.config.imageSize)});a.push(g)});this.extcon.setImageData(a,e)},getFlickrURL:function(b,e,a){if(a==undefined)a="";return"http://farm"+b[a+"farm"]+".static.flickr.com/"+b[a+"server"]+"/"+b[a+"id"]+"_"+b[a+"secret"]+"_"+e+".jpg"},parseGalleries:function(b){var e=
[],a=this,c;f.each(b.galleries.gallery,function(g,d){c={raw:d};f.extend(c,{title:d.title._content,description:d.description._content,thumb:a.getFlickrURL(d,a.config.thumbSize,"primary_photo_"),adata:{id:d.id,origin:a}});e.push(c)});this.extcon.setAlbumData(e)},parsePhotosets:function(b){var e=[],a=this,c;f.each(b.photosets.photoset,function(g,d){c={raw:d};f.extend(c,{title:d.title._content,description:d.description._content,thumb:a.getFlickrURL(f.extend({},d,{id:d.primary}),a.config.thumbSize),adata:{farm:d.farm,
id:d.id,origin:a}});e.push(c)});this.extcon.setAlbumData(e)},parsePhotoset:function(b,e,a){var c=[],g=this,d;f.each(b.photoset.photo,function(h,i){i.farm=e.farm;d={raw:i};f.extend(d,{title:i.title,description:i.description._content,thumb:g.getFlickrURL(i,g.config.thumbSize),img:g.getFlickrURL(i,g.config.imageSize)});c.push(d)});this.extcon.setImageData(c,a)}}})(jQuery);

