/* 	Google+ Activity Widget v1.0
	Blog : http://www.moretechtips.net
	Project: http://code.google.com/p/googleplus-activity-widget/
	Copyright 2009 [Mike @ moretechtips.net] 
	Licensed under the Apache License, Version 2.0 
	(the "License"); you may not use this file except in compliance with the License. 
	You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
*/
(function(f){f.fn.googlePlusActivity=function(o){o=f.extend({},f.fn.googlePlusActivity.defaults,o);return this.each(function(){var i=f(this),j=null,n=null,e=o,u=function(a){if(a.error)e.debug&&i.html('<b style="color:red">Error: '+a.error.message+"</b>");else if(a.displayName){n=f('<div class="gpaw-profile"></div>').prependTo(i);n.html((a.image?'<a href="'+a.url+'" class="avatar"><img src="'+t(a.image.url,{sz:e.avatar_max})+'" /></a>':"")+'<div class="name">'+a.displayName+'</div><a href="'+a.url+'" class="add">Add to circles</a>');r()}},t=function(a,b){var c=a+(a.indexOf("?")<0?"?":"&"),g=true;for(var m in b){g||(c+="&");c=c+m+"="+encodeURIComponent(b[m]);g=false}return c},w=function(a){if(a.error)e.debug&&i.html('<b style="color:red">Error: '+a.error.message+"</b>");else if(a.items){var b=a.items.length;if(b!=0){j=f('<ul class="gpaw-body" style="height:'+e.body_height+'px"></ul>');if(n)j.insertAfter(n);else j=j.prependTo(i);j.append('<div class="fade"></div>');for(b=b-1;b>=0;b--){var c=a.items[b],g=c.object.replies?c.object.replies.totalItems:0,m=c.object.plusoners?c.object.plusoners.totalItems:0,p=c.object.resharers?c.object.resharers.totalItems:0,d;d={src:"",imgLink:"",useLink:"",useTitle:""};var k=c.object.attachments;if(k)if(k.length){for(var l=0;l<k.length;l++){var h=k[l];if(h.image){d.src=h.image.url;d.imgLink=h.url;if(h.fullImage){d.w=h.fullImage.width||0;d.h=h.fullImage.height||0}}if(h.objectType=="article")d.useLink=h.url;if(h.displayName)d.useTitle=h.displayName}if(!d.useLink)d.useLink=d.imgLink;if(d.src.indexOf("resize_h")>=0)d.src=d.w>=d.h?d.src.replace(/resize_h=\d+/i,"resize_h="+e.image_height):d.src.replace(/resize_h=\d+/i,"resize_w="+e.image_width)}d=d;j.append("<li>"+(e.show_image&&d.src?'<span class="thumb" style="width:'+(e.image_width+2)+"px; height:"+(e.image_height+2)+'px; overflow:hidden">'+(d.useLink?'<a href="'+d.useLink+'">':"")+'<img src="'+d.src+'" />'+(d.useLink?"</a>":"")+"</span>":"")+'<span class="title">'+(d.useLink?'<a href="'+d.useLink+'">':"")+(c.title?c.title:d.useTitle)+(d.useLink?"</a>":"")+'</span><span class="meta">'+(e.show_plusones?'<span class="plusones">+'+q(m)+"</span>":"")+(e.show_shares?'<span class="shares">'+q(p)+" shares</span>":"")+(e.show_replies?'<span class="replies">'+q(g)+" comments</span>":"")+(e.show_date?'<a class="date" href="'+c.url+'">'+v(c.published)+"</a>":"")+" &raquo;</span></li>")}r();e.rotate&&s()}}},q=function(a){var b=a;if(a>999999)b=Math.floor(a/1E6)+"M";else if(a>9999)b=Math.floor(a/1E3)+"K";else if(a>999)b=Math.floor(a/1E3)+","+a%1E3;return b},v=function(a){var b=a;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d*)?(Z|[+-]\d{2}:\d{2})$/i.test(b)){a=b.slice(0,4);var c=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][1*b.slice(5,7)],g=b.slice(8,10),m=b.slice(11,13),p=b.slice(14,16),d=b.slice(17,19),k="GMT";if(b.indexOf("Z")==-1){var l=b.lastIndexOf(":");k+=b.slice(l-3,l)+b.slice(l+1)}a=g+" "+c+" "+a+" "+m+":"+p+":"+d+" "+k}else a="";b=new Date;b.setTime(Date.parse(a));a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];c=Math.floor((new Date-b)/1E3);if(c<0)c=0;return c<60?c+" seconds ago":c/60<60?Math.floor(c/60)+" minutes ago":c/60/60<24?Math.floor(c/60/60)+" hours ago":a[b.getMonth()]+" "+b.getDate()+", "+b.getFullYear()},s=function(){var a=f("li",j),b=a.size();if(!(b<=1)){var c=a.eq(0),g=a.eq(b-1);g.css({display:"none",visibility:"hidden"}).remove().insertBefore(c);g.animate({height:"show"},e.slide_time,"linear",function(){g.css({display:"none",visibility:"visible"});f(this).fadeIn(e.fade_time,x)})}},x=function(){j.animate({opacity:1},e.stay_time,"linear",s)},r=function(){f(".gpaw-info",i).show().css("display","block")};(function(){var a=i.attr("data-options");if(!a){var b=i.html().replace(/\n|\r\n/g,"");if(b)if((b=b.match(/<!--\s*(\{.+\});?\s*--\>/))&&b.length==2)a=b[1]}if(a){if(a.indexOf("{")<0)a="{"+a+"}";try{e=eval("("+a+")")}catch(c){i.html('<b style="color:red">'+c+"</b>");return}e=f.extend({},f.fn.googlePlusActivity.defaults,e)}!e.user&&e.debug&&i.html('<b style="color:red">user ID was not set!</b>');f.ajax({url:"https://www.googleapis.com/plus/v1/people/"+e.user+"/activities/public",data:{key:e.api_key,maxResults:e.n,prettyprint:false,fields:"items(id,kind,object(attachments(displayName,fullImage,id,image,objectType,url),id,objectType,plusoners,replies,resharers,url),published,title,url,verb)"},success:w,cache:true,dataType:"jsonp"});e.show_profile&&f.ajax({url:"https://www.googleapis.com/plus/v1/people/"+e.user,data:{key:e.api_key,prettyprint:false,fields:"displayName,image,tagline,url"},success:u,cache:true,dataType:"jsonp"})})()})};f.fn.googlePlusActivity.defaults={debug:0,api_key:"AIzaSyD9RxIkPH0TYhPRp6zfn0NYjjVqQEjtWP0",user:"",n:20,rotate:1,stay_time:5E3,slide_time:200,fade_time:500,show_profile:1,show_date:1,show_replies:1,show_plusones:1,show_shares:1,show_image:1,image_width:75,image_height:75,avatar_max:50,body_height:300}})(jQuery);jQuery(document).ready(function(){jQuery("div.google-plus-activity").googlePlusActivity()});
