// CONSTRUCTOR        
function Book(asin, title, author, publisher, bookSource, bookUrl, bookImageUrl)
{
    this.asin = asin;
    this.title = title;
    this.author = author;
    this.publisher = publisher;
    this.bookSource = bookSource;
    this.url = bookUrl;
    this.imageSource = bookImageUrl;
}


/////////////////////////////
// INSTANCE METHODS        
// (may access the keyword "this")
/////////////////////////////
var DEFAULT_IMAGE_HEIGHT = 200;
var ASSOCIATES_ID = "sfsi0c-20";

function overrideDeafultHeight(newValue)
{
    DEFAULT_IMAGE_HEIGHT = newValue;
}

function _drawBookInTable()
{
    document.writeln("<td class=\"bookSlot\">");
    if (this.bookSource == Book.BOOK_SRC_AMAZON)
    {
        document.writeln("<a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\"><img height=\"" + DEFAULT_IMAGE_HEIGHT + "\" src=\"http://images.amazon.com/images/P/" + this.asin + ".01._SCLZZZZZZZ_SL" + DEFAULT_IMAGE_HEIGHT + "_.jpg\" alt=\"\" border=\"0\" class=\"justBorder\"></a><br>");
        document.writeln("<strong><a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\">" + this.title + "</a></strong><br>");
        document.writeln(this.author + "<br>");
        document.writeln(this.publisher);
    }
    else if (this.bookSource == Book.BOOK_SRC_AMAZON_UK)
    {
        document.writeln("<a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\"><img height=\"" + DEFAULT_IMAGE_HEIGHT + "\" src=\"http://images.amazon.com/images/P/" + this.asin + ".01._SCLZZZZZZZ_SL" + DEFAULT_IMAGE_HEIGHT + "_.jpg\" alt=\"\" border=\"0\" class=\"justBorder\"></a><br>");
        document.writeln("<strong><a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\">" + this.title + "</a></strong><br>");
        document.writeln(this.author + "<br>");
        document.writeln(this.publisher);
    }
    else if (this.bookSource == Book.BOOK_SRC_SFBC)
    {
        document.writeln("<a href=\"http://www.sfbc.com/doc/full_site_enrollment/detail/fse_product_detail.jhtml?repositoryId=" + this.asin + "510\"><img src=\"http://www.sfbc.com/doc/sfc/GlobalData/GlobalImages/BookJacketsLarge/" + this.asin + "_lg.jpg\" alt=\"\" border=\"0\" class=\"justBorder\" style=\"border-width:0\"></a><br>");
        document.writeln("<strong><a href=\"http://www.sfbc.com/doc/full_site_enrollment/detail/fse_product_detail.jhtml?repositoryId=" + this.asin + "510\">" + this.title + "</a></strong><br>");
        document.writeln(this.author + "<br>");
        document.writeln(this.publisher);
    }
    else if (this.bookSource == Book.CD_SRC_AMAZON)
    {
        document.writeln("<a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\"><img src=\"http://images.amazon.com/images/P/" + this.asin + ".01._SCLZZZZZZZ_SL" + DEFAULT_IMAGE_HEIGHT + "_.jpg\" alt=\"\" border=\"0\" class=\"libraryCD\"></a><br>");
        document.writeln("<strong><a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\">" + this.title + "</a></strong><br>");
        document.writeln(this.author + "<br>");
        document.writeln(this.publisher);
    }
    else if (this.bookSource == Book.CD_SRC_AMAZON_NO_BORDER)
    {
        document.writeln("<a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\"><img src=\"http://images.amazon.com/images/P/" + this.asin + ".01._SCLZZZZZZZ_SL" + DEFAULT_IMAGE_HEIGHT + "_.jpg\" alt=\"\" border=\"0\" class=\"libraryCDNoBorder\"></a><br>");
        document.writeln("<strong><a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\">" + this.title + "</a></strong><br>");
        document.writeln(this.author + "<br>");
        document.writeln(this.publisher);
    }
    else if (this.bookSource == Book.BOOK_SRC_OTHER)
    {
        document.writeln("<a href=\"" + this.url + "\"><img src=\"" + this.imageSource + "\" alt=\"\" border=\"0\" class=\"justBorder\"></a><br>");
        document.writeln("<strong><a href=\"" + this.url + "\">" + this.title + "</a></strong><br>");
        document.writeln(this.author + "<br>");
        document.writeln(this.publisher);
    }
    else if (this.bookSource == Book.BOOK_SRC_AMAZON_OUR_IMAGE)
    {
        document.writeln("<a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\"><img src=\"" + this.imageSource + "\" alt=\"\" border=\"0\" class=\"justBorder\"></a><br>");
        document.writeln("<strong><a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\">" + this.title + "</a></strong><br>");
        document.writeln(this.author + "<br>");
        document.writeln(this.publisher);
    }
    else if (this.bookSource == Book.DVD_SRC_AMAZON)
    {
        document.writeln("<a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\"><img height=\"" + DEFAULT_IMAGE_HEIGHT + "\" src=\"http://images.amazon.com/images/P/" + this.asin + ".01._SCLZZZZZZZ_SL" + DEFAULT_IMAGE_HEIGHT + "_.jpg\" alt=\"\" border=\"0\" class=\"justBorder\" style=\"border:none\"></a><br>");
        document.writeln("<strong><a href=\"http://amazon.com/exec/obidos/ASIN/" + this.asin + "/" + ASSOCIATES_ID + "\">" + this.title + "</a></strong><br>");
        document.writeln(this.author + "<br>");
        document.writeln(this.publisher);
    }
    else if (this.bookSource == Book.BOOK_NO_BORDER)
    {
        document.writeln("<a href=\"" + this.url + "\"><img src=\"" + this.imageSource + "\" alt=\"\" border=\"0\" class=\"noBorder\"></a><br>");
        document.writeln("<strong><a href=\"" + this.url + "\">" + this.title + "</a></strong><br>");
        document.writeln(this.author + "<br>");
        document.writeln(this.publisher);
    }
    else // Book.AS_IS
    {
        document.writeln("<a href=\"" + this.url + "\"><img src=\"" + this.imageSource + "\" alt=\"\" border=\"0\" style=\"border:solid black 1px\"></a><br>");
        document.writeln("<strong><a href=\"" + this.url + "\">" + this.title + "</a></strong><br>");
        document.writeln(this.author + "<br>");
        document.writeln(this.publisher);
    }

    document.writeln("</td>");
}

function _toString()
{
    return "[" + this.asin + ", " + this.title + ", " + this.author + ", " + this.publisher + ", " + this.bookSource + "]";
}

/////////////////////////////
// PROTOTYPES
/////////////////////////////
Book.prototype.drawBookInTable = _drawBookInTable;
Book.prototype.toString = _toString;

/////////////////////////////
// CLASS METHODS & CONSTANTS
// (may NOT access the keyword "this")
/////////////////////////////
Book.BOOK_SRC_AMAZON            = 0;    // Standard Amazon link
Book.BOOK_SRC_AMAZON_UK         = 1;    // Amazon UK link
Book.BOOK_SRC_SFBC              = 2;    // Science Fiction Book Clucb link
Book.CD_SRC_AMAZON              = 3;    // Amazon CD link
Book.CD_SRC_AMAZON_NO_BORDER    = 4;    // Amazon CD link, no border
Book.BOOK_SRC_OTHER             = 5;    // Use own image and link
Book.BOOK_SRC_AMAZON_OUR_IMAGE  = 6;    // Use own image, no resize
Book.AS_IS                      = 7;    // Use own image, no resize
Book.DVD_SRC_AMAZON             = 8;    // DVD/Blu-ray, No Border
Book.BOOK_NO_BORDER             = 9;    // Book with no Border image

/////////////////////////////
// HELPER METHODS FOR POSTS
/////////////////////////////
var NUM_COLUMNS = 3
function drawBooksReceived()
{
    for (var x=0; x<books.length; x++)
    {
        if (x%NUM_COLUMNS == 0){document.writeln("<tr valign=\"top\">");}
        books[x].drawBookInTable();
        if (x%NUM_COLUMNS == (NUM_COLUMNS-1)){document.writeln("</tr>");}
    }
}

