// Start function when DOM has completely loaded
$(document).ready(
	function() {
		randomizeBoxBackgrounds();
		capitalsInParagraphs();
	}
);

function stringIsValid(str) {
	if(str != null && str != undefined && String(str).length > 0) { return true; } 
	else { return false; }
}

function randomizeBoxBackgrounds() {
	$(".boxed").each(function(){
		$(this).css("background-position", Math.floor(720*Math.random()) + "px " + Math.floor(480*Math.random()) + "px");
	});
}

function doCaps(text) {
	if(text.length > 0) text = "<div class='letter_" + text.substring(0,1).toLowerCase() + "'>"+ text.substring(0,1).toUpperCase() +"</div>" + text.substring(1,text.length);
	return text;
}

function capitalsInParagraphs() {
	$("u").each(function(i){
		$(this).html( doCaps( $(this).html() ) );
	});
}

// take from http://docs.jquery.com/Cookbook/wait
$.fn.wait = function(time, type) {
	time = time || 1000;
	type = type || "fx";
	return this.queue(type, function() {
		var self = this;
		setTimeout(function() {
			$(self).dequeue();
		}, time);
	});
};
