//console.debug('in fastshare.js ' , stFastShareObj);

/***************************JSONP********************/
var onDemand = new function() {
	
	return {

		js : function(fileSrc,callBack){
			this.head=document.getElementsByTagName('head')[0];
			this.scriptSrc=fileSrc;
			this.script=document.createElement('script');
			this.script.setAttribute('type', 'text/javascript');
			this.script.setAttribute('src', this.scriptSrc);
			this.script.async = true;
			this.script.onload=callBack;
			this.script.onreadystatechange=function(){
				if(this.readyState=='loaded'){
					callBack();
				}
			};
			this.s = document.getElementsByTagName('script')[0]; 
			this.s.parentNode.insertBefore(this.script, this.s);
		},
		css : function(fileSrc,callBack) {
			var cssInterval;
			this.head=document.getElementsByTagName('head')[0];
			this.cssSrc=fileSrc;
			this.css=document.createElement('link');
			this.css.setAttribute('rel', 'stylesheet');
			this.css.setAttribute('type', 'text/css');
			this.css.setAttribute('href', fileSrc);
			this.css.setAttribute('id', fileSrc);
			setTimeout(function(){
				callBack();
				if(!document.getElementById(fileSrc)){
					cssInterval=setInterval(function(){
						if(document.getElementById(fileSrc)){
							clearInterval(cssInterval);
							callBack();
						}
					}, 100);
				}
			},100);
			this.head.appendChild(this.css);		
		}
	};		
}();

var jsonp={};

jsonp.makeRequest=function(url){
	onDemand.js(url,function(){});
};

var jsUtilities = function() {
	return {
		clearTextArea : function(e)
		{
			e = e || window.event;
			var target = e.target || e.srcElement;
			if(target.value == target.getAttribute('placeholder'))
			{
				target.value = "";			
			}
		},
		fillTextArea : function(e)
		{
			e = e || window.event;
			var target = e.target || e.srcElement;
			if(target.value=='') 
			{
				if(target.getAttribute('placeholder')==null) {
					target.value = '';
				} else {
					target.value = target.getAttribute('placeholder');
				}
			}
		},
		trimString : function(str){
			if(str==null){
				return '';
			}
			return str.replace(/^\s+|\s+$/g,"");
		}
	};
}();

var fastShare = new function(){
	
	var d=document;
	var widgetOpen=false;
	
	var meta=document.getElementsByTagName("meta");

	var ogTitle, ogUrl;
	for(var i=0;i<meta.length;i++){
		if(meta[i].getAttribute('property')=="og:title"){
			ogTitle=meta[i].getAttribute('content');
		}else if(meta[i].getAttribute('property')=="og:url"){
			ogUrl=meta[i].getAttribute('content');
		}
	}

	var url = stFastShareObj.url;
	var title = stFastShareObj.title;
	var service = stFastShareObj.service;
	var username = stFastShareObj.username;

	var oldText="";
	//var template="Write your comment here...";
	var fsBox;
	var fsHTML = '<div style="position:relative;margin-right:10px;margin-top:10px;"><div id="stOCClose" class="close">&nbsp;</div><h2 id="fsHeading">Hi <em id="fsUsername"></em>, share this on <span id="headingServiceName">&nbsp;</span></h2><div class="container" id="fs_mainBody"><p id="twCountMsg" style="display:none;">The message should be less than 140 characters.</p><textarea placeholder="Write your comment here..." maxlength="1000" name="shareMessage" id="st_shareMessage">Write your comment here...</textarea><img id="loadingImg" style="display:none;"/><div class="fsFooter"><a id="fsSignOut">Sign Out</a><span id="showMessage">Show Message</span><span id="st_twCounter" class="counter" style="display:none;"></span><a id="st_shareButton" class="ctaButton">Share</a></div></div><div id="fs_doneScreen" style="display:none;"><p id="fs_doneMsg">&nbsp;</p></div></div>';
	
	//var fsHTML = '<div id="stOCClose" class="close">X</div><div class="container" id="fs_mainBody"><textarea placeholder="Write your comment here..." maxlength="1000" name="shareMessage" id="st_shareMessage">Write your comment here...</textarea><div class="footer"><span id="friendsWall" style="display:none;"><a id="postFriendsLink">Post to a friend\'s Facebook wall</a><span id="friendsInputWrapper" style="display:none;"><input type="text" autocomplete="off" id="txtFriendsName" name="txtFriendsName"/><a class="widgetIcons" id="cancelFriendsWall">&nbsp;</a></span><div id="friendsBox">&nbsp;</div></span><span id="showMessage">Show Message</span><span id="st_twCounter" class="counter" style="display:none;"></span><a id="st_shareButton" class="ctaButton">Share</a></div></div><div id="fs_doneScreen" style="display:none;"><p id="fs_doneMsg">&nbsp;</p></div>';

	var sharCreated = false;
	var needToShort = true;
	var sharFetched = false;
	
	var currentService;
	var sharURL = '';
	var twitterMessagePopulated = false;
	
	var sharPoller, fsLogger={};

	function stripHTML(oldString)
	{
		return oldString.replace(/<.*?>/g, '');
	}
	
	function getPageSize()
	{
		var pScroll = [0,0,0,0];
		var scX=0;
		var scY=0;
		var winX=0;
		var winY=0;
		if (typeof(window.pageYOffset) == 'number') {
		    //Netscape compliant
			scX=window.pageXOffset;
			scY=window.pageYOffset;
		} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		    //DOM compliant
			scX=document.body.scrollLeft;
			scY=document.body.scrollTop;
		} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		    //IE6 standards compliant mode
			scX=document.documentElement.scrollLeft;
			scY=document.documentElement.scrollTop;
		}

		if (window.innerWidth) {
			winX=window.innerWidth;
		 	winY=window.innerHeight;
		}
		else if (document.documentElement.offsetWidth) {
			winX= document.documentElement.offsetWidth;
			winY=document.documentElement.offsetHeight;
		}
		pScroll={scrX:scX,scrY:scY,width:winX,height:winY};
		return pScroll;
	}

	function getPosition(shareChicklet){
		
		function getHW(elem) {
			var retH=0;
			var retW=0;
			var going = true;
			while( elem!=null ) {
				retW+= elem.offsetLeft;
				if (going) {
					retH+= elem.offsetTop;
				}
				if (window.getComputedStyle) {
					if (document.defaultView.getComputedStyle(elem,null).getPropertyValue("position") == "fixed") {
						retH += (document.documentElement.scrollTop || document.body.scrollTop);
						going = false;
					}
				} else if (elem.currentStyle) {
					if (elem.currentStyle["position"] == "fixed") {
						retH += (document.documentElement.scrollTop || document.body.scrollTop);
						going = false;
					}
				}
				elem= elem.offsetParent;
			}
			return {height:retH,width:retW};
		}
		
		if(!shareChicklet){
			return false;
		}

		var chicklet = shareChicklet;
		var curleft = curtop = 0;

		var mPos = getHW(chicklet);
		curleft = mPos.width;
		curtop = mPos.height;

		var chicklet = shareChicklet;
		var eltop = 0;
		var elleft = 0;
		var topVal = 0;
		var leftVal = 0;
		var elemH = 0;
		var elemW = 0;
		eltop = curtop + chicklet.offsetHeight + 5;
		elleft = curleft + 4;
		topVal = eltop;
		topVal = eval(topVal);
		elemH = topVal;
		topVal += "px";
		leftVal = elleft;
		leftVal = eval(leftVal);
		elemW = leftVal;
		leftVal += "px";
		//console.debug(topVal, leftVal, document.body.scrollTop);
		fsBox.style.top = topVal;
		fsBox.style.left = leftVal;
		fsBox.oldScroll = document.body.scrollTop;
		var pginfo = getPageSize();
		var effectiveH = pginfo.height + pginfo.scrY;
		var effectiveW = pginfo.width + pginfo.scrX;
		var widgetH = 180;
		var widgetW = 355;
		var needH = widgetH + elemH; 
		var needW = widgetW + elemW; 
		var diffH = needH - effectiveH;
		var diffW = needW - effectiveW;
		var newH = elemH - diffH;
		var newW = elemW - diffW;
		
		var buttonPos = getHW(chicklet);
		var leftA, rightA, topA, bottomA = false;
		if (diffH > 0) {
			// bottom space is not available assume top is
			bottomA = false;
			topA = true;
			if ((buttonPos.height - widgetH) > 0) {
				newH = buttonPos.height - widgetH;
			}
			fsBox.style.top = newH + "px";
		}
		if (diffW > 0) {
			// left is not available assume right is...
			leftA = false;
			rightA = true;
			if ((buttonPos.width - widgetW) > 0) {
				newW = buttonPos.width - widgetW;
			}
			fsBox.style.left = newW + "px";
		}

		if(shareChicklet.parentNode && shareChicklet.parentNode.id=='stpulldownMain'){
			fsBox.style.position = 'fixed';
		} else if(shareChicklet.parentNode && shareChicklet.parentNode.parentNode && shareChicklet.parentNode.parentNode.id=='sharebarMain') {
			fsBox.style.top = (newH - pginfo.scrY) + 'px';
			fsBox.style.position = 'fixed';
		}
		else if(shareChicklet.parentNode && shareChicklet.parentNode.parentNode && shareChicklet.parentNode.parentNode.id=='sthoverbuttonsMain'){
			fsBox.style.top = eval(eltop-pginfo.scrY)+"px";
			fsBox.style.position = 'fixed';
		}
		else{
			fsBox.style.position = 'absolute';
		}
		//console.debug('Top is - ' + fsBox.style.top, 'Left is - ' + fsBox.style.left);		
	}

	/*function populateMessage(chicklet){
		var temp=fastShare.returnTemplate();
		
		temp=temp.replace(/\{url\}/gi,url);
		temp=temp.replace(/\{title\}/gi,title);
		return temp;
	}*/

	function fillBox(chicklet){
		if(service=='twitter')
		{
			var shar;
			if(!sharFetched)
			{
				shar='';
				createShar();
				clearInterval(sharPoller);
				sharPoller = setInterval( function(){
					shar = getSharURL();
					if(shar!='')
					{
						clearInterval(sharPoller);
						sharFetched = true;
						populateTwitterBox();
						clearInterval(sharPoller);
					}
				}, 1000);
			}
			else
			{
				populateTwitterBox();
			}
		}
		else 
		{
			document.getElementById("st_shareMessage").value = document.getElementById("st_shareMessage").getAttribute('placeholder');
		}
		updateCount();
	}

	function getMessageTemplate(){
		return template;
	}

	function updateCount(){
		if(service=='twitter')
		{
			var count = 140 - document.getElementById("st_shareMessage").value.length;
			document.getElementById("st_twCounter").innerHTML=count;
			if(count<0){
				document.getElementById("st_twCounter").setAttribute("style","color:#FF0000;");
				document.getElementById('twCountMsg').style.display='block';
			}else{
				document.getElementById("st_twCounter").setAttribute("style","");
				document.getElementById('twCountMsg').style.display='none';
			}	
		}
	}


	function editTemplate(){
		document.getElementById("editTemplate").style.display="none";
		document.getElementById("showMessage").style.display="inline";
		oldText = document.getElementById("st_shareMessage").value;
		document.getElementById("st_shareMessage").value=getTemplate();
		document.getElementById("st_twCounter").style.visibility="hidden";
		document.getElementById("st_shareButton").setAttribute("style","background:#888;");

	}

	/*
	function showMessage(){
		//document.getElementById("editTemplate").style.display="inline";
		document.getElementById("showMessage").style.display="none";
		document.getElementById("st_twCounter").style.visibility="visible";
		document.getElementById("st_shareButton").setAttribute("style","");
		updateCount();
		fillBox();
	}
	*/

	
	function createShar()
	{
		//console.debug('in createShar');
		if(url!=="" && url!==" " && url!==null && !sharCreated)
		{	
			if(needToShort!=true){
				sharURL=url;
				sharCreated = true;
				return true;
			}else{
				var data=["return=json","cb=fastShare.createShar_onSuccess","service=createSharURL","url="+encodeURIComponent(url)];
				data=data.join('&');
				jsonp.makeRequest((("https:" == document.location.protocol) ? "https://ws." : "http://wd.") + "sharethis.com/api/getApi.php?"+data);
			}
		}
	}
	
	function getSharURL()
	{
		return sharURL;
	}

	function postMessage()
	{
		//console.debug('in post message', service);
		var data;
		var comment = stripHTML(document.getElementById('st_shareMessage').value);
		var twitterComment = comment;
		data = ["return=json","cb=fastShare.postMessage_onSuccess", "url="+sharURL, "title="+encodeURIComponent(stFastShareObj.title),  "source=fastShare", "publisher="+ encodeURIComponent(stFastShareObj.publisher), "hostname="+ encodeURIComponent(stFastShareObj.hostname), "location="+ encodeURIComponent(stFastShareObj.location), "sessionID="+stFastShareObj.sessionID, "fpc="+stFastShareObj.fpc, "type=" +service + "_fastShare", "refer=" + document.referrer, "agent=" + navigator.userAgent,"aurl=" + encodeURIComponent(stFastShareObj.url)];
		
		gaLog('Fast Share Complete', service);
		
		if(typeof(stFastShareObj.image)!='undefined' && stFastShareObj.image!=='' && stFastShareObj.image!=null){
			data.push("img=" + stFastShareObj.image);
		}
		
		if(typeof(stFastShareObj.summary)!='undefined' && stFastShareObj.summary!=='' && stFastShareObj.summary!=null){
			data.push("description=" + encodeURIComponent(stFastShareObj.summary));
		}
		
		var mBox = document.getElementById('st_shareMessage');
		if(mBox.getAttribute('placeholder')==mBox.value){
			comment = '';
		}
		
		var hasUrlInComment = comment.indexOf('http://shar.es');
		if(hasUrlInComment == -1){
			hasUrlInComment = comment.indexOf('http://qa.shar.es');
			if(hasUrlInComment == -1){
				hasUrlInComment = comment.indexOf('http://qa2.shar.es');
			}
		}
		
		if( hasUrlInComment != -1){
			comment = comment.slice(0, hasUrlInComment);
		}
		
		var apiUrl = (("https:" == document.location.protocol) ? "https://ws." : "http://wd.") + "sharethis.com/api/getApi.php?";
		if(service == 'twitter')
		{
			//console.debug('in twitter');
			if(twitterComment.length > 140)
			{
				var tUrl = twitterComment.slice(twitterComment.indexOf('http'), twitterComment.indexOf('http') + 24);
				twitterComment = twitterComment.slice(0, 115) + ' ' + tUrl;
			}
			
			data.push("service=postTwitter", "status=" + encodeURIComponent(twitterComment), "destination=twitter");
			data=data.join('&');
			jsonp.makeRequest(apiUrl+data);
		}
		else if (service == 'facebook')
		{
			//console.log('in facebook');
		 	data.push("service=postFacebook", "comment=" + encodeURIComponent(comment), "destination=facebook");
			data=data.join('&');
			jsonp.makeRequest(apiUrl+data);
		}
		else if (service == 'yahoo')
		{
			data.push("service=postYahooPulse", "comment=" + encodeURIComponent(comment), "destination=ypulse");
			data=data.join('&');
			jsonp.makeRequest(apiUrl+data);
		}
		else if (service == 'linkedin')
		{
		 	data.push("service=postLinkedIn", "comment=" + encodeURIComponent(comment), "destination=linkedin");
			data=data.join('&');
			jsonp.makeRequest(apiUrl+data);
		}
		else if (service.search('facebookfriend')!='-1')
		{
			var friendId = service.slice(service.indexOf('-') + 1);
			data.push("service=postFacebookUserWall", "comment=" + encodeURIComponent(comment), "destination=facebook", "friend_id=" + friendId);
			data=data.join('&');
			jsonp.makeRequest(apiUrl+data);
		}
	}
	
	/*
	function initFacebookFriends()
	{
		document.getElementById('postFriendsLink').style.display='none';
		document.getElementById('friendsInputWrapper').style.display='block';
		if(typeof(facebook)=="undefined")
		{
			onDemand.js((("https:" == document.location.protocol) ? "https://ws.sharethis.com/secure5x/js/facebook.js" : "http://w.sharethis.com/share5x/js/facebook.js"),function(){});
		}
		else
		{
			facebook.getFacebookFriends(true);
		}
	}
	
	function cancelFacebookFriends()
	{
		document.getElementById('postFriendsLink').style.display='block';
		document.getElementById('friendsInputWrapper').style.display='none';
		document.getElementById('txtFriendsName').value = '';
		//domUtilities.removeClassIfPresent('null', 'txtFriendsName', 'friendSelected');
	}
	*/
	
	function populateTwitterBox()
	{
		//console.trace();
		//console.log('in populateTwitterBox ', twitterMessagePopulated, sharFetched);
		if(!twitterMessagePopulated)
		{	
			var appendString =  stFastShareObj.title + ' ' + getSharURL();
			var mBox=document.getElementById('st_shareMessage');
			if(mBox.getAttribute('placeholder')==mBox.value){
				mBox.value = appendString;
			} else {
				mBox.value += ' ';
				mBox.value += appendString;
			}
			twitterMessagePopulated = true;
		}
		updateCount();
	}
	
	function getURLInfo()
	{
		var data=['return=json',"url="+encodeURIComponent(stFastShareObj.url),"cb=fastShare.fillURLInfo","service=getLiveUrlInfo"];
		data=data.join('&');
		jsonp.makeRequest((("https:" == document.location.protocol) ? "https://ws." : "http://wd.") + "sharethis.com/api/getApi.php?"+data);
	}

	function signOut()
	{
		deleteCookie('recents');
		deleteCookie('ShareUT');
		deleteCookie('stOAuth');
		document.getElementById('fsSignOut').style.display='none';
		document.getElementById('fsHeading').innerHTML='<em id="fsUsername"></em>Share this on <span id="headingServiceName">'+ service +'</span>';
		//fastShare.hideWidget();
	}

	function deleteCookie(name)
	{
		var _div = document.createElement('div');
		_div.setAttribute("id", name);
		_div.setAttribute("type", "hidden");
		document.body.appendChild(_div);

		var
		div = document.getElementById(name),
		form = document.createElement('form');

		try {
		  var iframe = document.createElement('<iframe name="'+name+'" ></iframe>');
			//try is ie
		} catch(err) {
			//catch is ff and safari
			iframe = document.createElement('iframe');
		}
			
		iframe.name = name;
		iframe.src = 'javascript:false';
		iframe.style.display="none";
		div.appendChild(iframe);

		form.action = (("https:" == document.location.protocol) ? "https://sharethis.com/" : "http://sharethis.com/")+"account/deleteCookie.php";
		form.method = 'POST';

		var hiddenField = document.createElement("input");
		hiddenField.setAttribute("type", "hidden");
		hiddenField.setAttribute("name", "name");
		hiddenField.setAttribute("value", name);
		form.appendChild(hiddenField);

		form.target = name;
		div.appendChild(form);

		form.submit();
	}
	
	function initGA(){
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		var headID = document.getElementsByTagName("head")[0];         
		var newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		newScript.src = gaJsHost + "google-analytics.com/ga.js";
		onDemand.js(newScript.src,function(){
			 try{
				fsLogger.ga = _gat._getTracker("UA-1645146-17");
				fsLogger.ga._trackPageview();
			 }catch(err) {}
		});
	}
	
	function gaLog(category, action, label, value) {
		 if( typeof(fsLogger.ga) != "undefined" && fsLogger.ga!==null ) {
			fsLogger.ga._trackEvent(category, action, label, value);
		 }
	}
	
	return {
		returnTemplate : function()
		{
			//console.debug(template);
			return template;
		},
		
		createFastShare : function()
		{
			var docBody = document.getElementsByTagName('body')[0];
			var fsWrapper = document.createElement('div');
			fsWrapper.innerHTML = fsHTML;
			fsWrapper.setAttribute('id', 'stOCWrapper');
			fsWrapper.className = 'fsWrapper';
			fsWrapper.style.display = 'block';
			docBody.appendChild(fsWrapper);
			fsBox = document.getElementById('stOCWrapper');
		},
		
		initWidget : function()
		{
			var cssUrl = (("https:" == document.location.protocol) ? "https://ws.sharethis.com/button/css/fastShare-secure.css" : "http://w.sharethis.com/button/css/fastShare.css");
			onDemand.css(cssUrl,function(){});
			//console.info('now starting init');
			fastShare.createFastShare();
			document.getElementById("fsSignOut").onclick=function(e){signOut(e);};
			document.getElementById("stOCClose").onclick=function(e){fastShare.hideWidget(e);};
			document.getElementById("st_shareMessage").onkeyup=function(e){updateCount(e);};
			document.getElementById("st_shareButton").onclick=function(e){
				createShar();
				clearInterval(sharPoller);
				sharPoller = setInterval( function(){
					shar = getSharURL();
					if(shar!='')
					{
						clearInterval(sharPoller);
						sharFetched = true;
						document.getElementById('loadingImg').style.display="inline";
						document.getElementById('loadingImg').src='http://w.sharethis.com/images/spinner.gif';
						postMessage();
						clearInterval(sharPoller);
					}
				}, 1000);
			};
			document.getElementById("st_shareMessage").onfocus=function(e){jsUtilities.clearTextArea(e);};
			document.getElementById("st_shareMessage").onblur=function(e){jsUtilities.fillTextArea(e);};
			
			initGA();
			
			/*
			document.getElementById('postFriendsLink').onclick=function(e){initFacebookFriends(e)};
			document.getElementById('cancelFriendsWall').onclick=function(e){cancelFacebookFriends(e)};
			
			//console.debug('look, i am in init');
			//document.getElementById("editTemplate").onclick=function(){editTemplate();};
			//document.getElementById("showMessage").onclick=function(e){showMessage(e);};
			*/
		},
		
		
		hideWidget : function()
		{
			document.getElementById("stOCWrapper").style.display="none";
			widgetOpen=false;
		},

		showWidget : function()
		{
			sharCreated = false;
			//console.log(fsBox);
			if(widgetOpen==true){
				fastShare.hideWidget();
				return false;
			}
			//console.debug(stFastShareObj);
			gaLog('Fast Share', stFastShareObj.service);
			//e = e || window.event;
			//var target = e.target || e.srcElement;

			var target = stFastShareObj.element;
			service = stFastShareObj.service;
			username = stFastShareObj.username;
			document.getElementById('fsUsername').innerHTML = username;
			document.getElementById('fsSignOut').style.display='inline';
			
			if(url!=stFastShareObj.url)
			{
				url = stFastShareObj.url;
				title = stFastShareObj.title;
				sharFetched = false;
				twitterMessagePopulated = false;
				document.getElementById('st_shareMessage').value = document.getElementById('st_shareMessage').getAttribute('placeholder');
			}
			
			if(service!='twitter')
			{
				if( (typeof(stFastShareObj.image)=='undefined' || stFastShareObj.image==='' || stFastShareObj.image==null) || (typeof(stFastShareObj.summary)=='undefined' || jsUtilities.trimString(stFastShareObj.summary)==='' && stFastShareObj.summary==null) )
				{
					getURLInfo();	
				}	
			}
			
			document.getElementById('twCountMsg').style.display='none';
			if(service=='twitter'){
				document.getElementById('st_twCounter').style.display='inline';
				twitterMessagePopulated = false;
				document.getElementById('st_shareMessage').value = document.getElementById('st_shareMessage').getAttribute('placeholder');
			} else {
				document.getElementById('st_twCounter').style.display='none';
			}
			
			document.getElementById('headingServiceName').innerHTML = service;
			getPosition(target);

			document.getElementById("stOCWrapper").style.display="block";
			document.getElementById('fs_mainBody').style.display="block";
			document.getElementById('fs_doneScreen').style.display="none";
			fillBox(target);
			widgetOpen=true;

			//console.log(service);
			/*
			if(service=='twitter'){
				document.getElementById('st_twCounter').style.display='inline';
				document.getElementById('friendsWall').style.display='none';
			} else if(service=='facebook'){
				document.getElementById('friendsWall').style.display='inline-block';
				document.getElementById('st_twCounter').style.display='none';
			} else {
				document.getElementById('friendsWall').style.display='none';
				document.getElementById('st_twCounter').style.display='none';
			}
			*/
		},
		
		
		fillURLInfo : function(response)
		{
			if(response && response.status=="SUCCESS")
			{	
				if(typeof(stFastShareObj.image)=='undefined' || stFastShareObj.image==='' || stFastShareObj.image==null)
				{
					if( (typeof(response.urls[0].img)!='undefined' && response.urls[0].img != "null" && response.urls[0].img != "" &&  response.urls[0].img.indexOf('http://sharethis.com/share/thumb')==-1 ) || (response.urls[0].imagehash && response.urls[0].imagehash != ""))
					{		
						if (response.urls[0].imagehash && response.urls[0].imagehash != "")
						{
							stFastShareObj.image = "http://img.sharethis.com/" + response.urls[0].imagehash + "/100_100.jpg";
						} 
						else
						{
							stFastShareObj.image = response.urls[0].img;
						}
					}
				}

				if (typeof(stFastShareObj.summary)=='undefined' || jsUtilities.trimString(stFastShareObj.summary)==='' || stFastShareObj.summary==null)
				{
					if(typeof(response.urls[0].snippet)!='undefined')
					{
						stFastShareObj.summary = response.urls[0].snippet;

					}
				}
			}
		},
		
		createShar_onSuccess : function(response)
		{
			//console.debug(response);
			if(response && response.status=="SUCCESS")
			{
				sharURL=response.data.sharURL;
				sharCreated = true;
			}
			else
			{
				sharURL = url;
			}
		},
		
		postMessage_onSuccess : function(response)
		{
			//console.debug(response);			
			document.getElementById('fs_mainBody').style.display="none";
			document.getElementById('fs_doneScreen').style.display="block";
			document.getElementById('loadingImg').style.display='none';
			if(response && response.status=="SUCCESS")
			{
				document.getElementById('fs_doneMsg').innerHTML="Your message was succesfully shared!";
				document.getElementById('twCountMsg').style.display='none';
				//console.debug('look, it worked');
			}
			else
			{
				if(response && response.statusMessage=='MISSING_PARAMETER_TOKEN')
				{
					document.getElementById('fs_doneMsg').innerHTML="Sorry, it seems like you are not signed in.";					
				}
				else
				{
					document.getElementById('fs_doneMsg').innerHTML="Sorry, there was an error. Please try again later.";	
				}
			}
		}
	};
}();

fastShare.initWidget();
