
$(function() {
	var $test1 = $('#test1'),
		$test2 = $('#test2'),
		$slideshow = $('#slideshow'),
		$caption = $('div.caption'),
		$pause = $('#pause'),
		$resume = $('#resume'),
		$freeze = $('#freeze'),
		$stop = $('#stop'),
		$restart = $('#restart'),
		captions = ['Sand Castle', 'Sunflower', 'Flip Flops', 'Rubber Ring'],
		STOP = 1, RUN = 2, PAUSE = 3;



	$slideshow.crossSlide({
		fade: 1
	}, [
		{
			src:  'http://ccm.bigdevelopment.com/wp/wp-content/themes/ccmtheme/images/1.jpg',
			from: '100% 100% 1x',
			to:   'top left 1x',
			time: 4
		}, {
			src:  'http://ccm.bigdevelopment.com/wp/wp-content/themes/ccmtheme/images/2.jpg',
			from: 'top left',
			to:   'bottom right 1x',
			time: 4
		}, {
			src:  'http://ccm.bigdevelopment.com/wp/wp-content/themes/ccmtheme/images/1.jpg',
			from: '100% 100% 1x',
			to:   'bottom left 1.1x',
			time: 4
		}, {
			src:  'http://ccm.bigdevelopment.com/wp/wp-content/themes/ccmtheme/images/2.jpg',
			from: 'bottom left',
			to:   'top right 1x',
			time: 4
		}
	], function(idx, img, idxOut, imgOut) {
		if (idxOut == undefined) {
			$caption.text(captions[idx]).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() {
		$slideshow.crossSlidePause();
		state(PAUSE);
	});

	$resume.click(function() {
		$slideshow.crossSlideResume();
		state(RUN);
	})

	$freeze.click(function() {
		$slideshow.crossSlideFreeze();
		state(STOP);
	});

	$stop.click(function() {
		$slideshow.crossSlideStop();
		$caption.css({ opacity: 0 })
		state(STOP);
	});

	$restart.click(function() {
		$slideshow.crossSlideRestart();
		state(RUN);
	});
	
});



