var tp;

//10000=10秒
var changeTime = 5000;


$(function() {
//	$('#eyecatch .bg').css('opacity', '0.75');
	$('#eyecatch .textWrapper li:eq(0)').show();
	
	$('#eyecatch .paginate li a').each(function(index) {
		$(this).click(function() {
			changeEyecatch(index);
		});
	});
	
	startChangeEyecatch(1);
});

function startChangeEyecatch(index) {
	tp = setTimeout("changeEyecatch('" + index + "')", changeTime);
}

function changeEyecatch(index) {
	$('#eyecatch .textWrapper li').hide();
	var on_image = $('#eyecatch .paginate li a[@class*="selectedRecommend"] img').get();
	if(on_image[0].src.match(/.+_on\.(gif|jpg|jpe|jpeg|png)/)) {
		on_image[0].src = on_image[0].src.replace(/(.+)_on(\.(gif|jpg|jpe|jpeg|png))/, '$1$2');
	}
	
	$('#eyecatch .paginate li a').removeClass('selectedRecommend');
	
	$('#eyecatch .imageWrapper ul').animate({left:-910 * index}, 'slow');
	$('#eyecatch .textWrapper li:eq(' + index + ')').fadeIn();
	$('#eyecatch .paginate li:eq(' + index + ') img').attr('src', 'images/top/paginate_'+(parseInt(index)+1)+'_on.gif');

	$('#eyecatch .paginate li:eq(' + index + ')').children('a').addClass('selectedRecommend');

	clearTimeout(tp);
	
	if(index < $('#eyecatch .textWrapper li').size() - 1) {
		startChangeEyecatch(parseInt(index) + 1);
	} else {
		startChangeEyecatch(0);
	}
}

