$('.ppt li:gt(0)').hide();
$('.ppt li:last').addClass('last');
$('.ppt li:first').addClass('first');
$('#play').hide();

var cur = $('.ppt li:first');
var interval;

//These are the functions that are used when a user clicks a control
$('#fwd').click( function() {
	goFwdClick();
	showPause();
} );

$('#back').click( function() {
	goBackClick();
	showPause();
} );

$('#stop').click( function() {
	stop();
	showPlay();
} );

$('#play').click( function() {
	start();
	showPause();
} );


//This function moves the tile forward constantly with fade
function goFwd() {
	stop();
	forward();
	start();
}

//This function moves the tile forward quickly when user clicks the forward button
function goFwdClick() {
	stop();
	forwardClick();
	start();
}


//This function moves the tile back quickly when user clicks the back button
function goBackClick() {
	stop();
	backClick();
	start();
}


//This states that there is no fade when you click the back button
function backClick() {
	cur.fadeOut( 1 );
	if ( cur.attr('class') == 'first' )
		cur = $('.ppt li:last');
	else
		cur = cur.prev();
	cur.fadeIn( 1 );
}

//This applies the fade for the normal rotation
function forward() {
	cur.fadeOut( 500 );
	if ( cur.attr('class') == 'last' )
		cur = $('.ppt li:first');
	else
		cur = cur.next();
	cur.fadeIn( 500 );
}

//This states that there is no fade when you click the forward button
function forwardClick() {
	cur.fadeOut( 1 );
	if ( cur.attr('class') == 'last' )
		cur = $('.ppt li:first');
	else
		cur = cur.next();
	cur.fadeIn( 1 );
}



function showPause() {
	$('#play').hide();
	$('#stop').show();
}

function showPlay() {
	$('#stop').hide();
	$('#play').show();
}

function start() {
	interval = setInterval( "forward()", 5000 );
}

function stop() {
	clearInterval( interval );
}

$(function() {
	start();
} );
