/*<iframe src="http://rcm.amazon.com/e/cm?t=adventuroft08-20&o=1&p=8&l=as1&asins=1590595335&fc1=000000&IS2=1&lt1=_blank&lc1=0000ff&bc1=000000&bg1=ffffff&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<iframe src="http://rcm.amazon.com/e/cm?t=adventuroft08-20&o=1&p=8&l=as1&asins=0767921992&fc1=000000&IS2=1&lt1=_blank&lc1=0000ff&bc1=000000&bg1=ffffff&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<iframe src="http://rcm.amazon.com/e/cm?t=adventuroft08-20&o=1&p=8&l=as1&asins=0671502336&fc1=000000&IS2=1&lt1=_blank&lc1=0000ff&bc1=000000&bg1=ffffff&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<iframe src="http://rcm.amazon.com/e/cm?t=adventuroft08-20&o=1&p=8&l=as1&asins=0451191145" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
*/			

function drawLibrary( xmlDoc, filter) {
  var bookReplace = document.getElementById( 'books');
  if(!bookReplace) {
    document.write("<p>broken, span - form or gallery placeholder doesn't exist</p>");
    return;
  }
  if(!filter) {
     filter = "all";
  }
   
  bookReplace.parentNode.replaceChild( createLibrary( xmlDoc, filter), bookReplace);
  xmlDoc = null;
}

function createLibrary ( xmlDoc, filter) {
  var bookLists = xmlDoc.getElementsByTagName( "list");
  var library = document.createElement( "div");
  library.setAttribute( "id", "books");

  for( var i = 0; i < bookLists.length; i++) {
    var entry = document.createElement( "div");
    entry.setAttribute( "class", "entry");
    var header = document.createElement( "h3");
    header.appendChild( document.createTextNode( bookLists[i].getElementsByTagName( "name")[0].firstChild.data));
    entry.appendChild( header);
    var listName = bookLists[i].getElementsByTagName("name")[0].firstChild.data;
    var books = bookLists[i].getElementsByTagName("book");
    for( var x = 0; x < books.length; x++) {
      var p = document.createElement( "p");
      p.appendChild( document.createTextNode( books[x].getElementsByTagName( "name")[0].firstChild.data));
 //     entry.appendChild( p);
      var iframe = document.createElement( "iframe");
      iframe.setAttribute( "style",'width:120px;height:240px;');
      iframe.style.width = "120px";
      iframe.style.height = "240px";
      iframe.setAttribute( "scrolling", "no");
      iframe.setAttribute( "marginwidth", "0");
      iframe.setAttribute( "marginheight", "0");
      iframe.setAttribute( "frameborder", "0");
      var amazonSrc = 'http://rcm.amazon.com/e/cm?t=adventuroft08-20&o=1&p=8&l=as1&asins=';
      amazonSrc += books[x].getElementsByTagName( "isbn")[0].firstChild.data;
      amazonSrc += '&fc1=000000&IS2=1&lt1=_blank&lc1=0000ff&bc1=000000&bg1=ffffff&f=ifr';
      iframe.setAttribute( "src", amazonSrc);
      entry.appendChild( iframe);
      
    }
/*<iframe style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<iframe src="http://rcm.amazon.com/e/cm?t=adventuroft08-20&o=1&p=8&l=as1&asins=0767921992&fc1=000000&IS2=1&lt1=_blank&lc1=0000ff&bc1=000000&bg1=ffffff&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<iframe src="http://rcm.amazon.com/e/cm?t=adventuroft08-20&o=1&p=8&l=as1&asins=0671502336&fc1=000000&IS2=1&lt1=_blank&lc1=0000ff&bc1=000000&bg1=ffffff&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<iframe src="http://rcm.amazon.com/e/cm?t=adventuroft08-20&o=1&p=8&l=as1&asins=0451191145" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
*/			
    library.appendChild( entry);
  }
  
  return library;

/*
  var table = document.createElement( "table");
  gallery.appendChild( table);
  var movies = xmlDoc.getElementsByTagName( "movie");

  var row = table.insertRow(0);
  var cell = 0;
  for( var i = 0; i < movies.length; i++) {
    var img = document.createElement( "img");
    img.setAttribute( "src", thumbPath+movies[i].getElementsByTagName( "thumb")[0].firstChild.data);
    img.setAttribute( "Alt", "Click to view movie");
//    img.setAttribute( "onclick\", "javascript:openNewMovie(\'"+basePath+movies[i].getElementsByTagName( "name")[0].firstChild.data+"\')");
    var link = document.createElement( "a");
//    link.setAttribute( "href", "javascript:openViewer(\'"+imageArray[ i]+"\',\'"+filter+"\')");
    link.setAttribute( "href", "javascript:openNewMovie(\'"+basePath+movies[i].getElementsByTagName( "name")[0].firstChild.data+"\');");

    link.appendChild( img);
    row.insertCell(cell).appendChild( link);
    cell = 1;
    var p = document.createElement( "p");
    p.appendChild( document.createTextNode( movies[i].getElementsByTagName( "size")[0].firstChild.data+" - "));
    p.appendChild( document.createTextNode( movies[i].getElementsByTagName( "length")[0].firstChild.data+" - "));
    p.appendChild( document.createTextNode( movies[i].getElementsByTagName( "description")[0].firstChild.data));
    row.insertCell(cell).appendChild( p);
    row = table.insertRow( i + 1);
    cell = 0;
  }
  return gallery;
*/
}
