window.addEvent('domready',function(){
	$('share_this_form').injectTop($E('body'));
	$('share_this_form').setStyle('font-size','85%');
	if (window.ie6 && $('email_updates_form')) {
		$('email_updates_form').injectTop($E('body'));
	}
})

function share_this_show(type, id, orientation, url, title, bodytext)
{
	title = encodeURI(title.trim());
	var form = $('share_this_form');
	
	var link = $('share_this_link_' + id);
	var rel_node = form;
	do  {
		rel_node = rel_node.getParent();
	} while (rel_node.getParent() && rel_node.getParent().tagName.toLowerCase() != 'html' && (rel_node.getParent().getStyle('position') == '' || rel_node.getParent().getStyle('position') == 'static'));

	
	$('share_this_social').style.display = $('share_this_email').style.display = 'none';
	
	if ( type == 'social' ) {
		$('share_this_social').style.display = 'block';
	} else {
		$('share_this_email').style.display = 'block';
	}
	form.setStyle('visibility','hidden');
	if (form.style.display == 'block') {
	   form.style.display = 'none';
	}
	else {
	   form.style.display = 'block';
	}
	
	var offset = new Array((window.getWidth() - form.getSize().size.x) / 2 - rel_node.getPosition().x,
		(window.getHeight() - form.getSize().size.y) / 2 - rel_node.getPosition().y + window.getScrollTop()); // Position.cumulativeOffset(link);	
	
	form.style.left = offset[0] + 'px';
	form.style.top = offset[1] + 'px';

	if ($("share_this_delicious")) {$("share_this_delicious").href = "http://del.icio.us/post?url=" + url + "&title=" + title + "&notes=" + bodytext;}
	if ($("share_this_digg")) {$("share_this_digg").href = "http://digg.com/submit?phase=2&url=" + url + "&title=" + title + "&bodytext=" + bodytext;}
	if ($("share_this_furl")) {$("share_this_furl").href = "http://furl.net/storeIt.jsp?u=" + url + "&t=" + title;}
	if ($("share_this_netscape")) {$("share_this_netscape").href = "http://www.netscape.com/submit/?U=" + url + "&T=" + title;}
	if ($("share_this_yahoo_myweb")) {$("share_this_yahoo_myweb").href = "http://myweb2.search.yahoo.com/myresults/bookmarklet?u=" + url + "&t=" + title;}
	if ($("share_this_technorati")) {$("share_this_technorati").href = "http://www.technorati.com/faves?add=" + url + "";}
	if ($("share_this_google_bmarks")) {$("share_this_google_bmarks").href = "http://www.google.com/bookmarks/mark?op=edit&bkmk=" + url + "&title=" + title + "&annotation=" + bodytext;}
	if ($("share_this_newsvine")) {$("share_this_newsvine").href = "http://www.newsvine.com/_wine/save?u=" + url + "&h=" + title;}
	if ($("share_this_blinklist")) {$("share_this_blinklist").href = "http://blinklist.com/index.php?Action=Blink/addblink.php&Url=" + url + "&Title=" + title;}
	if ($("share_this_reddit")) {$("share_this_reddit").href = "http://reddit.com/submit?url=" + url + "&title=" + title;}
	if ($("share_this_blogmarks")) {$("share_this_blogmarks").href = "http://blogmarks.net/my/new.php?mini=1&url=" + url + "&title=" + title;}
	if ($("share_this_magnolia")) {$("share_this_magnolia").href = "http://ma.gnolia.com/bookmarklet/add?url=" + url + "&title=" + title;}
	if ($("share_this_windows_live")) {$("share_this_windows_live").href = "https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=" + url + "&title=" + title + "&top=1";}
	if ($("share_this_tailrank")) {$("share_this_tailrank").href = "http://tailrank.com/share/?link_href=" + url + "&title=" + title;}
	if ($("share_this_mrwong")) {$("share_this_mrwong").href = "http://www.mister-wong.de/index.php?action=addurl&bm_url=" + url + "&bm_description=" + title;}
	if ($("share_this_stumbleupon")) {$("share_this_stumbleupon").href = "http://www.stumbleupon.com/submit?" + url + "=url&title=" + title, url, title;}

	$$('#share_this_form a').each(function(node){
		if (/^\s*http/.test(node.getProperty('href'))) {
			node.target = "_blank";
		}
	});

	form.setStyle('visibility','visible');
}



function share_this_tab(tab) 
{
	var tab1 =  $('share_this_tab1');
	var tab2 =  $('share_this_tab2');
	var body1 = $('share_this_social');
	var body2 = $('share_this_email');
	
	switch (tab) {
		case '1':
			tab2.setClass('');
			tab1.setClass('selected');
			body2.style.display = 'none';
			body1.style.display = 'block';
			break;
		case '2':
			tab1.setClass('');
			tab2.setClass('selected');
			body1.style.display = 'none';
			body2.style.display = 'block';
			break;
	}
} 