Epson.TeaserCarousel = function( element )
{
	var _self = this;
	var _carousel = jQuery( element );
	var _next;
	var _previous;
	var _list = _carousel.find( 'ul' );
	var _index = _carousel.find( '.pageIndex' );
	var _pages = 0;

	setup();

	function setup()
	{
		_pages = Math.ceil( _list.find( 'li' ).length / 3 );

		// set up pagination index
		_index.append( '<strong></strong>' );
		for ( var x = 1; x < _pages; x++ ) _index.append( '<span></span>' );

		// set up pagination buttons
		if ( _pages > 1 ) _carousel.find( '.content:first' ).append( '<a href="#" class="prevPagination"></a><a href="#" class="nextPagination"></a>' );
		
		_next = _carousel.find( '.nextPagination' ).bind( 'click', next );
		_previous = _carousel.find( '.prevPagination' ).bind( 'click', previous );
	}

	function next(e)
	{
		var page = Math.abs( parseInt( parseInt( _list.css( 'marginLeft' ) ) / 915 ) );
		var new_page = page < _pages - 1 ? page + 1 : 0;
		var amount = -915 * new_page;

		_list.animate( { marginLeft:amount }, 750, 'swing' );

		_index.find( 'strong' ).replaceWith( '<span></span>' );
		_index.find( 'span:eq( ' + new_page + ' )' ).replaceWith( '<strong></strong>' );

		e.preventDefault();
	}

	function previous(e)
	{
		var page = Math.abs( parseInt( parseInt( _list.css( 'marginLeft' ) ) / 915 ) );
		var new_page = page > 0 ? page - 1 : _pages - 1;
		var amount = -915 * new_page;

		_list.animate( { marginLeft:amount }, 750, 'swing' );

		_index.find( 'strong' ).replaceWith( '<span></span>' );
		_index.find( 'span:eq( ' + new_page + ' )' ).replaceWith( '<strong></strong>' );

		e.preventDefault();
	}
}