// JScript source code
attachShareit = function(){

	//grab all the anchor tag with rel set to shareit
	$('a[rel=shareit], #shareit-box').mouseenter(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);
		
		//grab the href value and explode the bar symbol to grab the url and title
		//the content should be in this format url|title
		var value = $(this).attr('href').split('|');
		
		//assign the value to variables and encode it to url friendly
		var field = value[0];
		var url = value[0];
		var title = $(this).attr('title');
		title = title.replace(/ /g, '+');
		
		//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-url')[0].innerHTML = '<strong>Copy & Paste</strong> <br /><br /><a href=' + field + '>' + field + '</a>';
		
		//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=ArvinMeritor - 14X Podcasts&body=' + value[0]);
		$('a[rel=shareit-delicious]').attr('href', 'http://delicious.com/post?url='+url+'&title='+title+'&notes='+url+'+'+'http://www.mpgseries.com/podcasts.aspx');
		$('a[rel=shareit-digg]').attr('href', 'http://digg.com/submit?phase=2&url=http://www.mpgseries.com/podcasts.aspx&title='+title+'&bodytext='+url+'+'+'http://www.mpgseries.com/podcasts.aspx');
		$('a[rel=shareit-twitter]').attr('href', 'http://www.twitter.com/home?status=' + title +'+'+ url+'+'+'http://www.mpgseries.com/podcasts.aspx');
		$('a[rel=shareit-facebook]').attr('href', 'http://www.facebook.com/share.php?u='+url+'&t='+title);
	});
	
	//onmouse out hide the shareit box
	$('#shareit-box').mouseleave(function(){
		$('#shareit-field').val('');
		$(this).hide();
	});
	
	//hightlight the textfield on click event
	$('#shareit-field').click(function(){
		$(this).select();
	});
}
