$(function() {
	$('ul#uutiset li a').click(function() {
		$('div#newsContainer').fadeOut(function() {
			$(this).remove();
		});
		var id = $(this).attr('id').replace('news_', '');
		var title = $(this).html();
		var left = $(this).offset().left;
		var top = $(this).offset().top;
		
		$.ajax({
			url: BASE_DIR+'etusivu/getNewsItem/',
			type: 'POST',
			data: 'id='+id,
			success: function(response) {
				$p		= $(document.createElement('p')).html(response.replace(/\r\n|\r|\n/g, '<br />'));
				$a		= $(document.createElement('a')).attr('href', '#').html('Sulje');
				$h		= $(document.createElement('h2')).html(title).prepend($a);
				
				$div	= $(document.createElement('div')).attr('id', 'newsContainer').append($h).append($p).css({
							left: (left - 490) +'px',
							top: top +'px'
						}).hide();
				
				$('body').append($div);
				$div.fadeIn();
				
				$a.click(function() {
					$div.fadeOut(function() {
						$div.remove();
					});
					return false;
				});
			}
		});
		
		return false;
	});
});
