// hero.jquery.js

var refreshIntervalID = 0;
var pause = 5000;
var length;

var newFrame = 1;

$(document).ready( function () {
	
	length = $('.image').length;
	
	$('#hero-controls li a').click( function (e) {
		clearInterval(refreshIntervalID);
		var currentID = parseInt($(this).parent().attr('id').substr(3, 1));
		show(currentID);
		e.preventDefault();
		startTimer();
	});
	
	startTimer();
	
});

this.startTimer = function () {
	refreshIntervalID = setInterval(rotate,pause);
}

this.rotate = function () {
	var currentID = parseInt($('.current-image').attr('id').substr(5, 1));
	if( currentID == 3 ) { currentID = 0; }
	show( currentID + 1 );
}

this.show = function (id) {
	$('.current-image').removeClass('current-image').fadeOut(500, function () {
		$('#image' + id).fadeIn(500).addClass('current-image');
		$('li.current-item').removeClass('current-item');
		$('li#img' + id).addClass('current-item');
	});
}
