/**
 * Monitors the bookmark, and if javascript working uses ajax to record it
 * 
 * @copyright Scribendi Inc.
 * @author Dave Redfern
 * @requires Prototype 1.6
 */
Event.observe(window, 'load', function() {
	if ( $('bookmark') !== null ) {
		$('bookmark').observe('click', function(event){
			var category_id = $('bookmark').getAttribute('href').gsub(/[^0-9]+/, '');
			new Ajax.Request('/customer', {
			  	parameters: {
					ajax_action: 'add_bookmark',
					category_id: category_id
				},
				onSuccess: function(request) {
					$('bookmark').down('.bookmark').innerHTML = '<em>Bookmark saved</em>';
				},
				onFailure: function(request) {
					$('bookmark').down('.bookmark').innerHTML = '<em>Error saving bookmark</em>';
				}
			});
			event.stop();
		});
	}
});
