function newRecaptcha() {
	Recaptcha.create("6LdZxQUAAAAAAEXD6ahcV_izZXG0e1voiddu2Woy",
	"recaptcha_div", {
   		theme: "custom",
   		callback: Recaptcha.focus_response_field
	});
}

function popShareMod(type) {
	
	if (type == "email") {
	
		var inner_recaptcha = '<div id="recaptcha_code" style="display:none;"><h3>Security Check</h3><div class="etof_input_desc"><span class="recaptcha_only_if_image">Can\'t read the words below? Try <a href="javascript:Recaptcha.reload();">different words</a> or an <a href="javascript:Recaptcha.switch_type(\'audio\')">audio CAPTCHA</a> challenge.</span><span class="recaptcha_only_if_audio">Return to <a href="javascript:Recaptcha.switch_type(\'image\')">image CAPTCHA challenge</a> or try <a href="javascript:Recaptcha.reload();">different audio</a>.</span></div><div class="etof_input_field"><div id="recaptcha_image" style="margin-left:8px;"></div></div><div class="etof_input_desc"><span class="recaptcha_only_if_image">Enter <i>both words</i> above, <i>separated by a space</i>:</span><span class="recaptcha_only_if_audio">Enter your response here:</span></div><div class="etof_input_field"><input class="popup" type="text" name="recaptcha_response_field" id="recaptcha_response_field" /></div></div>';
		
		var inner_html = '<div id="share_container_email"><div class="share_container_content"><div class="share_container_headspace"><div id="share_container_close" onclick="javascript:closeShareMod(\'email\');"></div></div><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td nowrap="nowrap"><h1 class="sharing_header">Email to a Friend</h1></td><td>&nbsp;</td><td class="sharing_hash" width="100%">&nbsp;</td><td width="15"><img src="/images/blank.gif" width="15" height="1"></td></tr></table><table cellpading="0" cellspacing="0" border="0"><tr><td><p id="etof_form_intro">Fill out the form below to send this page to a friend.</p></td></tr><tr><td><div id="etof_form_container"><form name="form_etof" id="form_etof" method="get" action="/include/sharing/etof_ajax.php"><input type="hidden" name="url" value="'+location.href+'" /><div class="etof_input_desc">Friend\'s Email: <span class="etof_req">(Required)</span></div><div class="etof_input_field"><input class="popup" type="text" name="recipient_email" maxsize="100" /></div><div class="etof_input_desc">Your Name: <span class="etof_req">(Optional)</span></div><div class="etof_input_field"><input class="popup" type="text" name="sender_name" maxsize="100" /></div><div class="etof_input_desc">Your Email: <span class="etof_req">(Required)</span></div><div class="etof_input_field"><input class="popup" type="text" name="sender_email" maxsize="100" /></div><div class="etof_input_desc">Personal Message: <span class="etof_req">(500 character max)</div><div class="etof_input_field"><textarea name="personal_message" rows="4"></textarea></div><div id="etof_recaptcha_holder">'+inner_recaptcha+'</div><div class="etof_input_field"><input name="send" type="image" src="/include/sharing/images/btn_send.png" width="45" height="17" border="0" alt="send" class="etof_submit_btn" /><img src="/include/sharing/images/btn_cancel.png" width="59" height="17" border="0" alt="cancel" class="etof_cancel_btn" onclick="javascript:document.forms[\'form_etof\'].reset();closeShareMod(\'email\');" /></div></form></div><div id="etof_form_success"><p>An email has been sent to your friend.</p></div></td></tr></table></div></div>';
		
		if (document.getElementById('flashcontent')) {
			document.getElementById('flashcontent').style.visibility = 'hidden';
		}
		
		new Element('div', { 'id':'shareOverlay','styles':{ 'opacity':0,'visibility':'visible','height':0,'overflow':'hidden' }}).inject($(document.body));
		$('shareOverlay').setStyles({ 'top': -$(window).getScroll().y,'height':$(window).getScrollSize().y+$(window).getScroll().y });
		//$('shareOverlay').tween('opacity', 0.7);
		$('shareOverlay').set('opacity', 0.7);
		
		window.addEvent('resize',function(){
			if($('shareOverlay').getStyle('opacity') == 0){ return; };
			var scrollSize = $(window).getScrollSize().y;
			var scrollTop = $(window).getScroll().y;
			$('shareOverlay').setStyles({ 'height':scrollSize+scrollTop,'top':-scrollTop });
		}.bindWithEvent(this));
		
		var div_popup = document.createElement('div');
		div_popup.className = 'email_popup';
		div_popup.id = 'divEmailPopup';
		document.body.appendChild(div_popup);
		
		document.getElementById('divEmailPopup').innerHTML = inner_html;
		document.getElementById('share_container_email').style.display = 'block';
		document.getElementById('divEmailPopup').appendChild(document.getElementById('share_container_email'));
		
		// add recaptcha form element
		document.getElementById('recaptcha_code').style.display = 'block';
		newRecaptcha();
		
		$('form_etof').addEvent('submit', function(e) {
			// prevent the submit event
			new Event(e).stop();
			var sender = new Request();
			sender.onSuccess = function(responseText, responseXML) {
				if (responseText == "sent") {
					document.forms['form_etof'].reset();
					$('etof_form_intro').style.display = 'none';
					$('etof_form_container').style.display = 'none';
					$('etof_form_success').style.display = 'block';
					sharingAnalytics("email", "");
				} else {
					newRecaptcha();
					alert(responseText);
				}
			};
			sender.send({data: this, url: this.get('action')});
		});
		
		
		var kill_overlay = function(){ closeShareMod('email'); }
		
		$('shareOverlay').addEvent('click', kill_overlay);
		 
		$('divEmailPopup').addEvent('mouseover', function(){
			$('shareOverlay').removeEvent('click', kill_overlay);
		});
		
		$('divEmailPopup').addEvent('mouseout', function(){
			$('shareOverlay').addEvent('click', kill_overlay);
		});

	
	} else if (type == "social") {
		
		var inner_html = '<div id="share_container_social"><div class="share_container_content"><div class="share_container_headspace"><div id="share_container_close" onclick="javascript:closeShareMod(\'social\');"></div></div><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td nowrap="nowrap"><h1 class="sharing_header">Share</h1></td><td>&nbsp;</td><td class="sharing_hash" width="100%">&nbsp;</td><td width="15"><img src="/images/blank.gif" width="15" height="1"></td></tr></table><table cellpadding="0" cellspacing="0" border="0"><tr><td><ul class="share_list"><li><a target="_blank" href="http://twitter.com/home" onclick="window.open(\'http://twitter.com/home?status=Currently browsing: '+encodeURIComponent(location.href)+'\'); sharingAnalytics(\'social\', \'twitter\'); return false;"><img src="/include/sharing/images/icon_twitter.png" width="16" height="16" border="0" alt="twitter" /> Twitter</a></li><li><a target="_blank" href="http://digg.com/submit" onclick="window.open(\'http://digg.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&bodytext=&media=NEWS&topic=general_sciences\'); sharingAnalytics(\'social\', \'digg\'); return false;"><img src="/include/sharing/images/icon_digg.png" width="16" height="16" border="0" alt="digg" /> Digg</a></li><li><a target="_blank" href="http://www.google.com/bookmarks/mark" onclick="window.open(\'http://www.google.com/bookmarks/mark?op=add&bkmk='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'\'); sharingAnalytics(\'social\', \'google\'); return false;"><img src="/include/sharing/images/icon_google.png" width="16" height="16" border="0" alt="google" /> Google</a></li><li><a target="_blank" href="http://delicious.com/save" onclick="window.open(\'http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title)+'\'); sharingAnalytics(\'social\', \'delicious\'); return false;"><img src="/include/sharing/images/icon_delicious.png" width="16" height="16" border="0" alt="delicious" /> Delicious</a></li><li><a target="_blank" href="http://www.linkedin.com/shareArticle" onclick="window.open(\'http://www.linkedin.com/shareArticle?mini=true&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&ro=false&summary=&source=\'); sharingAnalytics(\'social\', \'linkedin\'); return false;"><img src="/include/sharing/images/icon_linkedin.png" width="16" height="16" border="0" alt="linkedin" /> LinkedIn</a></li><li><a target="_blank" href="http://www.facebook.com/sharer.php" onclick="window.open(\'http://www.facebook.com/sharer.php?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title)+'\'); sharingAnalytics(\'social\', \'facebook\'); return false;"><img src="/include/sharing/images/icon_facebook.png" width="16" height="16" border="0" alt="facebook" /> Facebook</a></li><li><a target="_blank" href="http://technorati.com/faves" onclick="window.open(\'http://technorati.com/faves?add='+encodeURIComponent(location.href)+'\'); sharingAnalytics(\'social\', \'technorati\'); return false;"><img src="/include/sharing/images/icon_technorati.png" width="16" height="16" border="0" alt="technorati" /> Technorati</a></li><li><a target="_blank" href="http://stumbleupon.com/submit" onclick="window.open(\'http://www.stumbleupon.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'\'); sharingAnalytics(\'social\', \'stumbleupon\'); return false;"><img src="/include/sharing/images/icon_stumbleupon.png" width="16" height="16" border="0" alt="stumbleupon" /> StumbleUpon</a></li></ul><td></tr></table></div></div>';
		
		if (document.getElementById('flashcontent')) {
			document.getElementById('flashcontent').style.visibility = 'hidden';
		}
		
		new Element('div', { 'id':'shareOverlay','styles':{ 'opacity':0,'visibility':'visible','height':0,'overflow':'hidden' }}).inject($(document.body));
		$('shareOverlay').setStyles({ 'top': -$(window).getScroll().y,'height':$(window).getScrollSize().y+$(window).getScroll().y });
		//$('shareOverlay').tween('opacity', 0.7);
		$('shareOverlay').set('opacity', 0.7);
		
		window.addEvent('resize',function(){
			if($('shareOverlay').getStyle('opacity') == 0){ return; };
			var scrollSize = $(window).getScrollSize().y;
			var scrollTop = $(window).getScroll().y;
			$('shareOverlay').setStyles({ 'height':scrollSize+scrollTop,'top':-scrollTop });
		}.bindWithEvent(this));
		
		var div_popup = document.createElement('div');
		div_popup.className = 'social_popup';
		div_popup.id = 'divSocialPopup';
		document.body.appendChild(div_popup);
		
		document.getElementById('divSocialPopup').innerHTML = inner_html;
		document.getElementById('share_container_social').style.display = 'block';
		document.getElementById('divSocialPopup').appendChild(document.getElementById('share_container_social'));
		
		
		var kill_overlay = function(){ closeShareMod('social'); }
		
		$('shareOverlay').addEvent('click', kill_overlay);
		 
		$('divSocialPopup').addEvent('mouseover', function(){
			$('shareOverlay').removeEvent('click', kill_overlay);
		});
		
		$('divSocialPopup').addEvent('mouseout', function(){
			$('shareOverlay').addEvent('click', kill_overlay);
		});
		
	}
	
}

function closeShareMod(type) {
	
	if (type == "email") {
		
		if (document.getElementById('flashcontent')) {
			document.getElementById('flashcontent').style.visibility = 'visible';
		}
		
		// remove recaptcha form element
		document.getElementById('recaptcha_code').style.display = 'none';
		Recaptcha.destroy();
		
		document.getElementById('share_container_email').style.display = 'none';
		document.getElementById('divEmailPopup').removeChild(document.getElementById('share_container_email'));
		document.body.removeChild(document.getElementById('divEmailPopup'));
		document.body.removeChild(document.getElementById('shareOverlay'));
		
	} else if (type == "social") {
		
		if (document.getElementById('flashcontent')) {
			document.getElementById('flashcontent').style.visibility = 'visible';
		}
		
		document.getElementById('share_container_social').style.display = 'none';
		document.getElementById('divSocialPopup').removeChild(document.getElementById('share_container_social'));
		document.body.removeChild(document.getElementById('divSocialPopup'));
		document.body.removeChild(document.getElementById('shareOverlay'));
	
	}

}


function sharingAnalytics(type, social_network) {
	
	if (type == "email") {
	
		// access log data
		var sharing_img = new Image;
		sharing_img.src = '/include/sharing/images/tracking.gif?sharing_type=email&url='+location.href;
		
		// google analytics data
		pageTracker._trackEvent('share_page_by_email', location.href);
		
		
	} else if (type == "social") {
		
		// access log data
		var sharing_img = new Image;
		sharing_img.src = '/include/sharing/images/tracking.gif?sharing_type=social&social_network='+social_network+'&url='+location.href;
		
		// google analytics data
		pageTracker._trackEvent('share_page_by_social_network', social_network, location.href);
	
	}

}