jQuery(document).ready(function() {
	jQuery('.social ul').find('li:not(:last)').after('<li>|</li>');
	
	jQuery('.tooltip')
		.tooltip({ showURL: false })
		.click(function() { return false; })
		.find('a')
		.click(function() { return false; });
	
	jQuery('#addthis')
		.hover(
			function() { addthis_open(this, '', '[URL]', '[TITLE]'); },
			function() { addthis_close(); }
		)
		.click(
			function() { return addthis_sendto(); }
		);
		
	
	jQuery('a[href*=#TB_inline]').click(function() {
		jQuery('#result').empty();
		jQuery('#f_share').show();
		jQuery('#f_share_from').focus();
		jQuery('#f_share_bcc').css({display:'inline',textAlign:'left'});
	});
	
	retry = function() {
		jQuery('#result').slideUp();
		jQuery('#f_share').slideDown();
		return false;
	};

	jQuery('#share .submit').click(function() {
		jQuery('#f_share input, #f_share textarea').removeClass('error');
		errors = 0;
		if (!document.forms.f_share.text.value) {
			jQuery('#f_share_text').addClass('error').focus();
			errors++
		}
		if (!document.forms.f_share.subject.value) {
			jQuery('#f_share_subject').addClass('error').focus();
			errors++
		}
		if (!/^([-a-z0-9_\.\+])+@(([-a-z0-9])+\.)+([a-z]{2,6})+$/i.test(document.forms.f_share.to.value)) {
			jQuery('#f_share_to').addClass('error').focus();
			errors++
		}
		if (!/^([-a-z0-9_\.\+])+@(([-a-z0-9])+\.)+([a-z]{2,6})+$/i.test(document.forms.f_share.from.value)) {
			jQuery('#f_share_from').addClass('error').focus();
			errors++
		}
		if (!errors) jQuery.ajax({
			url:      site_w_path +'async/share.php',
			type:     'post',
			data:     {
				'from'    : escape(document.forms.f_share.from.value   ),
				'to'      : escape(document.forms.f_share.to.value     ),
				'subject' : escape(document.forms.f_share.subject.value),
				'text'    : escape(document.forms.f_share.text.value   ),
				'bcc'     : document.forms.f_share.bcc.checked
			},
			timeout: 30000,
			beforeSend: function() {
				jQuery('#f_share').slideUp();
				jQuery('#result').hide().html('<p><img src="'+ w_path + '/img/loading.gif" alt="" /> Please wait&hellip;</p>').slideDown();
			},
			success: function(html) {
				jQuery('#result').hide().html(html).slideDown();
			},
			error: function(html) {
				jQuery('#result').hide().html('<p>An error has occured.</p><p><a href="#" id="retry">Try again</a></p>').slideDown();
				jQuery('#retry').click(retry);
			}
		});
	});

});
