// ==UserScript==
// @name           Wordpress Social Bookmarks
// @namespace      http://www.m69.co.uk/greasemonkey/
// @description    Script to quickly add social bookmarking links to posts
// @include        http://*.wordpress.com/wp-admin/post*.php*
// @include        https://*.wordpress.com/wp-admin/post*.php*
// ==/UserScript==
function clear() {
	var sb=document.getElementById('sbtext');
	if(!(sb==null)){
		sb.parentNode.removeChild(sb);
		ss=document.getElementById('sbex');
		ss.parentNode.removeChild(ss);
	}
}
function AddSB() {
	if(document.getElementById('socialmedia').className=='postbox closed'){
		clear();
		var social_text='<a href="http://del.icio.us/post?url=xURIx;title=xTITLEx" rel="nofollow" title="add to del.icio.us"><img src="http://osblues.files.wordpress.com/2008/07/delicious.gif" alt="add to del.icio.us" title="del.icio.us:xTITLEx" /></a> :: <a href="http://technorati.com/faves/?add=xURIx;title=xTITLEx" rel="nofollow" title="add to Technorati"><img title="Technorati:xTITLEx" src="http://osblues.files.wordpress.com/2008/07/technorati.gif" alt="Bookmark Post in Technorati" /></a> :: <a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=xURIx;Title=xTITLEx" rel="nofollow" title="add to Blinkslist"><img src="http://osblues.files.wordpress.com/2008/07/blinklist.gif" alt="Add to Blinkslist" title="blinklist:xTITLEx" /></a> :: <a href="http://www.furl.net/storeIt.jsp?u=xURIx;t=xTITLEx" rel="nofollow" title="add to Furl"><img src="http://osblues.files.wordpress.com/2008/07/furl.gif" alt="add to furl" title="furl:xTITLEx" /></a> :: <a href="http://digg.com/submit?phase=2&url=xURIx" rel="nofollow" title="Digg it"><img src="http://osblues.files.wordpress.com/2008/07/digg.gif" alt="Digg it" title="Digg it:xTITLEx" /></a> :: <a href="http://ma.gnolia.com/bookmarklet/add?url=xURIx;title=xTITLEx" rel="nofollow" title="add to ma.gnolia"><img src="http://osblues.files.wordpress.com/2008/07/magnolia.gif" alt="add to ma.gnolia" title="ma.gnolia:xTITLEx" /></a> :: <a href="http://www.stumbleupon.com/submit?url=xURIx&title=xTITLEx" rel="nofollow" title="Stumble it!"><img src="http://osblues.files.wordpress.com/2008/07/stumbleit.gif" alt="Stumble It!" title="Stumble it:xTITLEx" /></a> :: <a href="http://www.simpy.com/simpy/LinkAdd.do?url=xURIx;title=xTITLEx" rel="nofollow" title="add to Simpy"><img src="http://osblues.files.wordpress.com/2008/07/simpy.png" alt="add to simpy" title="simpy:xTITLEx" /></a> :: <a href="http://www.newsvine.com/_tools/seed&save?url=xURIx;title=xTITLEx" rel="nofollow" title="seed the vine"><img src="http://osblues.files.wordpress.com/2008/07/newsvine.gif" alt="seed the vine" title="newsvine:xTITLEx" /></a> :: <a href="http://reddit.com/submit?url=xURIx;title=xTITLEx" rel="nofollow" title="add to Reddit"><img src="http://osblues.files.wordpress.com/2008/07/reddit.gif" title="reddit:xTITLEx" /></a> :: <a href="http://cgi.fark.com/cgi/fark/edit.pl?new_url=xURIx;new_comment=xTITLEx" rel="nofollow" title="add to Fark"><img src="http://osblues.files.wordpress.com/2008/07/fark.png" title="fark:xTITLEx" /></a> :: <a href="http://tailrank.com/share/?text=&link_href=xURIx&title=xTITLEx" rel="nofollow" title="add to TailRank"><img src="http://osblues.files.wordpress.com/2008/07/tailrank.gif" alt="TailRank" /></a> :: <a href="http://www.facebook.com/sharer.php?u=xURIx&t=xTITLEx" rel="nofollow" title="post to FaceBook"><img src="http://sunburntkamel.files.wordpress.com/2008/02/facebookcom.gif" alt="post to facebook" title="facebook:xTITLEx" /></a> :: <a href="http://www.google.com/bookmarks/mark?op=edit&bkmk=xURIx;title=xTITLEx" rel="nofollow" title="bookmark on Google"><img alt="Bookmark on Google" src="http://osblues.files.wordpress.com/2008/07/google_bmarks.gif" title="Google:xTITLEx" /></a> :: <a href="http://www.netscape.com/submit/?U=xURIx;title=xTITLEx" rel="nofollow" title="add to Netscape"><img alt="Add to Netscape" src="http://osblues.files.wordpress.com/2008/07/netscape.gif" title="NetScape:xTITLEx" /></a> :: <a href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=xURIx;title=xTITLEx" rel="nofollow" title="share on Yahoo!"><img alt="Share on Yahoo" src="http://osblues.files.wordpress.com/2008/07/yahoo_myweb.gif" title="Yahoo:xTITLEx" /></a> :: <a href="https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=xURIx;title=xTITLEx" rel="nofollow" title="add this to Live"><img alt="Add this to Live" src="http://osblues.files.wordpress.com/2008/07/windows_live.gif" title="Live:xTITLEx" /></a>'
		var title = document.getElementById('title').value.replace(/ /g,'+');
		var permalink = document.getElementById('sample-permalink').innerHTML.replace(/<span.*<\/span>\//g,'');
		var post_name_full = document.getElementById('editable-post-name-full').innerHTML;
		var uri = permalink+post_name_full+'/';
		social_text = social_text.replace(/xURIx/g,uri);
		social_text = social_text.replace(/xTITLEx/g,title);
		var s=document.createElement('textarea');
		s.id='sbtext';
		s.cols='40';
		s.rows='8';
		s.style.margin='0pt 0pt 5pt 0pt';
		s.style.width='100%';
		s.style.border='0pt none';
		s.style.lineHeight='150%';
		s.style.outlineColor='invert';
		s.style.outlineStyle='none';
		s.style.outlineWidth='medium';
		s.style.padding='0pt';
		s.innerHTML=social_text;
		var div=document.getElementById('sbdiv');
		div.appendChild(s);
		var ex=document.createElement('span');
		ex.id='sbex';
		ex.style.paddingTop='5px';
		ex.style.fontWeight='bold';
		ex.innerHTML='Simply copy the above in to your post (HTML tab).  You probably want them at the end.';
		div.appendChild(ex);
		document.getElementById('socialmedia').className='postbox';
	} else {
		document.getElementById('socialmedia').className='postbox closed';
	}
	
}
window.addEventListener('load', function() {
	var outdiv=document.createElement('div');
	outdiv.className='postbox closed';
	outdiv.id='socialmedia';
	var handlediv=document.createElement('div');
	handlediv.className='handlediv';
	handlediv.title='Expand to generate';
	var h3=document.createElement('h3');
	h3.className='hndle';
	h3.innerHTML='<span>Social Bookmarks</span>';
	var indiv=document.createElement('div');
	indiv.className='inside';
	indiv.id='sbdiv';
	outdiv.appendChild(handlediv);
	outdiv.appendChild(h3);
	outdiv.appendChild(indiv);
	handlediv.addEventListener('click',function() {AddSB();},true);
	document.getElementById('postexcerpt').parentNode.insertBefore(outdiv,document.getElementById('postexcerpt'));
}, true);