$(function() {
		
	$('.matches-calendar-navi a').live('click', function() {
		$.ajax({
			url: $(this).attr('href'),
			success: function(r) {
				$('#matches-calendar').replaceWith(r);
			}
		});
    	return false;
    });
    
    var scrollerTimeout = setTimeout(function() {
		$('#splash .splash-navi.splash-next').click();
	}, 5000);
    
	$('#splash .banners-scroller').each(function() {
    	var total_width = 460 * $(this).find('.banners-scroller-item').length;
    	$(this).width(total_width);
    });
	
    $('#splash .splash-navi').click(function() {
    		
    	clearTimeout(scrollerTimeout);
    	scrollerTimeout = setTimeout(function() {
    		$('#splash .splash-navi.splash-next').click();
    	}, 5000);
    	
    	var $context = $(this).closest('#splash');
		var dir = $(this).hasClass('splash-prev') ? 1 : -1;
		var $items = $context.find('.banners-scroller');
		var distance = $items.find('.banners-scroller-item').first().outerWidth();
		
		if($context.data('animating') !== true) { 
			
			$context.data('animating', true);
			
			if(dir == 1) {
				
				$items.find('.banners-scroller-item').last().prependTo($items);
				$items.css({
					marginLeft: -1 * distance
				}).animate({
					marginLeft: 0
				}, 500, function() {
					$context.data('animating', false);
				});
				
			} else {
				
				$items.animate({
					marginLeft: -1 * distance
				}, 500, function() {
					$items.find('.banners-scroller-item').first().appendTo($items);
					$items.css({
						marginLeft: 0
					});
					$context.data('animating', false);
				});
			}
		}
		
    	return false;
    });
});

