// Title: Nic Plowman v2 - javascript
// Author: Kalon Edser, http://www.kalonedser.com/
// Updated: 12 May 2010

jQuery(document).ready(function() {

	$('body').addClass('js');


	// global
	var fadespeed = 0;
	var halfspeed = fadespeed / 2; // half transition speed

	// submenu navigation hover
	$('.nav li').hover(
	  function () {
		$(this).find("ul").stop(false,true).hide().show(); // "slide", { direction: "up", duration: 300 }
	  },
	  function () {
		$(this).find("ul").stop(false,true).show().hide();
	  }
	);
	
	// last thumbnail
	$('#thumbnails li:last').addClass('last');
	
	// vertical align artwork images
	$.fn.vAlign = function() {
		return this.each(function(i){
		var ah = $(this).height();
		var ph = $(this).parent().height();
		var mh = (ph - ah) / 2;
		$(this).css('margin-top', mh);
		});
	};
	
	$('.valign img').vAlign();
	
	// artwork caption
	function caption() { 
		var thiscaption = $(this).find('.caption').html();
		$('#artwork-caption').fadeOut(halfspeed, function () {
		 	$(this).html(thiscaption).fadeIn(halfspeed);
		});
	};

	// artwork display
	$('#artwork-images').cycle({ 
		fx: 'fade', 
		speed: fadespeed, 
		timeout: 0,
		pause: 1,
		pager: '#thumbnails',
		before: caption, 
		pagerAnchorBuilder: function(idx, slide) { 
		    // return selector string for existing anchor 
		    return '#thumbnails li:eq(' + idx + ') a'; 
		} 
	});
	
	// pretty photo
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		opacity: 0.80, /* Value between 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: false, /* true/false */
		default_width: 800,
		default_height: 500,
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_square' /* light_rounded / dark_rounded / light_square / dark_square / facebook */
	});

	$('.print a').click(function() {
		window.print();
		return false;
	});

	// open new window for external links
	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });

});
