/*
 * Ready Handler ------------------------------------------------------------------------------------------------------------------------
 */
$(bigOhSoftwareWebReadyHandler);

function bigOhSoftwareWebReadyHandler() {

	decorateHyperlinks();

	decorateImages();

	augmentWindowUnload();

}

function decorateHyperlinks() {

	// open external links in a new window
	$("a[href^=http://]").attr("target", "_blank");
	
	// open non-JSP file links in a new window
	$("a:not([href$=.jsp])").attr("target", "_blank");

	// set title on all links that don't have an explicitly defined title
	$("a[href]:not([title])").attr("title", function() {
		return this.href;
	});

	// augment title on all links that open in a new window
	$("a[title][target=_blank]").attr("title", function() {
		return this.title + '  (new window)';
	});

}

function decorateImages() {

	// set an alt attribute on all images that don't have an explicitly defined alt attribute
	$("img[src]:not([alt])").attr('alt', function() {
		var srcElements = $.trim(this.src).split("/");
		if (srcElements.length > 0) {
			return srcElements[srcElements.length - 1];
		} else {
			return $.trim(this.src);
		}
	});

	// set the title on all images that don't have an explicitly defined title
	// attribute
	$("img[alt]:not([title])").attr("title", function() {
		return $.trim(this.alt);
	});

}

function augmentWindowUnload() {

	// fade the main content while user waits for next page
	// note that 'onbeforeunload' doesn't seem to be a jquery-supported event.
	window.onbeforeunload = function() {
		$("div#content").fadeTo("fast", .3);
	};

}

/*
 * jQuery Aliases ------------------------------------------------------------------------------------------------------------------------
 */
$.fn.replaceWith = function(html) {
	return this.after(html).remove();
}
