// Updated 16 Feb 2011.

$(document).ready(function() {
	
	// Show grid. --------------------------------------------------------------------

  var showDiv = location.hash;
  $(showDiv).show();

	// Gallery behaviours. -----------------------------------------------------------
	
	// Variables.
	
	var image = 	$('.work img:first, .posters img:first, iframe');
	var images = 	$(".posters img, .work img, iframe").size();
	
	// Check to see if images exist

	$(image).one("load", function() {
		$('.loading, .loading_poster').fadeOut(400),
		$('.number').fadeIn(400);
	 }).each(function() {
		if (this.complete) $(this).trigger("load");
	});

	// Cycle through div.images.
	  	
	$(function() {
		$(image).fadeIn(200, function() {
			$('.work, .posters').cycle({
				speed:     200,
				timeout:   0,
				prev:      '.previous',
				next:      '.next, .work img, .posters img',
				after: 		 onAfter
			});
			
			$('#description').cycle({
				speed:     00,
				timeout:   0,
				prev:      '.previous',
				next:      '.next, .work img, .posters img',
				cleartype:  1,
				after: 		 onAfter
			});
		});  
	});
	
	function onAfter(curr,next,opts) {
		var caption = (opts.currSlide + 1) + '/' + opts.slideCount;
		$('.number').html(caption);
	}
	
	// Deal with single images
	
	if ((images) == 1) {
		$(".pagination").css("visibility", "hidden");
		$(".description").css("display", "block");
	};	
	// Links in text block open in blank.

	$('#description a[href^=http], #small-text a[href^=http], #large-text a[href^=http]').click(function() {
		window.open(this.href);
		return false;
	});

});
