/* Author: Matt Senior <http://mattsenior.com/> */
$(document).ready(function() {
	$('input').add('textarea').addPlaceholder();

	var play = $('section.download-prospectus a.play');
	var pause = $('section.download-prospectus a.pause');
	var slideshow = $('section.download-prospectus .slideshow');

	pause.click(function() {
		slideshow.cycle('pause');
		pause.hide();
		play.show();
		return false;
	});
	play.click(function() {
		slideshow.cycle('resume');
		play.hide();
		pause.show();
		return false;
	});
});

$(window).load(function() {
	imgSizer.collate();

	var oldWindowWidth = document.documentElement.clientWidth;
	var newWindowWidth = 0;
	var mediaThreshold = 991;

	$(window).resize(function() {
		newWindowWidth = document.documentElement.clientWidth;
		if ((oldWindowWidth <= mediaThreshold && newWindowWidth  > mediaThreshold) ||
			(oldWindowWidth  > mediaThreshold && newWindowWidth <= mediaThreshold))
		{
			oldWindowWidth = newWindowWidth;
			init_cycle();
		}
	});

	init_cycle();
});

function init_cycle()
{
	var slideshow = $('section.download-prospectus .slideshow');
	slideshow.hide().cycle('destroy').children('div').attr('style', '');
	slideshow.show().cycle({
		timeout: 5000,
		speed: 2000
	});
	$('section.download-prospectus a.pause').fadeIn();
}

