function externalLinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i = 0; i < anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank"; 
		}
	}
}

if (window.addEventListener) {
	window.addEventListener('load', externalLinks, false); 
} else if (window.attachEvent) { 
	window.attachEvent('onload', externalLinks);
}

function popup(pageUrl, width, height) {
	var left = screen.width / 2 - width / 2;
	var top = screen.height / 2 - height / 2;
	
	window.open(pageUrl, '', 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ",scrollbars=yes,resizable=no");
}

function getUrlFragment() {
	if (window.location.hash != undefined &&
		window.location.hash != '') {
		var hasHash = window.location.hash.indexOf('#');
		if (hasHash == -1) {
			return window.location.hash;
		} else if (window.location.hash.length > 1) {
			return window.location.hash.substr(hasHash + 1);
		} else {
			return false;
		}
	}
	return false;
}

function moreBlocks(className, appendStyle) {
	$('.' + className).hide();
	if (appendStyle != undefined) {
		$('.' + className).css(appendStyle);
	}
	$('.' + className + 'More').click(function() {
		var elementId = this.id.substring(0, this.id.indexOf('More'));
		if ($('#' + elementId).is(':visible')) {
			// hide the element contents
			$('#' + elementId).animate({
				height: "hide",
				paddingTop: '0',
				paddingBottom: '0'
			});
		} else {
			// show the elements contents
			$('.' + className + ':visible:not(#' + elementId + ')').animate({
				height: "hide",
				paddingTop: '0',
				paddingBottom: '0'
			});
			$('#' + elementId).animate({
				height: "show",
				paddingTop: '8px',
				paddingBottom: '8px'
			});
		}
		return false;
	});
}

/* from http://developer.apple.com/internet/safari/faq.html */
function isAppleWebkit() {
	// String found if this is a AppleWebKit based product
	var kitName = "applewebkit/";
	var tempStr = navigator.userAgent.toLowerCase();
	var pos = tempStr.indexOf(kitName);
	return (pos != -1);
}

function isCrappyBrowser() { // returns true for IE < 7
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		if (ieversion < 7) return true;
	}
	return false;
}

function is_numeric_string(validationString) {
	return validationString.match('^[0-9]+$');
}

	// two string methods from http://www.ditchnet.org/wp/2005/04/04/i-want-my-javalang/

	/**
 *  String convenience method to trim leading and
 *  trailing whitespace.
 *  @returns string
 */
	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g, '');
	};

	/**
 *  String convenience method for checking if the
 *  end of this string equals a given string.
 *
 *  @returns boolean
 *  @throws IllegalArgumentException for parameters
 *                          not of type String
 */
	String.prototype.endsWith = function (s) {
		if ('string' != typeof s) {
			throw('IllegalArgumentException: Must pass a ' +
				' string to String.prototype.endsWith()');
		}
		var start = this.length - s.length;
		return this.substring(start) == s;
	};

// from http://www.irt.org/script/1621.htm

function wordcount(string) {
	var a = string.split(/\s+/g); // split the sentence into an array of words
	return a.length;
}

$(document).ready(function() {

	if (window.stepcarousel) {
	stepcarousel.setup({
		galleryid: 'slideshow', //id of carousel DIV
		beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
		panelclass: 'slide', //class of panel DIVs each holding content
		autostep: {
			enable:true,
			moveby:1,
			pause:10000
		},
		panelbehavior: {
			speed:500,
			wraparound:true,
			wrapbehavior:'slide',
			persist:true
		},
		defaultbuttons: {
			enable: true,
			moveby: 1,
			leftnav: ['/images/slidenav_prev.gif', -9, 105],
			rightnav: ['/images/slidenav_next.gif', -20, 105]
			},
			onslide:function(){
				 _i = 0;
				 $("#buttonbar img").each(function(){
						  _i++;
						 if (_i==statusA) $(this).attr("src","/images/slidebutton.jpg"); else $(this).attr("src","/images/slidebuttongo.jpg");
				 });
			},
		statusvars: ['statusA', 'statusB', 'statusC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
		contenttype: ['inline'] //content setting ['inline'] or ['ajax', 'path_to_external_file']
	});
	}
	 

	
	$('#navigation > li').bind('mouseover', function(){
		$(this).addClass('active');
		var $curSubmenu = $(this).find('ul:first');
		$curSubmenu.stop().animate({
			opacity: 1
		}, 100, function(){
			$curSubmenu.show();
		});
	});
	$('#navigation > li').bind('mouseout', function(){
		$(this).removeClass('active');
		var $curSubmenu = $(this).find('ul:first');
		$curSubmenu.stop().animate({
			opacity: 1
		}, 100, function(){
			$curSubmenu.hide();
		});
	});	
	
	if (!isCrappyBrowser()) {
		$('a > img.thumbnail').each(function() {
			var href = this.parentNode.href;
			if (href.indexOf('/images/db') != -1) {
				var imgDiv = $('<div style="position: fixed; z-index: 1000; top: 40px; left: 0; width: 100%; height: 100%; text-align: center; cursor: pointer;"><img src="' + href + '" style="border: 1px solid black; -webkit-box-shadow: 0 0 30px black" alt="" /></div>');
				$(this).click(function() {
					window.status = 'Showing ' + href;
					$('div#header').prepend(imgDiv);
					imgDiv.click(function() {
						window.status = 'Removing...';
						$(this).remove();
					});
					return false;
				})
			}
		});
	}
});

	String.prototype.isEmailAddress = function() {
		var emailTestRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		return this.match(emailTestRegex);
	}
