﻿var Site = function () {
	_public = {};

	_public.init = function () {
		$.fn.extend({
			deleteRecord: function () {
				$(this).click(function (e) {
					e.preventDefault();
					var targetUrl = $(this).attr('href');
					$('#deleteDialog').dialog({
						buttons: {
							"Delete": function () {
								window.location.href = targetUrl;
							},
							"Cancel": function () {
								$(this).dialog('close');
							}
						}
					});

					$('#deleteDialog').dialog('open');

					return false;
				});
			},

			disable: function () {
				$(this).attr("disabled", "disabled");
			},
			enable: function () {
				$(this).removeAttr("disabled");
			}
		});

		$('.dateEntry').datepicker();
		$('table:not(.formatted) tbody tr:even').addClass('altrow');
		$('table:not(.formatted) tbody tr:odd').removeClass('altrow');

		$('#deleteDialog').dialog({
			autoOpen: false,
			resizable: false,
			modal: true
		});

		$('#ratingsExplanation').dialog({
			autoOpen: false,
			resizable: false,
			modal: true,
			width: '700px',
			buttons: {
				"Okay": function () {
					$(this).dialog('close');
				}
			}
		});

		$("#status, #error").slideDown("slow");
		$("#status a.close-notify").click(function () {
			$(this).parent().slideUp("slow");
			return false;
		});

		// TODO: Move this into a different file
		$('a.deleteRegistration').deleteRecord();
		$('a.deleteGame').deleteRecord();

		$('a#ratingsPopup').live('click', function () {
			$('#ratingsExplanation').dialog('open');
		});
	};

	return _public;
} ();

$(document).ready(Site.init);
