// Automatic link processing

function links()
{
	links = document.getElementsByTagName('A');

	for( x = 0; x < links.length; x++ ) {
		if(links[x].href) {
			h = document.all ? links[x].host.substring(0, links[x].host.length - 3) : links[x].host;
	
			if( !links[x].target && links[x].href.substring(0, 4) == 'http' && h != location.host ) {
					links[x].target = '_blank';
	
					if( links[x].className ) {
						links[x].className += ' ';
					}
					links[x].className += 'external';
			}
		}
	}
}

// Automatic caption generator

function captions()
{
	for( i = 0; i < document.images.length; i++ ) {
		aS = document.images[i].alt.indexOf('[');
		aE = document.images[i].alt.indexOf(']');

		if( aS > -1 && aE > -1 ) {
			pN = document.images[i].parentNode;

			div = document.createElement('div');

			div.className = 'caption';

			setFloat(div, document.all ? document.images[i].style.styleFloat : document.images[i].style.cssFloat);
			setFloat(document.images[i], 'none');

			if ( document.images[i].width ) {
				div.style.width = document.images[i].width + 'px';
			}

			div.appendChild( document.images[i] );
			div.appendChild( document.createTextNode( div.firstChild.alt.substring( ++aS, aE )));

			pN.insertBefore( div, pN.firstChild );
		}
	}
}

if( document.all ) {
	window.attachEvent('onload', captions);
	window.attachEvent('onload', links);
}
else {
	window.addEventListener('load', captions, false);
	window.addEventListener('load', links, false);
}

/* IE just HAD to use a different property name than 'Zilla... */
function setFloat(e, v) {
	if( document.all ) {
		e.style.styleFloat = v;
	}
	else {
		e.style.cssFloat = v;
	}
}