BookQuery = function(results, queue) {
    this.q = new DED.Queue;
    this.q.setRetryCount(5);
    this.q.setTimeout(3000);
	
	this.results = results;
	this.queue = queue;

	// Keeping track of my own requests as a client.
	this.requests = [];
    var that=this;
	
	// Notifier for each request that is being flushed.
	this.q.onFlush.subscribe(function(data) {
		var creator=data.getElementsByTagName("creator")[0].firstChild.data;
		var title=data.getElementsByTagName("title")[0].firstChild.data;
		var imageURL = data.getElementsByTagName("imageURL")[0].firstChild.data;
		var infoURL = data.getElementsByTagName("infoURL")[0].firstChild.data;
		var pubdate = data.getElementsByTagName("pubdate")[0].firstChild.data;
		var publisher = data.getElementsByTagName("publisher")[0].firstChild.data;
		var txt = "<img src=\"" + imageURL + "\"/> <b>" +creator+ ".</b> <a href=\"" + infoURL + "\">"+
				title+"</a>, <i>"+publisher+", "+pubdate+".</i>";
				  
		var newEl = AIS.$("<li>");
		newEl.setInnerHtml(txt);
		that.results.appendChild(newEl);
        that.requests.shift();
        that.queue.setInnerHtml(that.requests.toString());
    });
    // Notifier for any failures.
    this.q.onFailure.subscribe(function() {
		results.setInnerHtml(' <span style="color:red;">Connection Error!</span>');
    });
    // Notifier of the completion of the flush.
    this.q.onComplete.subscribe(function() {
    });
}

BookQuery.prototype.addRequest = function(isbn) {
    this.q.add({
         method: 'GET',
         uri: 'http://alexeysmirnov.name/books/getbook.php?isbn='+isbn,
         params: null
     });
     this.requests.push(isbn);
	 this.queue.setInnerHtml(this.requests.toString());
};
