$(document).ready(function() {

	//grab all the anchor tag with rel set to diggit
	$('a[rel=diggit], #diggit-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) - ($('#diggit-box').width() / 2);	

		// EDIT: piilotetaan muut boksit
		$("#shareit-box").hide();
		$("#commentit-box").hide();

		// EDIT: fiksattu vähän koordinaatteja by Juha
		left = left + 180;
		top = top - 88;
		
		//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 = encodeURIComponent(value[0]);
		var title = encodeURIComponent(value[1]);
		
		//assign the height for the header, so that the link is cover
		$('#diggit-header').height(height);
		
		//display the box
		$('#diggit-box').show();
		
		//set the position, the box should appear under the link and centered
		$('#diggit-box').css({'top':top, 'left':left});
		
		//assign the url to the textfield
		$('#diggit-field').val(field);
			
	});

	//onmouse out hide the diggit box
	$('#diggit-box').mouseleave(function () {
		$('#diggit-field').val('');
		$(this).hide();
	});
	

});