// source: http://www.queness.com/post/309/create-a-digg-style-post-sharing-tool-with-jquery
// with some minor changes.
// icons from: http://www.komodomedia.com



$(document).ready(function() {

	//grab all the anchor tag with rel set to shareit
	$('a[rel=shareit], #shareit-box').mouseover(function() {
		
		//get the height, top and calculate the left value for the sharebox
		var height = $(this).height();
		var top = $(this).offset().top;

		//get the left and find the center value
		var left = $(this).offset().left + ($(this).width() /2) - ($('#shareit-box').width() / 2 + 5);

		//grab the href value and explode the bar symbol to grab the url and title
		//the content should be in this format url|title
		if ( ! $(this).attr('href') )
		{
			return; // stop IE from complaining
		}


		var value = $(this).attr('href').split('|');
		//assign the value to variables and encode it to url friendly
		var field = value[0];
		var url = encodeURIComponent(value[0]);
		var title = encodeURIComponent(value[1]);

		//assign the height for the header, so that the link is cover
		$('#shareit-header').height(height);

		//display the box
		$('#shareit-box').show();

		//set the position, the box should appear under the link and centered
		$('#shareit-box').css({'top':top, 'left':left});

		//assign the url to the textfield
		$('#shareit-field').val(field);

		//make the bookmark media open in new tab/window
		$('a.shareit-sm').attr('target','_blank');

		//Setup the bookmark media url and title
		$('a[rel=shareit-mail]').attr('href', 'mailto:?subject=Watch this segment on ' + title + '&body=I wanted to share this segment with you:%0D%0A' + title +' %0D%0A'+ url);
		$('a[rel=shareit-twitter]').attr('href', 'http://wwww.twitter.com/home?status=' + title + '%20-%20' + url);
		$('a[rel=shareit-facebook]').attr('href', 'http://www.facebook.com/share.php?t=' + title + '&u=' + url);
		$('a[rel=shareit-linkedin]').attr('href', 'http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + title + '&source=wwww.ii3.com');
	});

	$('#topheader, #content_box_video_live, #left_menu, #monday, #tuesday, #wednesday').mouseover(function () {
//	$('#left_menu').mouseover(function () {
		var sharestatus = $('#shareit-box').css('display');	
		if (sharestatus == 'block')
		{ 
			$('#shareit-box').hide(300);
		}
	});


	$('a[rel=shareit]').click(function() {
		return false; // do nothing
	});
	
	//hightlight the textfield on click event
	$('#shareit-field').click(function () {
		$(this).select();
	});
	//hightlight the textfield on click event
	$('#shareit-field').mousedown(function () {
		$(this).select();
	});	
});

function close_share()
{
$('#shareit-box').hide();
}