﻿var $j = jQuery.noConflict();
$j(function () {

	//grab all the anchor tag with rel set to shareit
	$j('a[rel=shareit]').mouseenter(function() {		
		
		//get the height, top and calculate the left value for the sharebox
		var height = $j(this).height();
		var top = $j(this).offset().top;
		
		//get the left and find the center value
		var left = $j(this).offset().left + ($j(this).width() /2) - ($j('#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 = $j(this).attr('title').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
		$j('#shareit-header').height(height);
		
		//display the box
		$j('#shareit-box').show();
		
		//set the position, the box should appear under the link and centered
		$j('#shareit-box').css({'top':top, 'left':left});
		
		//assign the url to the textfield
		$j('#shareit-field').val(field);
		
		//make the bookmark media open in new tab/window
		$j('a.shareit-sm').attr('target','_self');
		
		//Setup the bookmark media url and title
		$j('a[rel=shareit-mail]').attr('href', 'mailto: ?Subject=Organdonor.gov&body=Check out this web page: ' + url + '&amp;title=' + title);
		$j('a[rel=shareit-delicious]').attr('href', 'http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=' + url + '&amp;title=' + title);
		$j('a[rel=shareit-facebook]').attr('href', 'http://www.facebook.com/share.php?u=' + url + '&amp;title=' + title);
		$j('a[rel=shareit-digg]').attr('href', 'http://digg.com/submit?phase=2&amp;url=' + url + '&amp;title=' + title);
		$j('a[rel=shareit-stumbleupon]').attr('href', 'http://www.stumbleupon.com/submit?url=' + url + '&title=' + title);
		$j('a[rel=shareit-twitter]').attr('href', 'http://twitter.com/home?status=StopTheBettle.info | ' + url + '&amp;title=' + title);
		
	});

	//onmouse out hide the shareit box
	$j('#shareit-box').mouseleave(function () {
		$j('#shareit-field').val('');
		$j(this).hide();
	});
	
	//hightlight the textfield on click event
	$j('#shareit-field').click(function () {
		$j(this).select();
	});
});


