$(function () {
	// General-purpose code for showing and hiding modals
	var activeClass = 'modal-active';
	var $overlays = $('.modal-foreground, .modal-background');
	$('.modal').each(function () {
		var $this = $(this);	
		var $target = $('a[href=#' + $this.attr('id') + ']');
		$target.click(function (ev) {
			ev.preventDefault();
			$overlays.addClass(activeClass);
			$this.addClass(activeClass);
		});
	});
	function closeModals (ev) {
		if (ev && ev.target !== this) return;
		$('.' + activeClass).removeClass(activeClass);
	}
	$('.modal-foreground, .modal-close').click(closeModals);
	$(window).keyup(function (ev) {
		if (ev.keyCode === 27) closeModals(); // Esc
	});

	// Special-purpose code for individual modal behaviour
 	$embedCode = $('#embed-code');
	$(Z).on('Z:statechange ready', function () {
		$embedCode.val($embedCode.val().replace(/src=".*?"/, 'src="' + window.location + '"'));
	});
	$embedCode.focus(function () { $embedCode.select(); });
});

@@ -765,47 +765,32 @@
 );%0A%09
-$(Z).on('Z:statechange ready', function
+function updateEmbedCode
  () 
@@ -879,24 +879,92 @@
  + '%22'));%0A%09%7D
+%0A%09$(Z).on('Z:statechange ready', updateEmbedCode);%0A%09updateEmbedCode(
 );%0A%09$embedCo

Fix embed code not updating on page load