$(document).ready( function(){

	//Animate the portfolio to the left
	$('.first-slide-button img').click( function(){ slideFirst() });

	//Animate the portfolio to the middle
	$('.second-slide-button img').click( function(){ slideMiddle() });

	//Animate the portfolio to the right
	$('.third-slide-button img').click( function(){ slideLast() });

	$('.first-slide-button img').trigger('click');
});

//Show the next protfolio items and animate them with a slide effect
//Using element position
function slideFirst() {
	slidePager( 'first' );
	$( '#home-slider' ).animate({ left: 0 }, 500, function() {
		clearInterval($.l_oFirstInterval);
		clearInterval($.l_oSecondInterval);
		clearInterval($.l_oThirdInterval);
		$.l_oSecondInterval = setInterval(function() {
			$('.second-slide-button img').trigger('click');
   		}, 3000);
	});
}

function slideMiddle() {
	slidePager( 'second' );
	$( '#home-slider' ).animate({ left: '-'+700 }, 500, function() {
		clearInterval($.l_oFirstInterval);
		clearInterval($.l_oSecondInterval);
		clearInterval($.l_oThirdInterval);
		$.l_oThirdInterval = setInterval(function() {
			$('.third-slide-button img').trigger('click');
   		}, 3000);

	});

}

//Show the next previous items and animate them with a slide effect
//Using element position
function slideLast() {
	slidePager( 'third' );
	$( '#home-slider' ).animate({ left: '-'+1400 }, 500, function() {
		clearInterval($.l_oFirstInterval);
		clearInterval($.l_oSecondInterval);
		clearInterval($.l_oThirdInterval);
		$.l_oFirstInterval = setInterval(function() {
			$('.first-slide-button img').trigger('click');
   		}, 3000);
	});
}

function slidePager( p_sSlide )
{	
	$('.slide-controls li').removeClass('active-slide');
	
	if( p_sSlide == 'first')
	{
		$('.first-slide-button').addClass('active-slide');
		$('.first-slide-button img').attr('src','images/active-slide-block.gif');
		$('.second-slide-button img').attr('src','images/slide-block.gif');
		$('.third-slide-button img').attr('src','images/slide-block.gif');
	}
	else if( p_sSlide == 'second')
	{
		$('.second-slide-button').addClass('active-slide');
		$('.first-slide-button img').attr('src','images/slide-block.gif');
		$('.second-slide-button img').attr('src','images/active-slide-block.gif');
		$('.third-slide-button img').attr('src','images/slide-block.gif');
	}
	else
	{
		$('.third-slide-button').addClass('active-slide');
		$('.first-slide-button img').attr('src','images/slide-block.gif');
		$('.second-slide-button img').attr('src','images/slide-block.gif');
		$('.third-slide-button img').attr('src','images/active-slide-block.gif');
	}
}
