
// Keep track
var currentShelf = 1;
var total = 0;

// Get ID
function parseId(id) {return id.substr(id.lastIndexOf("-")+1);}


// General on page load functionality
jQuery(document).ready(function(){
		
});

/* Determine if arrows are to be shown or not*/
function refreshArrows() {

	// Left arrow
	if (currentShelf == 1) jQuery('#leftarrow').fadeOut(400);
	else jQuery('#leftarrow').fadeIn(600);

	// Right arrow
	if (currentShelf == total) jQuery('#rightarrow').fadeOut(400);
	else jQuery('#rightarrow').fadeIn(600);

}

/* Control bookshelf */
function bookshelf() {
	
	currentShelf = 1;
	total = jQuery('.shelf').size();

	jQuery('#leftarrow').hide();
		
	// Left arrow
	jQuery('#leftarrow').click(function() {
		
		// Stay within limit
		if (currentShelf > 1) {
			currentShelf --;
			showShelf();
		}
	});


	// Right arrow
	jQuery('#rightarrow').click(function() {								 
		
		// Stay within limit
		if (currentShelf < total) {
			currentShelf ++;
			showShelf();
		}
	});
	
}

/* Show currrent shelf */
function showShelf() {

	// Hide all first
	jQuery('.shelf').hide();
	
	// Show current
	jQuery('#shelf-'+currentShelf).fadeIn(300);
	
	refreshArrows();
}

