var current = 0;
var interval = null;
var buttons = null;

var rotate = function() {
    if (current == $('#splash-carousel > li').size()-1) {
        current = 0
    } else {
        current++;
    }
    $('#splash-carousel > li').fadeOut('slow')
    $('#splash-carousel > li:eq('+current+')').fadeIn('slow')
	$(buttons).removeClass('active');
	$(".teaserLinks a:eq("+current+")").addClass('active');
}
var rotateBack = function() {
    if (current == 0) {
        current = $('#splash-carousel > li').size()-1
    } else {
        current--;
    }
    $('#splash-carousel > li').fadeOut('slow')
    $('#splash-carousel > li:eq('+current+')').fadeIn('slow')
	$(buttons).removeClass('active');
	$(".teaserLinks a:eq("+current+")").addClass('active');
}
// rotate to a specific slide
var rotateTo = function(num) {
	current = parseInt(num);
    $('#splash-carousel > li').fadeOut('slow')
    $('#splash-carousel > li:eq('+current+')').fadeIn('slow')
}
jQuery(document).ready(function() {
	buttons = $(".teaserLinks a");
	$(buttons[0]).addClass('active');
	$(buttons).bind('click', function(e) {
	 	e.preventDefault();
        clearInterval(interval);
		var split = this.id.split("");
		var num = parseInt(split[split.length-1]) - 1;
		rotateTo(num);
		$(buttons).removeClass('active');
		$(this).addClass('active');
	});
    $('#prev-slide').bind('click', function() {
        clearInterval(interval);
        rotateBack();
    });
    $('#next-slide').bind('click', function() {
        clearInterval(interval);
        rotate();
    });
    interval = setInterval('rotate()', 6000);
});
