jQuery(document).ready(function () {
	if (($div = jQuery('#mannAd')).length > 0) {
		initMannAd($div);		
	}
	
        setTimeout(function() {
                jQuery('.pinZyxFs.fixed').addClass('ready');
        }, 3000);

});

function initMannAd($div) {
	var $btn = $div.find('.btn');
	
	$btn.click(function() {
		var $carousel = $div.find('.carousel');
		var $firstItem = $carousel.find('li:first-child');
		var itemWidth = $firstItem.outerWidth();
		var itemsCount = $carousel.data('itemsCount');

		if (itemsCount < 4) {
			return false;
		}
		
		$carousel.data().offset++;

		var offset = $carousel.data('offset');
		var $marginLeft = -(offset * itemWidth);

		if (offset == itemsCount - 2) {
			$carousel.data().offset = 0;
			$marginLeft = 0;
		}
		
		$firstItem.css('margin-left', $marginLeft);
	});

	function scroll() {
		$btn.click();
	}

	var scrollIntervalId = setInterval(scroll, 5000);

	$div.on({
		mouseenter: function() {
			clearInterval(scrollIntervalId);
		},
		mouseleave: function() {
			scrollIntervalId = setInterval(scroll, 5000);
		},
	});
}
