/**
 * The main class that is responsible for pagination
 * and other activities in the Search Results page
 */
var BookSearch =
{
	init : function()
	{
		var searchResultDiv = document.getElementById("searchResults");
		
		ListDisplay.displayFunction = BookSearch.displayBooks;
		ListDisplay.init(searchResults[0], searchResultDiv);
	},
	
	/**
	 * This is the function that returns the HTML for an individual book atom
	 * @param {Object} bookItem
	 */
	displayBooks : function(bookItem)
	{
		var bookHTML = BOOK_ATOM_HTML.replace(/_BOOK_TITLE_/g,bookItem.title);
		bookHTML = bookHTML.replace(/_BOOK_BINDINGTYPE_/g, bookItem.bindingType);
		bookHTML = bookHTML.replace(/_BOOK_ID_/g, bookItem.id);

		var authorHtml = "";
		for(var i in bookItem.authorList)
		{
			authorHtml += bookItem.authorList[i] + "<br/>";
		}
	
		bookHTML = bookHTML.replace(/_BOOK_AUTHOR_/g, authorHtml);
		bookHTML = bookHTML.replace(/_BOOK_PUBLISHER_/g, bookItem.publisher);
		bookHTML = bookHTML.replace(/_BOOK_ISBN_/g, bookItem.isbn);
		
		if (bookItem.mediumImageUrl == "")
		{
			bookItem.mediumImageUrl = "../img/noImage.jpg";
		}
		
		bookHTML = bookHTML.replace(/_BOOK_SRC_/g, bookItem.mediumImageUrl);
		
		
		bookHTML += "<div class = 'empty-div'></div>"
	
		if (ShoppingCart.isInCart(bookItem.id))
		{
			bookHTML = bookHTML.replace("/cart.gif", "/cart_added.gif");
			bookHTML = bookHTML.replace("'javascript:ShoppingCart.addItems(\"" + bookItem.id + "\")'", "'#' style = \"cursor:default\"");
		}
		bookHTML = bookHTML.replace(/\${appBase}/g,APP_BASE);
		return bookHTML;
	}
}

BookSearch.init();