jQuery(document).ready(function() {

	// Alter the Media Library Gallery plugin.
	var gallery = jQuery('div.media-library-gallery');
	gallery.find('div.mlg-preview').each(function() {

		// Make image links into Thickbox popup links (rather than links to image pages).
		var imagePath = jQuery(this).find('div.mlg-title a').attr('href');
		jQuery(this).find('div.mlg-img a').addClass('thickbox').attr('href', imagePath);

		// Rewrite the title caption to include line breaks and remove the link (and unwanted quotes as a side effect).
		var captionLink = jQuery(this).find('div.mlg-actions a');
		var title = captionLink.html();
		captionLink.parent().html(title.replace(/ \| /g, '<br />'));

		// Set Thickbox title to match the above.
		jQuery(this).find('div.mlg-img a').attr('title', title);
	});

	// Remove gallery pages from the menu.  (We run these down our own sidebar.)
	var menu = jQuery('div#masthead div.menu');
	menu.find('li.page_item a[title~=Gallery:]').parent().hide();

	// Insert dividers between items and reveal the menu.
	var menuLinks = menu.find('li a[title!=Home]');
	menuLinks.before('<span style="float: left;">&nbsp; | &nbsp;</span>');
	menu.css('visibility', 'visible');

	// If we're on a gallery page...
	var url = window.location.href;
	var pattern = 'gallery-';
	if (url.indexOf(pattern) > -1) {

		// Highlight the active gallery in the "Explore" sidebar.
		var regex = new RegExp('^.*' + pattern);
		var gallerySlug = url.replace(regex, pattern);
		jQuery('ul#explore li a[href*=' + gallerySlug + ']').parent().addClass('current_page_item');

		// Remove the left-border.
		jQuery('div#wrapper div#main div#container').css('border-left', '0');

	// ... otherwise reveal the page title hidden by CSS unless we're home.
	} else {
		jQuery('h1.entry-title').not(':contains("Home")').css('display', 'block');
	}

	// Remove the title from the billboard image, and remove its surrounding link.
	billboard = jQuery('div#content div.entry-content img[title=billboard]').removeAttr('title');
	billboardLink = billboard.parent('a');
	billboardLink.parent().append(billboardLink.html());   // (.unwrap() apparently is too new for WordPress.)
	billboardLink.remove();

	// Help out the CSS a bit re: the contact form.
	jQuery('div.entry-content form input[type="text"]').addClass('text');
});



