$(document).ready(function() {
	//$('a#close-toolbar').corner('6px');
	//$('.share .options a').corner('3px');
  $(document).applySharingEventHandlers();
	
	var mouseisover = false; // we need to check this after a delay to see if user has mouseover'd again
	
	$('#panel').animate({opacity: 1.0}, 2000, function() {
		if (!mouseisover) { $(this).hide('fast'); }
	});
	
	$('#toolbar-left').hover(
		function() {
			mouseisover = true;
			$('#panel').show('fast');
		},
		function() {
			mouseisover = false;
			$('#panel').animate({opacity: 1.0}, 1000, function() {
				if (!mouseisover) { $(this).hide('fast'); }
			});
		}
	);
});

$.fn.applySharingEventHandlers = function(o) {

  this.each(function(index){
    $('.share a.twitter_referral_link', this).click(function() {
      $(this).parents('.share').find('.twitter_referral').show();
      $(this).parents('.share').find('.email_referral').hide();
      $(this).parents('.share').find('.email_referral_link').removeClass('selected'); // reset current selected
      $(this).addClass('selected');
    });

    $('.share a.email_referral_link', this).click(function() {
      $(this).parents('.share').find('.twitter_referral').hide();
      $(this).parents('.share').find('.email_referral').show();
      $(this).parents('.share').find('.twitter_referral_link').removeClass('selected'); // reset current selected
      $(this).addClass('selected');
    });

    $('.share a.facebook_referral_link', this).click(function() {
      window.open(this.href,'sharer','toolbar=0,status=0,width=570,height=370');
      $('#share-outer').slideToggle('normal');
      return false;
    });

  });
  return this;
}
