document.observe("dom:loaded", function() {
	if ($("content-puffs")) {
		new content_puff_handler($("content-puffs"));
	}
	
	$$("div[id^='search-results-book-']").each(function(div) {
		new search_result_handler(div);
	});
});

var content_puff_handler = Class.create({
	initialize: function(container) {
		this.container = container
		
		this.container.childElements().each(function(div) {
			var anchors = div.getElementsBySelector("a[href!='']");
			
			if (anchors.length == 1) {
				div.observe("click", function(event) {
					event.stop();
					window.location.href = anchors[0].readAttribute("href");
				}).setStyle({
					'cursor': 'pointer'
				});
			}
		});
	}
});

var search_result_handler = Class.create({
	initialize: function(container) {
		this.container = container;
		
		var anchors = this.container.getElementsBySelector("a[href!='']");
		
		if (anchors.length == 1) {
			this.container.observe("click", function(event) {
				event.stop();
				window.location.href = anchors[0].readAttribute("href");
			}).setStyle({
				'cursor': 'pointer'
			});
		}
	}
});
