var theRules = {
	'h1' : function(element) {
		element.onclick = function() {
			window.location.href = root;
		}
	},
	'a.voteup' : function(element) {
		element.onclick = function() {
			$('score' + element.getAttribute('qid')).innerHTML = '<img src="' + root + '/images/indicator.gif" alt="" height="16" width="16" />';
			new Ajax.Updater(
				'quote' + element.getAttribute('qid'),
				root + '/vote.php',
				{
					parameters: 'id=' + element.getAttribute('qid') + '&direction=up',
					evalScripts: true,
					onComplete: function() {
						Behaviour.apply();
					}
				}
			);
			return false;
		}
	},
	'a.votedown' : function(element) {
		element.onclick = function() {
			$('score' + element.getAttribute('qid')).innerHTML = '<img src="' + root + '/images/indicator.gif" alt="" height="16" width="16" />';
			new Ajax.Updater(
				'quote' + element.getAttribute('qid'),
				root + '/vote.php',
				{
					parameters: 'id=' + element.getAttribute('qid') + '&direction=down',
					evalScripts: true,
					onComplete: function() {
						Behaviour.apply();
					}
				}
			);
			return false;
		}
	},
	'img.approve' : function(element) {
		element.onclick = function() {
			new Ajax.Request(
				root + '/mod.php',
				{
					parameters: 'id=' + element.getAttribute('qid') + '&op=approve',
					onComplete: function(t) {
						if(t.responseText == 'ok') {
							new Effect.Fade('quote' + element.getAttribute('qid'));
						} else {
							new Effect.Shake('quote' + element.getAttribute('qid'), {
								afterFinish: function() {
									alert(t.responseText);
								}
							});
						}
					}
				}
			);
		}
	},
	'img.edit' : function(element) {
		element.onclick = function() {
			new Ajax.Updater(
				'thequote' + element.getAttribute('qid'),
				root + '/edit.php',
				{
					parameters: 'id=' + element.getAttribute('qid'),
					onComplete: function() {
						Behaviour.apply();
					}
				}
			);
			return false;
		}
	},
	'form.editquote' : function(element) {
		element.onsubmit = function() {
			new Ajax.Updater(
				'thequote' + element.getAttribute('qid'),
				root + '/edit.php',
				{
					parameters: 'id=' + element.getAttribute('qid') + '&' + Form.Element.serialize('tosave' + element.getAttribute('qid')),
					onComplete: function() {
						Behaviour.apply();
					}
				}
			);
			return false;
		}
	},
	'img.delete' : function(element) {
		element.onclick = function() {
			if(confirm('Are you sure you want to delete this quote?  This cannot be undone!')) {
				new Ajax.Request(
					root + '/mod.php',
					{
						evalScripts: true,
						parameters: 'id=' + element.getAttribute('qid') + '&op=delete',
						onComplete: function(t) {
							if(t.responseText == 'ok') {
								new Effect.Puff('quote' + element.getAttribute('qid'));
							} else {
								new Effect.Shake('quote' + element.getAttribute('qid'), {
									afterFinish: function() {
										alert(t.responseText);
									}
								});
							}
						}
					}
				);
				return false;
			} else {
				return false;
			}
		}
	}
};

Behaviour.register(theRules);