$(document).ready(function() {
	if (window.map_initialize) map_initialize();
	
	// make FAQ answers show/hide on clicking the questions
	$('#faqs .toggle').click(function(){
		var href=$(this).attr('href');
		var divid=href.replace('#faq','answer');
		$('#'+divid).toggle();
		return false;
	});
	// pre-hide all the answers on pageload
	$('#faqs .toggle').each(function(){$(this).click();});
	
	// equal-height each heading and cell on each row of the signposts
	if ($('#signposts > li > ul').length) {
		$('#signposts > li > ul').each(function(){$(this.children).equalHeights();});
	}
	
	// nivoslider
	if ($('#slider').length) $('#slider').nivoSlider({effect:'fade',pauseTime:5000,captionOpacity:1,controlNav:false,directionNav:false});
	
	// equal-height div children of #content-holder-holder
	// needs to be done after anything else that can affect the height of the elements being resized
	//$('#content-holder-holder > div').equalHeights();
	
	// fancybox
	$(".gallery a").each(function() {$(this).fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleShow'			: true,
		'scrolling'			: 'no'
	})});
	// fancybox youtube - see http://fancybox.net/blog
	$('.youtubegallery a').each(function(){$(this).click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'		: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
			   		 'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});return false;});
	});
	
	// look for anchors with href and rel="external", and add target="_blank" to them so that they open in a new window
	// from http://articles.sitepoint.com/article/standards-compliant-world/3
	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";
		}
	}
	
});
/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 * 
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com) 
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 * 
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 * 
 * 
 * TJS revision 1.1
 * 2010-06-14
 * Solves the problem of height-matching an element that has padding and/or border, with one that has no padding and/or border. 
 * It inspects the outerHeight rather than the height, but adjusts only the height by whatever shortfall was found.
 */
(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).outerHeight() > tallest) {
				tallest = $(this).outerHeight();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			shortfall=tallest-$(this).outerHeight();
			targetheight=$(this).height()+shortfall;
			$(this).height(targetheight)/*.css("overflow","hidden")*/;/* overflow:auto triggers scrollbars upon :active of a link */
		});
	}
})(jQuery);

