/*
    inpia.js - Custom javascript for the site. Heavily based on the wonderful Galleria demo
               at http://devkick.com/lab/galleria/demo_01.htm
*/

jQuery(function($) {
	$('.photos_unstyled').addClass('photos'); // adds new class name to maintain degradability
		
  $('ul.photos').galleria({
    history: false,
    insert: '#large_image',
  	onImage: function(image, thumb) { 
    	// Fade in the image
  		image.css('display','none').fadeIn(500);
  		// Thumbnail container
  		var _li = thumb.parents('li');
  		// Fade out inactive thumbnail
  		_li.siblings().children('img.selected').fadeTo(500, 0.7);
  		// Fade in active thumbnail
  		thumb.fadeTo('fast', 1).addClass('selected');
  		// add a title for the clickable image
  		image.attr('title','Next image >>');
  	},
	
  	onThumb : function(thumb) { // Thumbnail
  		// fetch the thumbnail container
  		var _li = thumb.parents('li');
  		// if thumbnail is active, fade all the way.
  		var _fadeTo = _li.is('.active') ? '1' : '0.7';
  		// fade in the thumbnail when finnished loading
  		thumb.css({display:'none',opacity:_fadeTo}).fadeIn(500);
  		// hover effects
  		thumb.hover(
  			function() { 
  			  thumb.fadeTo('fast', 1); 
  			},
  			function() { 
  			  _li.not('.active').children('img').fadeTo('fast', 0.7); // don't fade out if the parent is active
  			} 
  		)
  	}
  });
});

