jQuery(document).ready(function($){	
	
	/**
	 * Vertical alignment
	 * @see http://www.seodenver.com/simple-vertical-align-plugin-for-jquery/
	 */
	 $.fn.center = function() {
		return this.each(function(i){
			var ah = $(this).height();
			var ph = $(this).parent().height();
			var mh = (ph - ah) / 2;
			if ( mh < 0 ) {
				mh = 0; // prevent negative margins
			}
			
			$(this).css('margin-top', mh);
			$(this).css('display', 'block');
			$(this).css('margin-left', 'auto');
			$(this).css('margin-right', 'auto');
		});
	};
	
	/**
	 * Get the urls for the big images, create a container, and insert the images
	 */
	 $('.ngg-galleryoverview').each(function() {
		var links = $(this).find('.ngg-gallery-thumbnail a');
		if ( links.length > 0 ) {
			$(this).prepend('<div class="simple-slide"></div>');
			var slide = $(this).find('.simple-slide');
			$.each( links, function( index, val ) {
				$(slide).append('<div class="slide"><img src="' + val + '" /></div>')
			});
		}
	});
	
	// Add "alias" classes that will only be present if javascript is available
	$('.ngg-gallery-thumbnail-box').addClass('slide');
	$('.simple-slide .slide .ngg-gallery-thumbnail').center();
	$('#sponsors a img').center();
	
	/**
	 * Fire up the cycle
	 */
	$('.simple-slide').cycle({
		slideExpr: '.slide',
		fx:     'fade', 
	    speed:  1200,
	    delay:	1000,
	    timeout: 6000,
	    cleartypeNoBg: true
	}); 
	
	$('#sponsors').cycle({
		fx:'scrollUp',
		speed: 200,
		cleartypeNoBg: true
	});
	
	/**
	 * Hide the NextGen gallery thumbnails
	 */
	$('.ngg-gallery-thumbnail-box').hide();


});
