$(function(){
	$("td.aircraft").each(function(){
		var speed = 500,
			easing = 'easeOutQuart',
			td = $(this),
			img = $(".photo", td);
		
		td.hover(function(){
			img.stop().animate({
				width: 334
			}, speed, easing)
		},function(){
			img.stop().animate({
				width: 73
			}, speed, easing)
		});
	});
	
	// setup homepage widget
	
	$(".fancybox").fancybox({
		transitionIn: 'elastic',
		transitionOut: 'elastic',
		easingIn: 'easeOutQuint',
		easingOut: 'easeOutQuint',
		titlePosition: 'over'
	});
});


$.preview = {
	current: 0,
	items: null,
	setup: function(){
		var p = $(".preview");
		this.items = $(".item", p);
		this.menu_items = $(".main_nav a");

		$(".main_nav li").mouseover(function(e){
			var index = $(this).prevAll().length;
			$.preview.show(index);
		});
		this.menu_items.eq(0).addClass('active');
		$(".prev", p).click(function(e){
			e.preventDefault();
			$.preview.prev();
		});
		$(".next", p).click(function(e){
			e.preventDefault();
			$.preview.next();
		});
	},
	show: function(index){
		if (this.current && this.current == index) {
			return;
		}
		
		this.items.eq(this.current).fadeOut();
		this.current = index;
		this.items.eq(index).fadeIn();
		this.highlightMenuItem(index);
	},
	next: function(){
		if (this.current < this.menu_items.length-1) {
			this.show(this.current+1);
		}
		else {
			this.show(0);
		}
	},
	prev: function(){
		if (this.current > 0) {
			this.show(this.current-1);
		}
		else {
			this.show(this.menu_items.length-1);
		}
	},
	highlightMenuItem: function(index){
		$(".main_nav a").removeClass('active').eq(index).addClass('active');
	}
};
