function attach_vote_click(buttons) {
	for (var i = 0; i < buttons.length; i++) {
		var button = buttons[i];

		if (button.className == 'voteupbutton' || button.className == 'votedownbutton') {
			$(button).addEvent('click', function (e) {
				e = new Event(e).stop();
				if (e.target.className == 'votedisabled') {
					return;
				}
				var action = (e.target.className == 'voteupbutton'?'up':'down');
				var rowid = e.target.id.substr(action.length);
				var url;
				if (rowid.indexOf('_') == -1) {
					url = $('linkurl' + rowid).value;
				}
				new Request.HTML({
					url: '/vote'
					, method: 'post'
					, update: $('cnt' + rowid)
					, onSuccess: function() {
						$('up' + rowid).className = 'votedisabled';
						$('down' + rowid).className = 'votedisabled';
					} }).post({ 'action': action, 'id': rowid, 'url': url });
			});
		}
	}
}

window.addEvent('domready', function() {

	var buttons = document.getElementsByTagName('a');
	attach_vote_click(buttons);

});
