$(document).ready(function() {
});

// Function called on all pages
function pageClose() {	
	$("#video_home").click(function() {
			$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'			: 400,
				'height'		: 300,
				'href'			: this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
				'type'			: 'swf'
			});
			return false;
		});
	
	// jQuery placeholders for older browsers
	$('input,textarea').placeholder();
	// fancybox for all links with a ".fancy" class
	$('a.fancy').fancybox();
	// fancybox for videos (add a ".video" class to link)
	$('a.project').fancybox({
			'padding': 0,
			'width': 880,
			'height': 520,
			'type':'iframe',
			'titleShow':false
	});
	// fancybox for references (table)
	$('a.readmore').fancybox({
			'padding': 10,
			'width': 910,
			'height': 580,
			'type':'iframe',
			'titleShow':false,
			'scrolling':'auto'
	});
	// scroll to top
	$('a[href=#header]').click(function(){$('html,body').animate({scrollTop:0},'slow');return false;});
	
	$("a[rel=book_photos]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
}
function popupClose() {
	
	// Project slideshow
	var toggle = $('#navpause').click(function() {
		var paused = slideshow.is(':paused');
		slideshow.cycle(paused ? 'resume':'pause',true);
	});
	function onAfter(curr,next,opts) {
        var caption = $(next).find('figcaption').html();
        $('#caption').html(caption);
    }
	var slideshow = $('#slideshow ul').cycle({
		timeout:4000,
		pause:false,
		fx:'fade',
		speed:500,
		timeout: 0,
		next:'#navnext',
		prev:'#navprev',
		// paused:function(cont,opts,byHover){!byHover && toggle.html('Resume');},
		resumed:function(cont,opts,byHover){!byHover && toggle.html('Pause');},
		after:onAfter
	});
	
	$('#slideshow ul li').show(); 
	
}
