var pages_home_timeout;

function pages_home(size) {
	clearTimeout(pages_home_timeout);
	pages_home_timeout = setTimeout(function() {
		$('#pages_home').each(function() {
			$(this).find('div.aba').eq(($(this).find('div.aba-click').index() + 1) % size).click();
		});
		pages_home(size);
	}, 10000);
}

$(document).ready(function() {
	$('#pages_home').each(function() {
		var size = $(this).find('div.aa').children().size();
		$(this).find('div.aa').each(function() {
			$(this).css('width', $(this).width() * size + 'px');
		});
		if(size > 1) {
			for(var i = 0; i < size; i++) {
				$(this).find('div.ab').append('<div class="aba"></div>');
			}
		}
		$(this).find('div.aba').each(function() {
			$(this).hover(function() {
				$(this).addClass('aba-hover');
			}, function() {
				$(this).removeClass('aba-hover');
			});
			$(this).click(function() {
				$(this).siblings('div.aba-click').removeClass('aba-click');
				$(this).addClass('aba-click');
				$(this).parent().siblings('div.aa').animate( {
					left: $(this).parent().parent().width() * $(this).index() * -1 + 'px'
				}, 'slow', pages_home(size));
			});
		});
		$(this).find('div.aba').eq(0).click();
	});
});
