$(function() {
	var $swf1 = $('#swf1'),
		$caption = $('div.caption'),
		$pause = $('#pause'),
		$resume = $('#resume'),
		$freeze = $('#freeze'),
		$stop = $('#stop'),
		$restart = $('#restart'),
		STOP = 1, RUN = 2, PAUSE = 3;

	$swf1.crossSlide({
		fade: 1
	}, [
		{
			src:  'img/Home/pict0001.jpg',
			alt: 'Fun for the whole family',
			from: 'bottom left 1.1x',
			to:   'top right 1.0x',
			time: 8
		}, {
			src:  'img/Home/pict0213.jpg',
			alt: 'Private lessons island-wide',
			from: 'bottom left 1.0x',
			to:   'top right 1.0x',
			time: 8
		}, {
			src:  'img/Home/pict0011.jpg',
			alt: 'Small classes at great rates',
			from: 'bottom left 1.2x',
			to:   'top right 1.0x',
			time: 8
		}, {
			src:  'img/Home/pict0112.jpg',
			alt: 'Gain confidence in the surf',
			from: 'bottom left 1.2x',
			to:   'top right 1.0x',
			time: 8
		}, {
			src:  'img/Home/pict0084.jpg',
			alt: 'Catch a wave in no time',
			from: 'bottom left 1.2x',
			to:   'top right 1.2x',
			time: 8
		}, {
			src:  'img/Home/pict0206.jpg',
			alt: 'Most classes in beautiful Hanalei Bay',
			from: 'bottom left 1.2x',
			to:   'top right 1.2x',
			time: 8
		}
	], function(idx, img, idxOut, imgOut) {
		if (idxOut == undefined) {
			$caption.text(img.alt).animate({ opacity: .7 })
		} else {
			$caption.animate({ opacity: 0 })
		}
	});
	$caption.show().css({ opacity: 0 })

	function state(state) {
		$pause.attr('disabled', state != RUN);
		$resume.attr('disabled', state != PAUSE);
		$freeze.attr('disabled', state == STOP);
		$stop.attr('disabled', state == STOP);
	}
	state(RUN);

	$pause.click(function() {
		$swf1.crossSlidePause();
		state(PAUSE);
	});

	$resume.click(function() {
		$swf1.crossSlideResume();
		state(RUN);
	})

	$freeze.click(function() {
		$swf1.crossSlideFreeze();
		state(STOP);
	});

	$stop.click(function() {
		$swf1.crossSlideStop();
		$caption.css({ opacity: 0 })
		state(STOP);
	});

	$restart.click(function() {
		$swf1.crossSlideRestart();
		state(RUN);
	});
});

