// Template Specific
$(document).ready(function(){
	// Site Search box
	$('#search_q').focus(function(){
		if ($(this).val() == 'Search...') {
			$(this).val('');
		}
	}).blur(function(){
		if ($(this).val() == '') {
			$(this).val('Search...');
		}
	});

	// Strip any of the Google Maps "Terms of Use"
	$('a[href*="http://www.google.com/intl/"]').remove();

	// Make off-site links open in new windows
	$("a").filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).attr('target', '_blank');

	// Nav
	var path = location.pathname.substring(1);
	var path_arr = path.split('/');
	$('ul.nav_primary ul a[href="/'+path+'"]').parents('li').addClass('active');
	$('ul.nav_primary a[href^="/'+path_arr[0]+path_arr[1]+'"]').parent('li').parent('ul').parent('li').addClass('active');
	nav_primary();
	if ($('ul.nav_secondary').length > 0) {
		if ( path ) {
			$('#nav_secondary a[href$="' + path + '"]').attr('class', 'active').parents('li').addClass('active');
		}
	}
	if ($('ul.nav_secondary li ul:visible').length < 1) {
		$('#nav_secondary').css('padding-bottom', '0');
	}

	$('a.email.rev').live('click', function(){
		var $this = $(this);
		$this.attr('href', 'mailto:' + $this.text().split('').reverse().join(''));
	});
});




function nav_primary() {
	$('#nav_primary > div > ul > li').each(function () {
		children = $(this).children('ul').children('li').length;
		if (children) {
			if ($(this).hasClass('active')) {
				height = $(this).children('ul').children('li').eq(0).height() * $(this).children('ul').children('li').length;
				$(this).height(height).css('top', -height).children('ul').css('height','auto').css('opacity', 100);
			} else {
				$(this).hover(
					function () {
						height = $(this).children('ul').children('li').eq(0).height() * $(this).children('ul').children('li').length;
						$(this).animate({
							top: -height
						}, {queue: false}).children('ul').animate({
							height: height,
							opacity: 1
						}, {queue: false});
					}, function () {
						$(this).animate({
							top: 0
						}).children('ul').animate({
							height: 0,
							opacity: 0
						});
					}
				);
			}
		}
	});
}

