﻿/* UI scripts that appear on all or almost every page */

// Uses http://jQuery.com

$(document).ready(function() {

	// Toggle instructions panel
    $('.press').removeClass('open');
    $('.press > h3').click(function() {
        var open = $(this).siblings('div').is(':visible');
        if (open) {
            $(this).parent().removeClass('open');
        }
        else {
            $(this).parent().addClass('open');
        }
    });
    $('#subnav>li:last-child').addClass('last-child');
    
    $('a.locationMap').nyroModal({
        endShowContent: function(elts, settings) {
			var modalheight = $('#nyroModalContent').height();
			var captionheight = $('#nyroModalContent div.address-bar').height();
			var image = $('#nyroModalContent img');
			var imgheight = 540;
			var imgwidth = 700;
			var yspace = modalheight - (imgheight + captionheight);
			
			// if modal does not fit in window
			if(yspace < 0)
			{
				var scaledimgheight = imgheight + yspace;
				var scaledimgwidth = scaledimgheight * (imgwidth/imgheight);
				image.animate({
					height: scaledimgheight,
					width: scaledimgwidth
				});
			}
        }
    });
    
    $('a.detailImage').nyroModal();
});

