/**
 * Picasa Webalbum Integration jQuery plugin
 * This library was inspired aon pwa by Dieter Raber
 * @name jquery.pwi-min.js
 * @author Jeroen Diderik - http://www.multiprof.nl/
 * @revision 1.1.00
 * @date September 12, 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(c){var b,a={};c.fn.pwi=function(d){var m,f={};d=c.extend({},c.fn.pwi.defaults,d);b=this;function j(){f=d;ts=new Date().getTime();f.id=ts;m=c("<div id='pwi_"+ts+"'/>").appendTo(b);m.addClass("pwi_container");g();return false}function g(){if(f.username==""){alert("Make sure you specify at least your username.\nSee http://pwi.googlecode.com for more info");return}switch(f.mode){case"latest":p();break;case"album":l();break;default:q();break}}function r(t){var u=new Date(Number(t)),s=u.getYear();if(s<1000){s+=1900}return(f.months[(u.getMonth())]+" "+u.getDate()+", "+s)}function o(t){var u=new Date(Number(t)),s=u.getYear();if(s<1000){s+=1900}return(u.getDate()+"-"+(u.getMonth()+1)+"-"+s+" "+u.getHours()+":"+(u.getMinutes()<10?"0"+u.getMinutes():u.getMinutes()))}function i(v){var u=c("<div/>");for(var w=0;w<v.feed.entry.length;w++){var t=v.feed.entry[w].gphoto$name.$t,x=r(v.feed.entry[w].gphoto$timestamp.$t),y=v.feed.entry[w].media$group.media$thumbnail[0].url.replace(new RegExp("/s160-c/","g"),"/"),s;if(c.inArray(t,f.albums)>-1||f.albums.length==0){s=c("<div class='pwi_album'/>").bind("click.pwi",t,function(z){z.stopPropagation();f.page=1;f.album=z.data;l();return false});s.append("<img src='"+y+"?imgmax="+f.albumThumbSize+"&crop="+f.albumCrop+"'/>");f.showAlbumTitles?s.append("<br/>"+v.feed.entry[w].title.$t+"<br/>"+(f.showAlbumdate?x:"")+(f.showAlbumPhotoCount?"&nbsp;&nbsp;&nbsp;&nbsp;"+v.feed.entry[w].gphoto$numphotos.$t+" "+f.labels.photos:"")):false;u.append(s)}}u.append("<div style='clear: both;height:0px;'/>");k(false,u)}function e(E){var C,s,L=E.feed.openSearch$totalResults.$t,G=E.feed.gphoto$location.$t=="undefined"?"":E.feed.gphoto$location.$t,I=E.feed.subtitle.$t=="undefined"?"":E.feed.subtitle.$t,x=r(E.feed.gphoto$timestamp.$t),z=(L=="1")?false:true,u=E.feed.entry.length;f.albumTitle=E.feed.title.$t=="undefined"?f.albumTitle:E.feed.title.$t;C=c("<div/>");s=c("<div class='pwi_album_description'/>");if(f.mode!="album"){var J=c("<div class='pwi_album_backlink'>"+f.labels.albums+"</div>").bind("click.pwi",function(M){M.stopPropagation();q();return false});s.append(J)}if(f.showAlbumDescription){s.append("<div class='title'>"+f.albumTitle+"</div>");s.append("<div class='details'>"+L+" "+(z?f.labels.photos:f.labels.photo)+(f.showAlbumdate?", "+x:"")+(f.showAlbumLocation&&G?", "+G:"")+"</div>");s.append("<div class='description'>"+I+"</div>");if(f.showSlideshowLink){s.append("<div><a href='http://picasaweb.google.com/"+f.username+"/"+E.feed.gphoto$name.$t+""+((f.authKey!="")?"?authkey="+f.authKey:"")+"#slideshow/"+E.feed.entry[0].gphoto$id.$t+"' rel='gb_page_fs[]' target='_new' class='sslink'>"+f.labels.slideshow+"</a></div>")}}C.append(s);if(L>f.maxResults){$pageCount=(L/f.maxResults);var K=c("<div class='pwi_prevpage'/>").text(f.labels.prev),D=c("<div class='pwi_nextpage'/>").text(f.labels.next),B=c("<div class='pwi_pager'/>");if(f.page>1){K.addClass("link").bind("click.pwi",function(M){M.stopPropagation();f.page=(parseInt(f.page)-1);l();return false})}B.append(K);for(var F=1;F<$pageCount+1;F++){if(F==f.page){J="<div class='pwi_pager_current'>"+F+"</div> "}else{J=c("<div class='pwi_pager_page'>"+F+"</div>").bind("click.pwi",F,function(M){M.stopPropagation();f.page=M.data;l();return false})}B.append(J)}if(f.page<$pageCount){D.addClass("link").bind("click.pwi",function(M){M.stopPropagation();f.page=(parseInt(f.page)+1);l();return false})}B.append(D);C.append(B)}for(var F=0;F<u;F++){var A=E.feed.entry[F].content.src,w=E.feed.entry[F].gphoto$id.$t,v=(E.feed.entry[F].summary.$t?E.feed.entry[F].summary.$t:""),y=f.showPhotoDate?(E.feed.entry[F].exif$tags.exif$time?o(E.feed.entry[F].exif$tags.exif$time.$t):E.feed.entry[F].published.$t):"",t=y+" "+v.replace(new RegExp("'","g"),"&#39;");$scPhoto=c("<div class='pwi_photo' style='height:"+(f.thumbSize+1)+"px;cursor: pointer;'/>");$scPhoto.append("<a href='"+A+"?imgmax="+f.photoSize+"' rel='lb-"+f.username+"' title='"+t+"'><img src='"+A+"?imgmax="+f.thumbSize+"&crop="+f.thumbCrop+"'/></a>");if(f.showPhotoCaption){$scPhoto.append("<br/>"+v)}C.append($scPhoto)}C.append(B);C.append("<div style='clear: both;height:0px;'/>");f.photostore=C;var H=c(".pwi_photo",C).css(f.thumbCss);if(typeof(f.popupExt)==="function"){f.popupExt(H.find("a[rel='lb-"+f.username+"']"))}else{if(typeof(f.onclickThumb)==="function"){H.find("a[rel='lb-"+f.username+"']").bind("click.pwi",n)}else{if(typeof(f.onclickThumb)!="function"&&c.slimbox){H.find("a[rel='lb-"+f.username+"']").slimbox(f.slimbox_config)}}}k(false,f.photostore)}function h(w){var z=c("<div/>"),u=w.feed.entry.length?w.feed.entry.length:0;for(var x=0;x<u;x++){var v=w.feed.entry[x].content.src,A=w.feed.entry[x].gphoto$id.$t,t=f.showPhotoCaption?(w.feed.entry[x].summary.$t?w.feed.entry[x].summary.$t:""):"",B=f.showPhotoDate?(w.feed.entry[x].exif$tags.exif$time?o(w.feed.entry[x].exif$tags.exif$time.$t):w.feed.entry[x].published.$t):"",s=B+" "+t.replace(new RegExp("'","g"),"&#39;");$scPhoto=c("<div class='pwi_photo' >");$scPhoto.append("<a href='"+v+"?imgmax="+f.photoSize+"' rel='lb-"+f.username+"' title='"+s+"'><img src='"+v+"?imgmax="+f.thumbSize+"&crop="+f.thumbCrop+"'/></a>");$scPhoto.append("<br/>"+t);z.append($scPhoto)}z.append("<div style='clear: both;height:0px;'> </div>");var y=c("div.pwi_photo",z).css(f.thumbCss);if(typeof(f.popupExt)==="function"){f.popupExt(y.find("a[rel='lb-"+f.username+"']"))}else{if(typeof(f.onclickThumb)==="function"){y.find("a[rel='lb-"+f.username+"']").bind("click",n)}else{if(typeof(f.onclickThumb)!="function"&&c.slimbox){y.find("a[rel='lb-"+f.username+"']").slimbox(f.slimbox_config)}}}k(false,z)}function n(){f.onclickThumb.call(this);return false}function q(){if(f.albumstore!=""){k(false,f.albumstore)}else{k(true,"");var s="http://picasaweb.google.com/data/feed/api/user/"+f.username+"?kind=album&max-results="+f.albumMaxResults+"&access="+f.albumTypes+"&alt=json";c.getJSON(s,"callback=?",i)}return m}function l(){var s=((f.page-1)*f.maxResults)+1,t="http://picasaweb.google.com/data/feed/api/user/"+f.username+"/album/"+f.album+"?kind=photo&max-results="+f.maxResults+"&start-index="+s+"&alt=json"+((f.authKey!="")?"&authkey="+f.authKey:"");k(true,"");c.getJSON(t,"callback=?",e);return m}function p(){k(true,"");var s="http://picasaweb.google.com/data/feed/api/user/"+f.username+(f.album!=""?"/album/"+f.album:"")+"?kind=photo&max-results="+f.maxResults+"&alt=json&q="+((f.authKey!="")?"&authkey="+f.authKey:"");c.getJSON(s,"callback=?",h);return m}function k(t,s){if(t){if(c.blockUI){m.block(f.blockUIConfig)}}else{if(c.blockUI){m.unblock()}m.html(s)}}j()};c.fn.pwi.defaults={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:"",popupExt:"",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:""}})(jQuery);