$(function() {
	var w = 1025 - 45 * $("#bayan .slide").length;
		
	$("#bayan .slide").each(function(i){
		$(this).css('left', i * 45);
		$(this).css('width', w);
		$(this).data('left_pos', i * 45);
		$(this).data('right_pos', i * 45 + w - 45);
	});
	
	$("#bayan .tab").click(function(){
		if ( $(this).data('timer') ) {
			$(this).removeData('timer');
		} else {
			window.clearInterval(timer);
		}
		$(this).parent().addClass('on').animate({
			left: $(this).parent().data('left_pos')
		}, {
			queue: false
		});

		$(this).parent().prevAll().removeClass('on').each(function(){
			$(this).animate({
				left: $(this).data('left_pos')
			}, {
				queue: false
			});
		});

		$(this).parent().nextAll().removeClass('on').each(function(){
			$(this).animate({
				left: $(this).data('right_pos')
			}, {
				queue: false
			});
		});

		return false;
	});
	
	$("#bayan .slide:first .tab").click();
	
	var timer = window.setInterval(function(){
		if ( $("#bayan .slide.on").next()[0] ) {
			$("#bayan .slide.on").next().children(".tab").data('timer', true).click();
		} else {
			$("#bayan .slide:first .tab").data('timer', true).click();
		}
	}, 5000);
});

