$(function(){
	//var random = Math.floor($('#toggles li').length * Math.random());
	$('#toggles li').eq(0).addClass('active');
	$('#features_slides .slide').hide();
	$($('#toggles li.active a').attr('href')).show();
	$('#toggles li a').click(function() {
		__stop_slides();
		__change_slide(this);
		return false;
	});
	setTimeout("__next_slide()",timeout);
});

var timeout = 6000;
var clicked = false;

function __stop_slides()
{
	clicked = true;
}

function __change_slide(el)
{
	var activeSlide = $($('#toggles li.active a').attr('href'));
	$('#toggles li.active a').click(function() {
		__change_slide(this);
		return false;
	}).parent().removeClass('active');
	$(el).unbind('click').click(function(){ return false; }).parent().addClass('active');
	activeSlide.fadeOut("slow", function() {
		$($('#toggles li.active a').attr('href')).fadeIn("slow");
	});
}

function __next_slide()
{
	if (clicked) {
		return false;
	}
	if ($('#toggles li.active').next().length) {
		var next_slide = $('#toggles li.active').next().children();
	} else {
		var next_slide = $('#toggles li:first a');
	}
	__change_slide(next_slide);
	setTimeout("__next_slide()",timeout);
}