function BootLoader() {}
BootLoader.loaders = new Array();

/**
 * A method to register initializers to the bootloader
 * @param init The initialization function to run at window load
 */
BootLoader.register = function( init )
{
	this.loaders.push( init );
};

window.onload = function()
{
	for( var i = 0; i < BootLoader.loaders.length; i++ )
		BootLoader.loaders[i]();
};

BootLoader.init = window.onload;

// Find all external links, and set them to open in a new window
BootLoader.register( function() {
	// Base URL info, change to suit URL
	var URL_BASE = "http://cbojar.net/";
	var URL_BASE_WWW = "http://www.cbojar.net/";

	if( !document.getElementsByTagName )
		return;

	var links = document.getElementsByTagName( "a" );
	for( var i = 0; i < links.length; i++ )
	{
		var href = links[i].getAttribute( "href" );
		// Check for an empty link, if so, skip
		if( href == null || href == "" )
			continue;

		// Check for JavaScript hyperlinks, if so, skip
		if( href.match( /^javascript:/gi ) )
			continue;

		// Check for a local link, except PDFs, if so, skip
		if( ( href.match( /^(\.\.?)?\//gi ) || href.match( URL_BASE ) || href.match( URL_BASE_WWW ) ) && !href.match( /\.pdf/gi ) )
			continue;

		// Set onclick to open new window, and prevent following the link
		links[i].onclick = function()
		{
			window.open( this.getAttribute( "href" ) );
			return false;
		};
	}
} );

