$(document).ajaxError(function (event, request, options, error) {
	app.log("AJAX Error: " + error);
	app.log("An error has occured while communicating with the server.");
	app.callInProgress = false;
});

$(document).ajaxSend(function (event, request, options) {
	app.log("AJAX Call: " + options.url);
	app.callInProgress = true;
});

$(document).ajaxSuccess(function (event, request, options) {
	app.callInProgress = false;
});

var app = {

	debug : false,
	
	log : function (msg) {
		if (app.debug && typeof console == 'object')
			console.log(msg);
	},
	
	callInProgress : false,

	call : function (url, data, result) {
		$.ajax({
			type: "get",
			url: "/Data.cfm/" + url,
			data: data,
			dataType: "json",
			success: result
		});
	},

	featuredYearbookLoader : {
		show : function () {
			$('#featuredYearbookLoader').fadeIn('slow');
		},
		
		hide : function () {
			$('#featuredYearbookLoader').fadeOut('slow');
		}
	},

	util : {

		delay : function(action) {
			setTimeout(action, 250);
		},

		toProperCase : function(text) {
			return text.toLowerCase().replace(/^(.)|\s(.)/g, function(text) { return text.toUpperCase(); });
		},

		pad : function(n, totalLength, side, padCharacter) {
			if (n.toString().length < totalLength) {
				var padded = n.toString();

				while (padded.length < totalLength) {
					if (side === 'left')
						padded = padCharacter + padded;
					else if (side === 'right')
						padded = padded + padCharacter;
				}

				return padded;
			}
			else
				return n;
		}

	},

	service : {
		
	},

	action : {
		
	},

	event : {
	
	}

};

