var numSectionsToExpand = 1;
Shadowbox.init({
	skipSetup: true,
	handleOversize: 'none',
	viewportPadding: 1,
	overlayOpacity: '0.9'
});

(function($){
	$(document).ready(function(){
		setupTopNav();
		setupContentShadow();
		setupContentSections();
		$(window).resize(function() {
			windowChanged();
        });
		$('#print').click(function(){
			window.print();
			return false;
		});
		$('a.explore-huts').click(function() {
			Shadowbox.open({
				content: '/gallery',
				player: 'iframe',
				height: 600,
				width: 830
			});
			return false;
		});
		$(':text').example(function() {
			return $(this).attr('title');
		}, {className: 'example-text'});
		$('h2:first', 'div.blog-content').width('430px');
//		$('a.explore-huts').fancybox({
//			href: '/gallery',
//			type: 'iframe',
//			height: 600,
//			width: 830,
//			margin: 0,
//			padding: 0,
//			overlayColor: '#000',
//			overlayOpacity: '0.8'
//		});
    });
	function setupTopNav() {
		$('#top-nav ul:first').children().each(function(i) {
			var li = $(this);
			var id = li.attr('id');
			li.hover(
				function() {
					$('img:first', li).attr('src', topLinks[i].hover);
					li.addClass('hover');
				},
				function() {
					$('img:first', li).attr('src', topLinks[i].current);
					li.removeClass('hover');
				}
			);
		});
	}
	function setupContentShadow() {
		$('#content-shadow').height($('#content-wrapper-interior').height());
	}
	function windowChanged() {
		setupContentShadow();
	}
	function setupContentSections() {
		$('.section-heading').each(function(i) {
			var heading = $(this);
			var text = heading.html();
			heading.html('<div class="section-heading-sign"></div><div class="section-heading-text">' + text + '</div><div class="clear"></div>');
			var sign = $('div.section-heading-sign', heading);
			
			var content = heading.next();
			var status;
			if (i < numSectionsToExpand) {
				status = 'opened';
				sign.html('[&ndash;]');
			} else {
				status = 'closed';
				sign.html('[+]');
				content.hide();
			}
			heading.click(function() {
				content.slideToggle('fast', function() {
					if (status == 'opened') {
						sign.html('[+]');
						status = 'closed';
					} else {
						sign.html('[&ndash;]');
						status = 'opened';
					}
					windowChanged();
				});
			})
		});
		windowChanged();
	}
})(jQuery);

