$(document).ready(function() {

	// re-html-ize long_description text
	$("#primary h2 + div").html($("#primary h2 + div p").text());

	// activate image gallery	
	$("#splash ul.img").jqGalScroll({
		direction: "horizontal"
		, ease: "easeInOutQuint"
		, width: 420
		, height: 280
		, speed: 1000
		, titleOpacity: 1
	});
	if ($("#splash ul.img li").length > 1) {
		$("a.btn_prev, a.btn_next").click(function(){
			var maxIndex = $("#splash .jqGSPagination li").length - 1;
			var selIndex = $("#splash .jqGSPagination li a").index($(".jqGSPagination li a.selected")[0]);
			var inc = ($(this).is(".btn_prev")) ? -1 : 1;
			selIndex += inc;
			if (selIndex < 0) selIndex = maxIndex;
			if (selIndex > maxIndex) selIndex = 0;
			$("#splash .jqGSPagination li a").eq(selIndex).click();
			$("#splash .caption").text($(".jqGSTitle").eq(selIndex).text());
			updatePhotoCaption(selIndex);
		});
	} else {
		$("a.btn_prev, a.btn_next").hide();
	}
	
	function updatePhotoCaption(selIndex) {
		$("#splash .caption").hide().text($(".jqGSTitle").eq(selIndex).text()).fadeIn(500);
	}
	


	// add video
	$("a[class^='video_']").click(function(){
		var onOpenFn = (!($.browser.msie)) ? simplemodalOpen : null;
		var onCloseFn = (!($.browser.msie)) ? simplemodalClose : null;
		$.modal('<div>\
				<object width="116" height="87"><param name="movie" value="http://www.youtube.com/v/PyLj0mzxDVU&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/PyLj0mzxDVU&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>\
				<cite><span class="name">Doug Kohl</span> <span class="title">President/CEO, Akron Area YMCA</span></cite>\
			</div>', {
			containerId: "modalContainer_video"
			, opacity: 67
			, onOpen: onOpenFn
			, onClose: onCloseFn
		});

	});
	function simplemodalOpen (dialog) {
		dialog.overlay.fadeIn('normal', function () {
			dialog.container.fadeIn('normal', function () {
				dialog.data.hide().slideDown('normal');	 
			});
		});
	}
	function simplemodalClose (dialog) {
		dialog.data.fadeOut('normal', function () {
			dialog.container.hide('normal', function () {
				dialog.overlay.slideUp('normal', function () {
					$.modal.close();
				});
			});
		});
	}
	
	
	
	// stretch the shorter columns' heights to match that of the longest
	var hLongestColumn = Math.max($("#primary").height(), $("#secondary").height());
	$("#primary, #secondary").each(function(i){
		var hThisColumn = $(this).height();
		if (hThisColumn < hLongestColumn) {
			$(this).height(hLongestColumn);
		}
	});



});

