var FromFlash = {
	order: function () {
		location.href = '#shop';
	}
};

$(function () {
	$('#flash-hero').flash({
		src: '/swf/pilot_micro_animation_cropped_4.swf',
		width: 560,
		height: 400,
		wmode: 'transparent',
		bgcolor: '#041229'
	});
	$('#flash-video').flash({
		src: '/swf/jwplayer.swf',
		width: 328,
		height: 258,
		allowfullscreen: true,
		wmode: 'transparent',
		flashvars: {
			autostart: true,
			fullscreen: true, 
			image: '/flv/small.flv.jpg',
			file: '/flv/small.flv'
		}
	});
});

$(function () {
	var overlayColor = '#000',
		overlayOpacity = 0.6;
	 $("#fancy-360").fancybox({
	 	frameWidth: 500,
	 	frameHeight: 505,
	 	overlayColor: overlayColor,
	 	overlayOpacity: overlayOpacity
	 });
	 $("#fancy-photos").fancybox({
	 	frameWidth: 660,
	 	frameHeight: 500,
	 	overlayColor: overlayColor,
	 	overlayOpacity: overlayOpacity
	 });
	 $("#fancy-holiday-special").fancybox({
	 	frameWidth: 500,
	 	frameHeight: 250,
	 	overlayColor: overlayColor,
	 	overlayOpacity: overlayOpacity
	 });
});

$(function () {
	var squish;
	squish = new Squish({
		item: '#pilot-features-squish li',
		heading: '.pilot-features-squish-heading',
		content: '.pilot-features-squish-content',
		openClass: '.pilot-features-squish-open',
		transitions: {
			open: function () {
				// to-do: put a lil' "collapse" icon on the open pane
				$('.pilot-features-squish-heading', this).animate({
					opacity: 0
				}, 200);
			},
			close: function () {
				$('.pilot-features-squish-heading', this).animate({
					opacity: 1
				}, 300);
			}
		}
	});
});

$(function () {
	var slider, playPause, handle,
		frames, pos, max, direction, delay,
		update, play, pause, toggle, next, interval;
	
	update = function () {
		var i;
		for (i = 0; i < frames.length; i += 1) {
			$(frames[i]).css({
				display: i === pos ? 'block' : 'none'
			});
		}
	};
	
	next = function () {
		pos += direction;
		if (pos > max) {
			pos = max;
			direction = -1;
		}
		if (pos < 0) {
			pos = 0;
			direction = 1;
		}
		slider.slider('value', pos);
		update();
	};
	
	play = function () {
		if (!interval) {
			interval = setInterval(next, delay);
		}
		playPause.addClass('pilot-swivel-pause');
		playPause.removeClass('pilot-swivel-play');
	};
	
	pause = function () {
		if (interval) {
			clearInterval(interval);
			interval = 0;
		}
		playPause.addClass('pilot-swivel-play');
		playPause.removeClass('pilot-swivel-pause');
	};
	
	toggle = function () {
		if (interval) {
			pause();
		} else {
			play();
		}
	};
	
	playPause = $('#pilot-swivel-play-pause');
	frames = $('#pilot-swivel-frames li');
	pos = Math.floor(frames.length / 2);
	max = frames.length - 1;
	direction = 1;
	delay = 100;
	
	slider = $("#pilot-swivel-slider").slider({
		min: 0,
		max: max,
		value: pos,
		slide: function (event, ui) {
			pos = ui.value;
			pause();
			update();
			handle.blur();
		}
	});

	handle = $('#pilot-swivel-slider a')[0];
	
	playPause.mousedown(toggle);
	
	$('#pilot-swivel-frames').mousedown(toggle);
	
	update();
	pause();
	
});

