﻿var curr = 0, next = 0, count = 0;
$(document).ready(function() {	
	count = $('#img_list a').size();	
	
	t = setInterval('imgPlay()', 5000);
	
	$('#imgs li, #img_list a').hover(function() {
		clearInterval(t);
	}, function() {
		t = setInterval('imgPlay()', 5000);
	});
	
	
	$('#img_list a').click(function() {
		var index = $('#img_list a').index(this);
		if(curr != index) {
			play(index);
			curr = index;
		};
		return false;
	});
	
});

var imgPlay = function() {
	next = curr + 1;
	if(curr == count-1) next=0;
	play(next);
	
	curr++;
	if(curr > count-1) { curr=0; next = curr +1; }
};

var play = function(next) {
	$('#imgs li').eq(curr).css({'opacity': '0.5'}).animate({'left': '-280px', 'opacity': '1'}, 'slow', function() {
								 	$(this).css({'left': '270px'});
								 }).end()
							 .eq(next).animate({'left': '0px', 'opacity': '1'}, 'slow', function() {
								 	$('#img_list a').siblings('a').removeClass('active').end().eq(next).addClass('active');
								 });
};
