jQuery(function($) {
	$('html')
		.removeClass('no-js')
		.noisy({
			opacity: 0.03,
			monochrome: false
		});

	/**
	 * http://justinhileman.info/article/a-jquery-widont-snippet/
	 */
	$('h1, h2, h3, li, p').each(function() {
			var $this = $(this);
			var widont = $this.html().replace(/\s([^\s<]{0,10})\s*$/, '&nbsp;$1');
			$this.html(widont);
		});

	$('a.map').fancybox({
		type: 'image',
		titlePosition: 'inside',
		titleFormat: function(title, group, index) {
			var $this = $(group[index]);
			var addr  = $this.closest('dd').find('address').text();

			var link = $('<a target="_blank"></a>')
				.attr('href', $this.attr('directions'))
				.html('directions to '+ addr);

			var info = $('<p class="directions"></p>')
				.html('Need <a>directions</a>?')
				.find('a')
				.replaceWith(link)
				.end();

			info = info.wrap('<div id="fancybox-title-inside"></div>');
			info = info.wrap('<div></div>');

			return info.html();
		}
	});

	$('form dd.error').each(function() {
		var $this = $(this);
		$this.prev('dd').find(':input').addClass('error');
	});

	$('form a.confirm').click(function() {
		return confirm('This action cannot be undone.\n\nContinue?');
	});
});

