
var rotate = true;
var current = -1;
var total = 0;
var rotateInterval = 0;
var links;
var currentTitle = '';

$(function() {
	links = $('#features-nav a');
	total = links.length;
	$('#features-nav a').click(function(){
		rotate = false;
		var changed = false;
		for(var i=0; i<total; i++) {
			if (links.get(i) == this) {
				if (current != i) {
					changed = true;
				}
				current = i;
				break;
			}
		}
		if (changed) {
			$('#features-nav a').removeClass('active');
			$(this).addClass('active').blur();
			if (total > 1) {
				$('#features .feature').fadeOut('slow');
			}
      $('#features .feature').eq(current).fadeIn('slow');
		}
	});
	rotate_feature();
	rotateInterval = window.setInterval(rotate_feature, (7000));
});


function rotate_feature(){
  if(rotate){
    if(current == total - 1) {
      current = 0;
      rotate = true;
    } else {
    	current++;
    }
    $('#features-nav a').removeClass('active');
    $('#features-nav a').eq(current).addClass('active').blur();
    if (total > 1) {
    	$('#features .feature').fadeOut('slow');
    }
    $('#features .feature').eq(current).fadeIn('slow');
  } else{
    clearInterval(rotateInterval);
  }
}

