/*
Script: sharethis.js
	Contains <sharethis>

Author:
	Alan Roemen

Class: ShareThis
	<No Description>

Options:
	baseURL : URL of script. Default: false
	shareIMG : URL of Image. Default: false
	imgAlign : Image alignment around text. Options 'off' or 'both' or 'right' or 'left'. Default: 'off'
	timeout: Amount of time sharethis window will remain open. Default: false (false means it will timeout)
	duration: Amount of time to transition pop window opening. Default: 500
	offsets: PopUp offsets. Default: {'x': 0, 'y': 18}
	defaults: If set to true, will use page title and page url. Default: false
	shareTXT : Text to display in WebPage. Default: 'Share This Page'
	subject: Message default subject. Default: 'Check out this website'
	message: Message default message body. Default: 'I found a website that I thought you might find interesting. '
	className : Class name to CSS class. Default: 'ShareThis'

Events:
	onShow - optionally you can alter the default onShow behaviour with this option (like displaying a fade in effect);
	onHide - optionally you can alter the default onHide behaviour with this option (like displaying a fade out effect);
*/
var ShareThis=new Class({options:{onShow:function(A){if(window.ie6){A.setStyles({"visibility":"visible","opacity":1})}else{A.effects({duration:this.options.duration,transition:Fx.Transitions.quadInOut}).custom({"opacity":[0,1]})}},onHide:function(A){A.setStyle("visibility","hidden")},baseURL:false,shareIMG:false,imgAlign:"off",timeout:false,duration:500,offsets:{x:0,y:18},defaults:false,shareTXT:"Share This Page",subject:"Check out this website",message:"I found a website that I thought you might find interesting. ",globalClass:true,className:"ShareThis",scriptName:"sharethis"},initialize:function(){var A,C;$each(arguments,function(F,E){switch($type(F)){case"object":A=F;break;default:if(!C){C=$$(F)}else{C=C.concat($$(F))}}});this.fields=C;this.setOptions(A);if(!this.options.baseURL){var C=document.getElementsByTagName("script");for(var B=0;B<C.length;B++){if(C[B].src&&(C[B].src.indexOf(this.options.scriptName+".js")!=-1)){var D=C[B].src;this.options.baseURL=D.substring(0,D.lastIndexOf("/"));break}}this.documentBasePath=document.location.href;if(this.documentBasePath.indexOf("?")!=-1){this.documentBasePath=this.documentBasePath.substring(0,this.documentBasePath.indexOf("?"))}this.documentBasePath=this.documentBasePath.substring(0,this.documentBasePath.lastIndexOf("/"));if(this.options.baseURL.indexOf("://")==-1&&this.options.baseURL.charAt(0)!="/"){this.options.baseURL=this.documentBasePath+"/"+this.options.baseURL}}if(!this.options.shareIMG){this.options.shareIMG=this.options.baseURL+"/"+this.options.scriptName+".gif"}this.setfields();if(this.options.globalClass!==false){new Asset.css(this.options.baseURL+"/"+this.options.scriptName+".css",{id:"style"})}this.ajaxURL=this.options.baseURL+"/"+this.options.scriptName+".php";this.active=false;this.sharebox=new Element("div",{"class":this.options.className,"styles":{"position":"absolute","top":"0","left":"0","visibility":"hidden"}}).inject($$("body")[0]);this.wrapper=new Element("div").injectInside(this.sharebox)},setfields:function(){var A,C,B;C=$$("title")[0].innerHTML;B=location.href;$each(this.fields,function(E,D){A={"title":(E.title&&!this.options.defaults?E.title:C),"link":(E.innerHTML&&!this.options.defaults?E.innerHTML:B),"element":E};this.fields[D].empty();this.fields[D]=A;this.img=new Element("img",{"src":this.options.shareIMG,"styles":{"cursor":"pointer"},"events":{"click":(function(F){F=new Event(F).stop();this.start(D)}).bindWithEvent(this)}});if((this.options.imgAlign!="off"&&this.options.imgAlign!="right")||this.options.imgAlign=="both"){this.img.injectInside(this.fields[D].element)}this.fields[D].element.appendText(this.options.shareTXT);this.fields[D].element.setStyle("cursor","pointer");this.fields[D].element.addEvent("click",function(F){F=new Event(F).stop();this.start(D)}.bindWithEvent(this));if((this.options.imgAlign!="off"&&this.options.imgAlign=="right")||this.options.imgAlign=="both"){this.img.injectInside(this.fields[D].element)}}.bind(this))},build:function(){var B,C,A;this.wrapper.empty();this.header=new Element("div",{"class":"head"}).injectInside(this.wrapper);this.body=new Element("div",{"class":"body"}).injectInside(this.wrapper);this.close=new Element("a",{"href":"#","class":"close","events":{"click":(function(D){D=new Event(D);D.stop();this.end()}).bindWithEvent(this)}}).setHTML("close").injectInside(this.header);this.tabs=new Element("ul");this.tablinks=new Array();this.tablinks[0]=new Element("li",{"events":{"click":(function(D){if(this.alert_msg){this.alert_msg.remove();this.alert_msg=false}this.activeTab(0);this.toAddress.focus()}).bindWithEvent(this)}}).setHTML("Email").addClass("selected").injectInside(this.tabs);this.tablinks[1]=new Element("li",{"events":{"click":(function(D){this.activeTab(1)}).bindWithEvent(this)}}).setHTML("Social Web").injectInside(this.tabs);this.tabs.injectInside(this.header);this.bodydivs=new Array();this.bodydivs[0]=new Element("div",{"class":"email"});B=new Element("fieldset");new Element("legend").setHTML("Email It").injectInside(B);B.injectInside(this.bodydivs[0]);C=new Element("ul");A=new Element("li");new Element("label").setHTML("Recipient(s) Address").injectInside(A);this.toAddress=new Element("input",{"type":"text"}).injectInside(A);new Element("label").setHTML("(Multiple: friend1@site.com, friend2@site.com)").injectInside(A);A.injectInside(C);A=new Element("li");new Element("label").setHTML("Your Name").injectInside(A);this.senderName=new Element("input",{"type":"text"}).injectInside(A);A.injectInside(C);A=new Element("li");new Element("label").setHTML("Your Email Address").injectInside(A);this.senderAddress=new Element("input",{"type":"text"}).injectInside(A);A.injectInside(C);A=new Element("li");new Element("label").setHTML("Subject").injectInside(A);this.subject=new Element("input",{"type":"text","value":this.options.subject}).injectInside(A);A.injectInside(C);A=new Element("li");new Element("label").setHTML("Message").injectInside(A);this.message=new Element("textarea").setHTML(this.options.message).injectInside(A);A.injectInside(C);A=new Element("li");new Element("label").setHTML("<strong>Only</strong> enter the black characters in the image").injectInside(A);this.captcha=new Element("input",{"type":"text","class":"captcha"}).injectInside(A);this.captchaIMG=new Element("img",{"src":this.options.baseURL+"/images/captcha.php","title":"Click the image to obtain a new key","styles":{"cursor":"pointer"},"events":{"click":(function(D){D=new Event(D);D.stop();this.reloadCAPTCHA();this.captcha.focus()}).bindWithEvent(this)}}).injectInside(A);A.injectInside(C);A=new Element("li");new Element("button",{"events":{"click":(function(D){this.sendEmail()}).bindWithEvent(this)}}).setHTML("Send").injectInside(A);A.injectInside(C);C.injectInside(this.bodydivs[0]);this.bodydivs[0].injectInside(this.body);this.bodydivs[1]=new Element("ul",{"class":"social"});this.li=new Element("li");new Element("a",{"href":"http://del.icio.us/post?url="+this.fields[this.active].link+"&title="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_delicious.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("del.icio.us").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://digg.com/submit?phase=2&url="+this.fields[this.active].link+"&title="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_digg.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("Digg").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://furl.net/storeIt.jsp?u="+this.fields[this.active].link+"&t="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_furl.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("Furl").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://www.netscape.com/submit/?U="+this.fields[this.active].link+"&T="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_netscape.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("Netscape").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://myweb2.search.yahoo.com/myresults/bookmarklet?u="+this.fields[this.active].link+"&t="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_yahoo_myweb.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("Yahoo! My Web").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://www.stumbleupon.com/submit?url="+this.fields[this.active].link+"&title="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_stumbleupon.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("StumbleUpon").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://www.google.com/bookmarks/mark?op=edit&amp;bkmk="+this.fields[this.active].link+"&title="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_google_bmarks.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("Google Bookmarks").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://www.technorati.com/faves?add="+this.fields[this.active].link,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_technorati.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("Technorati").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://blinklist.com/index.php?Action=Blink/addblink.php&amp;Url="+this.fields[this.active].link+"&Title="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_blinklist.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("BlinkList").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://www.newsvine.com/_wine/save?u="+this.fields[this.active].link+"&h="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_newsvine.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("Newsvine").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://www.facebook.com/share.php?u="+this.fields[this.active].link+"&title="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_facebook.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("Facebook").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://reddit.com/submit?url="+this.fields[this.active].link+"&title="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_reddit.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("reddit").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url="+this.fields[this.active].link+"&title="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_windows_live.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("Windows Live").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.li=new Element("li");new Element("a",{"href":"http://tailrank.com/share/?link_href="+this.fields[this.active].link+"&title="+this.fields[this.active].title,"target":"_blank","styles":{"background":"transparent url("+this.options.baseURL+"/images/share_tailrank.gif) no-repeat"},"events":{"click":(function(D){this.end()}).bindWithEvent(this)}}).setHTML("Tailrank").injectInside(this.li);this.li.injectInside(this.bodydivs[1]);this.bodydivs[1].injectInside(this.body)},reloadCAPTCHA:function(){var A=this.captchaIMG.src;this.captcha.value="";this.captchaIMG.src=A+"?"+(new Date()).getTime()},sendEmail:function(){this.bodydivs[0].setStyle("opacity","0.5");var D=new Array();var C={to:{name:"To Address",value:this.toAddress.value},name:{name:"Your Name",value:this.senderName.value},from:{name:"Your Email Address",value:this.senderAddress.value},url:{name:"URL",value:this.fields[this.active].link},subject:{name:"Subject",value:this.subject.value},message:{name:"Message",value:this.message.value},captcha:{name:"Image Key",value:this.captcha.value}};for(var B in C){if(C[B].value.trim()==""){this.showError(C[B].name);return }}for(var A in C){D.push(A+"="+encodeURIComponent(C[A].value))}D=D.join("&");new Ajax(this.ajaxURL,{method:"post",data:"ax=send&"+D,onComplete:function(E){this.emailSent(E)}.bind(this)}).request()},showError:function(A){this.bodydivs[0].setStyle("opacity","1");this.reloadCAPTCHA();if(this.alert_msg){this.alert_msg.remove();this.alert_msg=false}this.alert_msg=new Element("p",{"class":"alert_msg"}).setHTML(A+" is missing or invalid").injectTop(this.body)},emailSent:function(B){if(B=="Email Sent"){if(this.alert_msg){this.alert_msg.remove();this.alert_msg=false}this.bodydivs[0].setStyle("opacity","1");this.alert_msg=new Element("p",{"class":"alert_msg"}).setHTML(B).injectTop(this.body);this.toAddress.value="";this.reloadCAPTCHA();var A=(function(){this.alert_msg.remove();this.alert_msg=false}.bind(this)).delay(5000)}else{this.showError(B)}},activeTab:function(B){for(var A=0;A<this.bodydivs.length;A++){if(A==B){this.tablinks[A].addClass("selected");this.bodydivs[A].setStyle("display","block")}else{if(this.tablinks[A]){this.tablinks[A].removeClass("selected")}this.bodydivs[A].setStyle("display","none")}}},position:function(){var A=this.fields[this.active].element.getPosition();this.sharebox.setStyles({"left":A.x+this.options.offsets.x,"top":A.y+this.options.offsets.y})},start:function(A){if(this.active!==false&&this.active==A){this.end();return }else{this.active=A}this.build();this.position();this.sharebox.setStyle("opacity","0");if(this.options.timeout){this.timer=this.end.delay(this.options.timeout,this)}this.fireEvent("onShow",[this.sharebox])},end:function(){this.alert_msg=false;this.active=false;$clear(this.timer);this.fireEvent("onHide",[this.sharebox]);for(var A=0;A<this.bodydivs.length;A++){this.bodydivs[A].removeProperty("style");if(window.webkit){this.bodydivs[A].setStyle("visibility","hidden")}}}});ShareThis.implement(new Events,new Options)