/**
*	File: newsPager.js
*
*	Author: Matthew Lindley, GForces Web Management: www.gforces.co.uk
*	Purpose: House most of the custom javascript for the Hills Ford website
*
*/

/****************************************
*	News pager
****************************************/

var newsPager = {

	currentIndex: 0,

	init: function ( element ) {

		this.pages = $$( '#' + $(element).id + ' div.newsItem' );

		$('newsGoBack').observe( 'click', function ( ev ) {

			Event.stop( ev );

			this.goBack();

		}.bind( this ));


		$('newsGoNext').observe( 'click', function ( ev ) {

			Event.stop( ev );

			this.goNext();

		}.bind( this ));


	},


	goBack: function () {

		this.pages[ this.currentIndex ].hide();

		if ( this.currentIndex == 0 ) {
			this.currentIndex = this.pages.length - 1;
		} else {
			this.currentIndex--;
		}

		this.pages[ this.currentIndex ].show();

		$('newsCurrentItem').update( this.currentIndex + 1 );

	},


	goNext: function () {

		this.pages[ this.currentIndex ].hide();

		if ( this.currentIndex == this.pages.length - 1 ) {
			this.currentIndex = 0;
		} else {
			this.currentIndex++;
		}

		this.pages[ this.currentIndex ].show();

		$('newsCurrentItem').update( this.currentIndex + 1 );

	}
}
