/*
	v1.3.2 :: 2007.11.28 10:38
	Base event and inclusion handlers.
*/


/* OnLoad Event Loader */
function addLoadEvent(f) {
	var oldOnload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = f;
	} else {
		window.onload = function() {
			if(oldOnload) {
				oldOnload();
			}

			f();
		}
	}
};


/* External Script Loader */
function include(s) {
	document.write('<script type="text/javascript" src="/scripts/'+s+'"></script>');
};

// Unobtrusive Flash Object
include('ufo.js');


addLoadEvent(function() {
	if(document.getElementById) {
/* Search Form additions, until 2008 template push */
		var searchForm = document.getElementById('search');
		if(searchForm) {
			searchForm.method = 'get';
			searchForm.innerHTML = searchForm.innerHTML +
				'<input type="hidden" name="site" value="default_collection">' +
				'<input type="hidden" name="proxystylesheet" value="nashville">' +
				'<input type="hidden" name="client" value="nashville">' +
				'<input type="hidden" name="output" value="xml_no_dtd">';
		}

/* Link Checker -- Adds mini icons before specific documents and/or link URIs */
		if(document.createElement && document.getElementsByTagName) {
			var links = document.getElementById('main');
			if(links) {
				links = links.getElementsByTagName('a');
				var numLinks = links.length+1;

				if(numLinks > 0) {
					var currentLink, linkSuffix, linkVal, linkIcon, linkType,
						thisURI = window.location.protocol + '//' + window.location.host,
						linkImgs = {}, // icon cache
						linkTypes = {
							pdf: 'PDF Document',
							docx: 'Word 2007 Document',
							doc: 'Word Document',
							dot: 'Word Document Template',
							pptx: 'Powerpoint 2007 Document',
							ppt: 'Powerpoint Document',
							ppsx: 'Powerpoint 2007 Slideshow Document',
							pps: 'Powerpoint Slideshow Document',
							xlsx: 'Excel 2007 Document',
							xls: 'Excel Document',
							wmv: 'Windows Media Video',
							asf: 'Windows Media Video',
							mailto: 'Email',
							ftp: 'FTP Link',
							https: 'Secure Link',
							ext: 'External Link',
							zip: 'Zipped file'
						};

					var linkImg = document.createElement('img');
						linkImg.style.marginRight = '.25em';
						linkImg.style.verticalAlign = 'middle';
						linkImg.style.border = '0px';
						linkImg.style.cssFloat = 'none';
						linkImg.style.height = '18px';
						linkImg.style.width = '18px';

					do {
						currentLink = links[numLinks];
						linkSuffix = '';

						try {
							if((linkVal = currentLink.getAttribute('href').toLowerCase()) && currentLink.getElementsByTagName('img').length == 0) {
								if((linkVal.indexOf(thisURI) == 0) || (linkVal.indexOf('http:') != 0)) {
									for(linkType in linkTypes) {
										if(linkVal.lastIndexOf('.')==(linkVal.length-5)) {
											if(linkVal.substring((linkVal.length-5), linkVal.length).indexOf('.'+linkType) == 0 || linkVal.indexOf(linkType+':') == 0) {
												linkSuffix = linkType;
												break;
											}
										} else {
											if(linkVal.substring((linkVal.length-4), linkVal.length).indexOf('.'+linkType) == 0 || linkVal.indexOf(linkType+':') == 0) {
												linkSuffix = linkType;
												break;
											}
										}
									}
								} else {
									linkSuffix = 'ext';
								}

								if(linkSuffix != '') {
									if(linkImgs.linkSuffix) { // cached?
										linkIcon = linkImgs.linkSuffix.cloneNode(false);
									} else {
										linkIcon = linkImg.cloneNode(false);
										linkIcon.src = '/images/icon_'+linkSuffix+'.gif';
										linkIcon.alt = linkTypes[linkSuffix];
										linkImgs[linkSuffix] = linkIcon;
									}
									currentLink.parentNode.insertBefore(linkIcon, currentLink);
									currentLink.target = '_blank';
								}
							}
						} catch(e) {}
					} while(--numLinks);
				}
			}
		}
	}
});