$(document).ready(function() {
	var width = $('.displayNews .contents').width();
	var height = $('.displayNews .contents').height();

	$('.displayNews .contents').wrapInner('<div class="wrapper"/>');
	$('.displayNews .contents .entry').each(function() {
		$(this).width(width);
		$(this).height(height);
	});

	$('.displayNews .item').mouseenter(function(e) {
		var iElement = $(e.currentTarget);
		var gotoIndex = $(this).index();
		$('.displayNews').stopTime();
		$('.displayNews').oneTime(250, function() { 
			goToNews(gotoIndex, iElement);
		});
	});

	$('.displayNews .item').mouseleave(function() {
		$('.displayNews').stopTime();
	});

	function goToNews(index, element) {
		var sElement = element.find(".selected");

		sElement.fadeIn(250);
		$('.displayNews .item').not(':eq('+element.index()+')').find('.selected').stop().fadeOut(250);

		var marginLeftValue = -(index * (width + 15) );
		$('.displayNews .contents .wrapper').stop().animate({
			marginLeft: marginLeftValue
		}, 1000);
	}
});
