$(document).ready(function()
{
	var shadowbox_options = ''; //';options={animate:false}';
	
	//---------------------------------------------START CUSTOM JS//
	
	if(navigator.appVersion.indexOf("Mac")!=-1)
	{
		$('div#content h2').css('fontSize','1.5em');
	}
	
	$('ul#nav li a').each(function()
	{
		switch($(this).attr('title'))
		{
			case 'Sales':
				$(this).attr('title','Aircraft Sales');
			break;
			case 'Consulting':
				$(this).attr('title','General Aviation Consultancy and Advisory Services');
			break;
			case 'Innovations':
				$(this).attr('title','Innovative Product Sales and/or Investment Opportunities');
			break;
			case 'Peter Smales':
				$(this).attr('title','Owner and Managing Director Indigo Lyon Group');
			break;			
		}
	});

	$('div#container div#content div.page.small p.emph').each(function()
	{
		$(this).attr('class','hide');
	});
	
	// Grayscale all overview images
	if(!$.browser.msie)
	{
		var count = 1;
		
		$('div.item img').each(function()
		{
			$(this).attr('id','desaturate'+count);
			
			Pixastic.process(document.getElementById('desaturate'+count), 'desaturate');
			
			count++;
		});
		
		$('div.item a').bind('mouseenter',function()
		{
			var image_id = $(this).children('canvas').attr('id');
			
			if(image_id != 'undefined')
			{
				Pixastic.revert(document.getElementById(image_id));
			}
		}).bind('mouseleave',function()
		{
			var image_id = $(this).children('img').attr('id');
			
			if(image_id != 'undefined')
			{
				Pixastic.process(document.getElementById(image_id), 'desaturate');
			}
		});
	}
	
	// Keep page div and nav the same height
	var page_height = $('div.page').height();
	var nav_height	= $('ul#nav').height();
	
	if(page_height > nav_height)
	{
		$('ul#nav').css('height', (page_height + 8));
	}
	else
	{
		$('div.page').css('height', nav_height - 8);
	}
	
	//---------------------------------------------END CUSTOM JS//
	/*
	$("li.subnav").hover(function()
	{
		$(this).addClass("active");
		
		if($("a.nav_search").hasClass("active"))
		{
			$("a.nav_search").removeClass("active");
			$("form.search").animate({ opacity: 0 }, 250);
			
			search_height_timeout = setTimeout(function()
			{
				$("form.search").css("height","0");
			}, 1000);
		}
	},
	function()
	{
		$(this).removeClass("active");
	});
	*/
	if($("ul#subnav").length > 0)
	{
		if(!$.browser.msie || $.browser.version != 5.5)
		{
			$("ul#subnav").css("display","none");
		}
	}
	
	$('a[rel*="external"]').click(function()
	{
		open($(this).attr('href'));
		return false;
	});
	
	$('a[rel*="shadowbox"]').each(function()
	{
		if(!$(this).hasClass('page_video'))
		{
			var enlarge_img = $(this).attr('rel').split(' ');
			
			if(enlarge_img != 'undefined' && enlarge_img != '')
			{
				$(this).removeAttr('rel');
				
				if(enlarge_img[1] != 'undefined')
				{
					$(this).attr('rel', enlarge_img[1]+shadowbox_options);
				}
				else
				{
					$(this).attr('rel', enlarge_img[0]+shadowbox_options);
				}
			}
		}
	});
	
	$("ul.thumbs li a img").each(function()
	{
		$.preloadImages.add($(this).attr("src").replace("thumb", "mid"));
	});
	
	$("ul.thumbs li a").mouseover(function()
	{
		$("img#full").attr("src", ($(this).attr('href')).replace("full", "mid"));
		$("img#full").attr("alt", ($(this).attr('alt')));
		$("a#enlarge").attr("href", ($(this).attr('href')).replace("thumb", "full"));
		$("a#enlarge").attr("title", ($(this).attr('title')));
	});
	
	$("ul.thumbs li:first a").click(function()
	{
		$("a#enlarge").click();
	});
	
	$("ul.thumbs li a").click(function()
	{
		$("img#full").attr("src", ($(this).attr('href')).replace("full", "mid"));
		$("img#full").attr("alt", ($(this).attr('alt')));
		$("a#enlarge").attr("href", ($(this).attr('href')).replace("thumb", "full"));
		$("a#enlarge").attr("title", ($(this).attr('title')));
		return false;
	});
	
	if($('a.page_video').length > 0)
	{
		var page_video = $('a.page_video').attr('rel').split(' ');
		
		if(page_video != 'undefined' && page_video != '')
		{
			$('a.page_video').removeAttr('rel');
			$('a.page_video').attr('rel', page_video[1]);
		}
	}
	
	if($("li.help a").length > 0)
	{
		$("li.help a").click(function()
		{
			return false;
		});
		
		var help_timeout = 'undefined';
		
		$("li.help a").bind("mouseenter",function()
		{
			if(help_timeout != 'undefined')
			{
				clearTimeout(help_timeout);
			}
			$("li.help div").fadeOut();
			$(this).next().addClass('active').fadeIn();
		}).bind("mouseleave",function()
		{
			help_timeout = setTimeout(function()
			{
				$('li.help div.active').removeClass('active').fadeOut();
			},2000);
		});
		
		$('input').focus(function()
		{
			$('li.help div.active').removeClass('active').fadeOut();
		});
		
		$('select').focus(function()
		{
			$('li.help div.active').removeClass('active').fadeOut();
		});
		
		$('textarea').focus(function()
		{
			$('li.help div.active').removeClass('active').fadeOut();
		});
	}
});
