var theRules = {
	'#picupload' : function(element) {
		element.onsubmit = function() {
			return confirm('Uploading objectionable images will get you banned. If you wouldn\'t post it on the forums, don\'t post it here.');
		}
	},
	'.deletecomment' : function(element) {
		element.onclick = function() {
			if(confirm('Are you sure you want to delete this comment?')) {
				new Ajax.Request('/yearbook/deletecomment.php', {
					parameters: 'id=' + element.getAttribute('cid'),
					onComplete: function() {
						new Effect.Fade('comment' + element.getAttribute('cid'));
					}
				});
			}
			return false;
		}
	},
	'#deletepic' : function(element) {
		element.onclick = function() {
			if(confirm('Are you sure you want to delete this pic?')) {
				new Ajax.Request('/yearbook/deletepic.php', {
					parameters: 'id=' + id + '&year=' + year,
					onComplete: function() {
						new Effect.Fade('thePhoto');
					}
				});
			}
			return false;
		}
	},
	'.star-rating a' : function(element) {
		element.onclick = function() {
			new Ajax.Updater('voting', '/yearbook/ajax_voting.php', {
				parameters: 'id=' + id + '&year=' + year + '&category=' + element.getAttribute('category') + '&value=' + element.getAttribute('value'),
				onComplete: function() {
					Behaviour.apply();
				}
			});
			return false;
		}
	},
	'.editable' : function(element) {
		element.onmouseover = function() {
			Element.addClassName(element, 'editable-hover');
		},
		element.onmouseout = function() {
			Element.removeClassName(element, 'editable-hover');
		},
		element.onclick = function() {
			new Ajax.Updater(
				element.parentNode,
				'/yearbook/ajax.php',
				{
					parameters: 'year=' + year + '&id=' + id + '&field=' + element.id + '&op=edit',
					onComplete: function() {
						Behaviour.apply();
						$(element.id + '_value').focus();
					}
				}
			);	
			return false;
		}
	},
	'.ajaxform' : function(element) {
		element.onsubmit = function() {
			var theDiv = element.parentNode;
			new Ajax.Updater(
				element.parentNode,
				'/yearbook/ajax.php',
				{
					parameters:
					'year=' + year + '&id=' + id + '&field=' + element.getAttribute('field') + '&value=' + $(element.getAttribute('field') + '_value').value + '&op=save',
					onComplete: function() {
						Behaviour.apply();
						new Effect.Highlight(theDiv, {startcolor: '#a3cca7'});
					}
				}
			);
			return false;
		}
	},
	'input.ajaxcancel' : function(element) {
		element.onclick = function() {
			new Ajax.Updater(
				element.parentNode.parentNode,
				'/yearbook/ajax.php',
				{
					parameters: 'year=' + year + '&id=' + id + '&field=' + element.getAttribute('field') + '&op=show',
					onComplete: Behaviour.apply
				}
			);
			return false;
		}
	}
};

Behaviour.register(theRules);