var Books = new function() {
	this.LEFT = 0;
	this.RIGHT = 1;

	this._data = [];
	this._itemWidth = 0;
	this._rootWidth = 0;
	this._maxWidth = 0;

	this._direction = this.RIGHT;

	this._paused = false;
	this._interval = null;

	this.auto = function()
	{
		if(!this._paused && this._interval == null)
			this._interval = setTimeout('Books.'+(this._direction == this.RIGHT ? 'next' : 'prev' )+'()',12000);
	};

	this._clear = function()
	{
		if(null != this._interval)
			clearInterval(this._interval);
		this._interval = null;
	};

	this.prev = function()
	{
		this._data = $('#books .container .item');
		this._direction = this.LEFT;

		this._data.last().css('marginLeft',-1*this._itemWidth);
		this._data.last().prependTo(this._data.first().parent());
		this._data.last().animate( { marginLeft: 0 }, 600, 'swing' );
		this._clear();
		this.auto();
	};

	this.next = function()
	{
		this._data = $('#books .container .item');
		this._direction = this.RIGHT;

		this._data.first().animate( { marginLeft:-1*this._itemWidth }, 600, 'swing',
			function(){
				$(this).appendTo($(this).parent());
				$(this).css('marginLeft','');
			}
		);
		this._clear();
		this.auto();
	};

	this.pause = function()
	{
		this._clear();
		this._paused = !this._paused;
		this.auto();
	};

	this.init = function(sJQPath,iRootWidth)
	{
		this._sJQPath = sJQPath;
		this._data = $('#books .container .item');
		this._itemWidth = this._data.first().outerWidth();
		this._rootWidth = $('#books').outerWidth();
		this._maxWidth = this._data.length*this._itemWidth;

		if(this._rootWidth<this._maxWidth)
		{
			$('#books .controlls').show();
			$('#books .controlls .prev').bind('click',function(){ Books._paused = false; Books.prev(); });
			$('#books .controlls .pause').bind('click',function(){ Books.pause(); });
			$('#books .controlls .next').bind('click',function(){ Books._paused = false; Books.next(); });
			this.auto();
		};
	};
};

