$(document).ready(function() {
	// show gallery
	$("div.folio-image img").show();
	$("div#gallery-navigation").show();
	// add gallery wrappers
	$('div.folio-image').wrapAll('<div id="folio-gallery"></div>').wrapAll('<div id="folio-gallery-wrapper"></div>');
	
	if(document.URL.match(/#[0-9]+/)) Gallery.gotoImage(new Number(new String(document.URL.match(/#[0-9]+/)).replace("#", "")) - 1);
	else Gallery.updateCount(0);
	
	// attach events
	$('a#next-image').click(function() {
		Gallery.next();
		this.blur();
		return false;
	});	
	$('a#previous-image').click(function() {
		Gallery.previous();
		this.blur();
		return false;
	});
	
	// hide secondary paragraphs (if any exist)
	if($("div.folio-description p").length > 1) {
		$("div.folio-description p").not("p:eq(0)").hide();
		$("div.folio-description p:eq(0)").append('<a href="#" class="read-more">&raquo; more</a>')
		// hide/show events
		$("div.folio-description p").click(function(e) {
			if(e.target.className !== "read-more") return;

			if($(e.target).text().match(/more/)) {
				$("div.folio-description p").not("p:eq(0)").show(300);
				$(e.target).html("&laquo; less");
			} else {
				$("div.folio-description p").not("p:eq(0)").hide(300);
				$(e.target).html("&raquo; more");
			}

			this.blur();
			return false;
		});
	}
});