/**
 * Picasa Webalbum Integration jQuery plugin
 * This library was inspired aon pwa by Dieter Raber
 * @name jquery.pwi.js
 * @author Jeroen Diderik - http://www.multiprof.nl/
 * @revision 1.0.31
 * @date June 01, 2009
 * @copyright (c) 2009 Jeroen Diderik(www.multiprof.nl)
 * @license Creative Commons Attribution-Share Alike 3.0 Netherlands License - http://creativecommons.org/licenses/by-sa/3.0/nl/
 * @Visit http://pwi.googlecode.com/ for more informations, duscussions etc about this library
 */
(function(e){e.fn.pwi=function(b){var c;this.each(function(){c=e.data(this,"pwi");if(c)return false;new e.pwiGallery(this,b)});return c||this};e.pwi={version:"1.0.31",setDefaults:function(b){e.extend(t,b)}};var t={mode:'albums',username:'',album:"",authKey:"",albums:[],albumCrop:1,albumTitle:"",albumThumbSize:160,albumMaxResults:999,albumStartIndex:1,albumTypes:"public",page:1,photoSize:800,maxResults:50,thumbSize:72,thumbCrop:0,thumbCss:{'margin':'5px'},onclickThumb:"",showAlbumTitles:true,showAlbumdate:true,showAlbumPhotoCount:true,showAlbumDescription:true,showAlbumLocation:true,showSlideshowLink:true,showPhotoCaption:false,showPhotoDate:true,labels:{photo:"photo",photos:"photos",albums:"Back to albums",slideshow:"Display slideshow",loading:"PWI fetching data...",page:"Page",prev:"Previous",next:"Next",devider:"|"},months:["January","February","March","April","May","June","July","August","September","October","November","December"],slimbox_config:{loop:false,overlayOpacity:0.6,overlayFadeDuration:400,resizeDuration:400,resizeEasing:"swing",initialWidth:250,initlaHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"{x}/{y}",closeKeys:[27,88,67,70],prevKeys:[37,80],nextKeys:[39,83]},blockUIConfig:{message:"<div class='lbLoading pwi_loader'>loading...</div>",css:"pwi_loader"},albumstore:"",photostore:"",token:""};e.pwiGallery=function(z,A){var k,J=this,a;a=e.extend({},t,A);k=e(z);k.addClass('pwi_container');if(a.username==''){alert('Make sure you specify at least your username.\nSee http://pwi.googlecode.com for more info');return}switch(a.mode){case'latest':B();break;default:e.historyInit(C);break};function o(){var h,i,j=0;this.push=function(b){if(typeof(h)=='undefined'){i=new Array();h=i}else{var c=i;i=new Array();c[1]=i}i[0]=b;++j};this.toString=function(){if(j==0)return;while(j>1){var b=h,c=new Array(),d=c,f=0;while(typeof(b)!='undefined'){if(typeof(d[0])=='undefined'){d[0]=b[0];++f}else{if(typeof(b[0])!='undefined')d[0]+=b[0];d[1]=new Array();d=d[1]};b=b[1]};h=c;i=d;j=f};return h[0]}};function u(b){var c=new Date(Number(b)),d=c.getYear();if(d<1000){d+=1900};return(a.months[(c.getMonth())]+" "+c.getDate()+", "+d)};function v(b){var c=new Date(Number(b)),d=c.getYear();if(d<1000){d+=1900};return(c.getDate()+"-"+(c.getMonth()+1)+"-"+d+" "+c.getHours()+":"+(c.getMinutes()<10?"0"+c.getMinutes():c.getMinutes()))};function D(b){var c=new o();for(var d=0;d<b.feed.entry.length;d++){var f=b.feed.entry[d].gphoto$name.$t,h=u(b.feed.entry[d].gphoto$timestamp.$t),i=b.feed.entry[d].media$group.media$thumbnail[0].url.replace(new RegExp("/s160-c/","g"),"/");if(e.inArray(f,a.albums)>-1||a.albums.length==0){c.push("<div class='pwi_album'><a class='standard' href='#' onclick='javascript:$.historyLoad(\""+a.username+"/"+f+"/1\");return false;' title='"+b.feed.entry[d].title.$t+"'>");c.push("<img src='"+i+"?imgmax="+a.albumThumbSize+"&crop="+a.albumCrop+"'/><br>");a.showAlbumTitles?c.push("<a href='#' onclick='javascript:$.historyLoad(\""+a.username+"/"+f+"/1\");return false;'>"+b.feed.entry[d].title.$t+"</a><br/>"+(a.showAlbumdate?h:"")+(a.showAlbumPhotoCount?"&nbsp;&nbsp;&nbsp;&nbsp;"+b.feed.entry[d].gphoto$numphotos.$t+" "+a.labels.photos:"")):false;c.push("</div>")}};c.push("<div style='clear: both;height:0px;'> </div>");a.albumstore=c.toString();l(false,a.albumstore)}function E(b){var c=new o(),d=b.feed.openSearch$totalResults.$t,f=b.feed.gphoto$location.$t=="undefined"?"":b.feed.gphoto$location.$t,h=b.feed.subtitle.$t=="undefined"?"":b.feed.subtitle.$t,i=u(b.feed.gphoto$timestamp.$t),j=(d=="1")?false:true,q=b.feed.entry.length;a.albumTitle=b.feed.title.$t=="undefined"?a.albumTitle:b.feed.title.$t;c.push("<div class='pwi_album_description'>");if(a.mode!='album')c.push("<a href='#' onclick='$.historyLoad(\"\");return false;'>"+a.labels.albums+"</a> &gt; "+a.albumTitle+"<br/>");if(a.showAlbumDescription){c.push("<div class='title'>"+a.albumTitle+"</div>");c.push("<div class='details'>"+d+" "+(j?a.labels.photos:a.labels.photo)+(a.showAlbumdate?", "+i:"")+(a.showAlbumLocation&&f?", "+f:"")+"</div>");c.push("<div class='description'>"+h+"</div>");if(a.showSlideshowLink)c.push("<a href='http://picasaweb.google.com/"+a.username+"/"+b.feed.gphoto$name.$t+"/photo#s"+b.feed.entry[0].gphoto$id.$t+"' rel='gb_page_fs[]' target='_0' class='sslink'>"+a.labels.slideshow+"</a>")};c.push("</div>");if(d>a.maxResults){$pageCount=(d/a.maxResults);var p=a.labels.prev+" "+a.labels.devider+" ",n=a.labels.devider+" "+a.labels.next,m=new o();if(a.page>1){p="<a href='#' onclick='$.historyLoad(\""+a.username+"/"+a.album+"/"+(parseInt(a.page)-1)+"\");return false;'>"+a.labels.prev+"</a> | "};if(a.page<$pageCount){n="| <a href='#' onclick='$.historyLoad(\""+a.username+"/"+a.album+"/"+(parseInt(a.page)+1)+"\");return false;'>"+a.labels.next+"</a>"};m.push("<div class='pwi_pager'>"+p+a.labels.page+" ");for(var g=1;g<$pageCount+1;g++){if(g==a.page){m.push("<span class='pwi_pager_current'>"+g+"</span> ")}else{m.push("<a href='#' onclick='$.historyLoad(\""+a.username+"/"+a.album+"/"+g+"\");return false;'>"+g+"</a> ")}};m.push(n+"</div>");c.push(m.toString())};for(var g=0;g<q;g++){var w=b.feed.entry[g].content.src,K=b.feed.entry[g].gphoto$id.$t,x=(b.feed.entry[g].summary.$t?b.feed.entry[g].summary.$t:""),F=a.showPhotoDate?(b.feed.entry[g].exif$tags.exif$time?v(b.feed.entry[g].exif$tags.exif$time.$t):b.feed.entry[g].published.$t):"",G=F+" "+x.replace(new RegExp("'","g"),"&#39;");c.push("<div class='pwi_photo' style='height:"+(a.thumbSize+1)+"px;'>");c.push("<a href='"+w+"?imgmax="+a.photoSize+"' rel='lb-"+a.username+"' title='"+G+"'>");c.push("<img src='"+w+"?imgmax="+a.thumbSize+"&crop="+a.thumbCrop+"'/></a>");if(a.showPhotoCaption)c.push("<br/>"+x);c.push("</div>")};c.push(m);c.push("<div style='clear: both;height:0px;'> </div>");a.photostore=c.toString();l(false,a.photostore);var r=e(".pwi_photo");r.css(a.thumbCss);if(typeof(a.onclickThumb)!="function"&&e.slimbox){r.find("a[rel='lb-"+a.username+"']").slimbox(a.slimbox_config)}else if(typeof(a.onclickThumb)=="function"){r.find("a[rel='lb-"+a.username+"']").bind('click',y)}};function H(b){var c=new o(),d=b.feed.entry.length?b.feed.entry.length:0;for(var f=0;f<d;f++){var h=b.feed.entry[f].content.src,i=b.feed.entry[f].gphoto$id.$t,j=a.showPhotoCaption?(b.feed.entry[f].summary.$t?b.feed.entry[f].summary.$t:""):"",q=a.showPhotoDate?(b.feed.entry[f].exif$tags.exif$time?v(b.feed.entry[f].exif$tags.exif$time.$t):b.feed.entry[f].published.$t):"",p=q+" "+j.replace(new RegExp("'","g"),"&#39;");c.push("<div class='pwi_photo' >");c.push("<a href='"+h+"?imgmax="+a.photoSize+"' rel='lb-"+a.username+"' title='"+p+"'>");c.push("<img src='"+h+"?imgmax="+a.thumbSize+"&crop="+a.thumbCrop+"'/></a>");c.push("<br/>"+j);c.push("</div>")}c.push("<div style='clear: both;height:0px;'> </div>");l(false,c.toString());var n=e("div.pwi_photo").css(a.thumbCss);if(typeof(a.onclickThumb)!="function"&&e.slimbox){n.find("a[rel='lb-"+a.username+"']").slimbox(a.slimbox_config)}else if(typeof(a.onclickThumb)=="function"){n.find("a[rel='lb-"+a.username+"']").bind('click',y)}};function y(){a.onclickThumb.call(this);return false};function I(){if(a.albumstore!=""){l(false,a.albumstore)}else{l(true,'');var b='http://picasaweb.google.com/data/feed/api/user/'+a.username+'?kind=album&max-results='+a.albumMaxResults+'&access='+a.albumTypes+'&alt=json';e.getJSON(b,'callback=?',D)};return k};function s(){var b=((a.page-1)*a.maxResults)+1,c='http://picasaweb.google.com/data/feed/api/user/'+a.username+'/album/'+a.album+'?kind=photo&max-results='+a.maxResults+'&start-index='+b+'&alt=json'+((a.authKey!="")?"&authkey="+a.authKey:"");l(true,'');e.getJSON(c,'callback=?',E);return k};function B(){l(true,'');var b='http://picasaweb.google.com/data/feed/api/user/'+a.username+(a.album!=""?'/album/'+a.album:'')+'?kind=photo&max-results='+a.maxResults+'&alt=json&q='+((a.authKey!="")?"&authkey="+a.authKey:"");e.getJSON(b,'callback=?',H);return k};function C(b){if(b){if(b.split("/").length>2){a.username=b.split("/")[0];a.album=b.split("/")[1];a.page=b.split("/")[2];s()}else if(b.split("/").length>1){a.album=b.split("/")[0];a.page=b.split("/")[1];s()};}else if(a.album!=''&&a.mode=='album'){s()}else{I()}};function l(b,c){if(b){if(e.blockUI)k.block(a.blockUIConfig)}else{if(e.blockUI)k.unblock();k.html(c)}}}})(jQuery);
