(function($,window,document,undefined){var pluginName="sharrre",defaults={className:"sharrre",share:{googlePlus:false,facebook:false,twitter:false,digg:false,delicious:false},template:"",title:"",url:document.location.href,text:document.title,urlCurl:"sharrre.php",count:{},total:0,shorterTotal:true,enableHover:true,enableCounter:true,enableTracking:false,hover:function(){},hide:function(){},click:function(){},render:function(){},buttons:{googlePlus:{url:"",size:"medium",lang:"en-US"},facebook:{url:"",action:"like",layout:"button_count",width:"",send:"false",faces:"false",colorscheme:"",font:"",lang:"en_US"},twitter:{url:"",count:"horizontal",via:"",related:"",lang:"en"},digg:{url:"",type:"DiggCompact"},delicious:{url:"",size:"medium"}}},urlJson={googlePlus:"",facebook:"http://graph.facebook.com/?id={url}&callback=?",twitter:"http://cdn.api.twitter.com/1/urls/count.json?url={url}&callback=?",digg:"http://services.digg.com/2.0/story.getInfo?links={url}&type=javascript&callback=?",delicious:"http://feeds.delicious.com/v2/json/urlinfo/data?url={url}&callback=?"},loadButton={googlePlus:function(self){var sett=self.options.buttons.googlePlus;$(self.element).find(".buttons").append('<div class="button googleplus"><div class="g-plusone" data-size="'+sett.size+'" data-href="'+(sett.url!==""?sett.url:self.options.url)+'"></div></div>');window.___gcfg={lang:self.options.buttons.googlePlus.lang};var loading=0;if(typeof gapi==="undefined"&&loading==0){loading=1;(function(){var po=document.createElement("script");po.type="text/javascript";po.async=true;po.src="https://apis.google.com/js/plusone.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(po,s);})();}else{gapi.plusone.go();}},facebook:function(self){var sett=self.options.buttons.facebook;$(self.element).find(".buttons").append('<div class="button facebook"><div class="fb-like" data-href="'+(sett.url!==""?sett.url:self.options.url)+'" data-send="'+sett.send+'" data-layout="'+sett.layout+'" data-width="'+sett.width+'" data-show-faces="'+sett.faces+'" data-action="'+sett.action+'" data-colorscheme="'+sett.colorscheme+'" data-font="'+sett.font+'" data-via="'+sett.via+'"></div></div>');var loading=0;if(typeof FB==="undefined"&&loading==0){loading=1;(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id)){return;}js=d.createElement(s);js.id=id;js.src="//connect.facebook.net/"+sett.lang+"/all.js#xfbml=1";fjs.parentNode.insertBefore(js,fjs);}(document,"script","facebook-jssdk"));}else{FB.XFBML.parse();}},twitter:function(self){var sett=self.options.buttons.twitter;$(self.element).find(".buttons").append('<div class="button twitter"><a href="https://twitter.com/share" class="twitter-share-button" data-url="'+(sett.url!==""?sett.url:self.options.url)+'" data-count="'+sett.count+'" data-text="'+self.options.text+'" data-via="'+sett.via+'" data-related="'+sett.related+'" data-lang="'+sett.lang+'">Tweet</a></div>');var loading=0;if(typeof twttr==="undefined"&&loading==0){loading=1;(function(){var twitterScriptTag=document.createElement("script");twitterScriptTag.type="text/javascript";twitterScriptTag.async=true;twitterScriptTag.src="http://platform.twitter.com/widgets.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(twitterScriptTag,s);})();}else{$.ajax({url:"http://platform.twitter.com/widgets.js",dataType:"script",cache:true});}},digg:function(self){var sett=self.options.buttons.digg;$(self.element).find(".buttons").append('<div class="button digg"><a class="DiggThisButton '+sett.type+'" rel="nofollow external" href="http://digg.com/submit?url='+(sett.url!==""?sett.url:self.options.url)+'"></a></div>');var loading=0;if(typeof __DBW==="undefined"&&loading==0){loading=1;(function(){var s=document.createElement("SCRIPT"),s1=document.getElementsByTagName("SCRIPT")[0];s.type="text/javascript";s.async=true;s.src="http://widgets.digg.com/buttons.js";s1.parentNode.insertBefore(s,s1);})();}},delicious:function(self){if(self.options.buttons.delicious.size=="tall"){var css="width:50px;",cssCount="height:35px;width:50px;font-size:15px;line-height:35px;",cssShare="height:18px;line-height:18px;margin-top:3px;";}else{var css="width:93px;",cssCount="float:right;padding:0 3px;height:20px;width:26px;line-height:20px;",cssShare="float:left;height:20px;line-height:20px;";}var count=self.shorterTotal(self.options.count.delicious);if(typeof count==="undefined"){count=0;}$(self.element).find(".buttons").append('<div class="button delicious"><div style="'+css+'font:12px Arial,Helvetica,sans-serif;cursor:pointer;color:#666666;display:inline-block;float:none;height:20px;line-height:normal;margin:0;padding:0;text-indent:0;vertical-align:baseline;"><div style="'+cssCount+'margin-bottom:5px;overflow:hidden;text-align:center;border:1px solid #ccc;border-radius:3px;">'+count+'</div><div style="'+cssShare+'display:block;padding:0;text-align:center;text-decoration:none;width:50px;background-color:#7EACEE;border:1px solid #40679C;border-radius:3px;color:#fff;"><img src="http://www.delicious.com/static/img/delicious.small.gif" height="10" width="10" alt="Delicious" /> Add</div></div></div>');$(self.element).find(".delicious").on("click",function(){self.openPopup("delicious");});}},tracking={googlePlus:function(){},facebook:function(){fb=window.setInterval(function(){if(typeof FB!=="undefined"){FB.Event.subscribe("edge.create",function(targetUrl){_gaq.push(["_trackSocial","facebook","like",targetUrl]);});FB.Event.subscribe("edge.remove",function(targetUrl){_gaq.push(["_trackSocial","facebook","unlike",targetUrl]);});FB.Event.subscribe("message.send",function(targetUrl){_gaq.push(["_trackSocial","facebook","send",targetUrl]);});clearInterval(fb);}},1000);},twitter:function(){tw=window.setInterval(function(){if(typeof twttr!=="undefined"){twttr.events.bind("tweet",function(event){if(event){_gaq.push(["_trackSocial","twitter","tweet"]);}});clearInterval(tw);}},1000);},digg:function(){$(this.element).find(".digg").on("click",function(){_gaq.push(["_trackSocial","digg","add"]);});},delicious:function(){}},popup={googlePlus:function(opt){window.open("https://plusone.google.com/_/+1/confirm?hl="+opt.buttons.googlePlus.lang+"&url="+encodeURIComponent((opt.buttons.googlePlus.url!==""?opt.buttons.googlePlus.url:opt.url)),"","toolbar=0, status=0, width=900, height=500");},facebook:function(opt){window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent((opt.buttons.facebook.url!==""?opt.buttons.facebook.url:opt.url))+"&t="+opt.text+"","","toolbar=0, status=0, width=900, height=500");},twitter:function(opt){window.open("https://twitter.com/intent/tweet?text="+opt.text+"&url="+encodeURIComponent((opt.buttons.twitter.url!==""?opt.buttons.twitter.url:opt.url))+(opt.buttons.twitter.via!==""?"&via="+opt.buttons.twitter.via:""),"","toolbar=0, status=0, width=650, height=360");},digg:function(opt){window.open("http://digg.com/tools/diggthis/submit?url="+encodeURIComponent((opt.buttons.digg.url!==""?opt.buttons.digg.url:opt.url))+"&title="+opt.text+"&related=true&style=true","","toolbar=0, status=0, width=650, height=360");},delicious:function(opt){window.open("http://www.delicious.com/save?v=5&noui&jump=close&url="+encodeURIComponent((opt.buttons.delicious.url!==""?opt.buttons.delicious.url:opt.url))+"&title="+opt.text,"delicious","toolbar=no,width=550,height=550");}};function Plugin(element,options){this.element=element;this.options=$.extend(true,{},defaults,options);this._defaults=defaults;this._name=pluginName;this.init();}Plugin.prototype.init=function(){var self=this;if(this.options.urlCurl!==""){urlJson.googlePlus=this.options.urlCurl+"?url={url}";}$(this.element).addClass(this.options.className);if(typeof $(this.element).data("title")!=="undefined"){this.options.title=$(this.element).data("title");}if(typeof $(this.element).data("url")!=="undefined"){this.options.url=$(this.element).data("url");}if(typeof $(this.element).data("text")!=="undefined"){this.options.text=$(this.element).data("text");}if(self.options.enableCounter===true){$.each(this.options.share,function(name,val){if(val===true){try{self.getSocialJson(name);}catch(e){}}});}else{this.loadButtons();this.options.render(this,this.options);}$(this.element).hover(function(){if($(this).find(".buttons").length===0&&self.options.enableHover===true){self.loadButtons();}self.options.hover(self,self.options);},function(){self.options.hide(self,self.options);});$(this.element).click(function(){self.options.click(self,self.options);return false;});};Plugin.prototype.loadButtons=function(){var self=this;$(this.element).append('<div class="buttons"></div>');$.each(self.options.share,function(name,val){if(val==true){loadButton[name](self);if(self.options.enableTracking===true){tracking[name]();}}});};Plugin.prototype.getSocialJson=function(name){var self=this,count=0,url=urlJson[name].replace("{url}",this.options.url);if(url!=""){$.getJSON(url,function(json){if(typeof json.count!=="undefined"){count+=parseInt(json.count,10);}else{if(typeof json.shares!=="undefined"){count+=parseInt(json.shares,10);}else{if(typeof json[0]!=="undefined"){count+=parseInt(json[0].total_posts,10);}}}self.options.count[name]=count;self.options.total+=count;self.renderer();self.options.render(self,self.options);});}};Plugin.prototype.renderer=function(){var total=this.options.total,template=this.options.template;if(this.options.shorterTotal===true){total=this.shorterTotal(total);}if(template!==""){template=template.replace("{total}",total);$(this.element).html(template);}else{$(this.element).html('<div class="box"><a class="count" href="#">'+total+"</a>"+(this.options.title!==""?'<a class="share" href="#">'+this.options.title+"</a>":"")+"</div>");}};Plugin.prototype.shorterTotal=function(num){if(num>=1000000){num=(num/1000000).toFixed(2)+"M";}else{if(num>=1000){num=(num/1000).toFixed(1)+"k";}}return num;};Plugin.prototype.openPopup=function(site){popup[site](this.options);if(this.options.enableTracking===true){var tracking={googlePlus:{site:"Google",action:"+1"},facebook:{site:"facebook",action:"like"},twitter:{site:"twitter",action:"tweet"},digg:{site:"digg",action:"add"},delicious:{site:"delicious",action:"add"}};_gaq.push(["_trackSocial",tracking[site].site,tracking[site].action]);}};$.fn[pluginName]=function(options){return this.each(function(){if(!$.data(this,"plugin_"+pluginName)){$.data(this,"plugin_"+pluginName,new Plugin(this,options));}});};})(jQuery,window,document); 
