var openNav = null;

$(document).ready(function() {	
	$("#navigation #nav li").mouseover(function()
	{
		var subnav_id = $(this).attr('id').replace('bttn-', '') + '-subnav';
		
		toggleNav(subnav_id, false);
	});
	
	$('#navigation #nav li a').mouseover(function()
	{
		$(this).css('background-position', 'bottom left');
	});
	
	$("#navigation #nav li").mouseout(function()
	{
		var subnav_id = $(this).attr('id').replace('bttn-', '') + '-subnav';
		
		toggleNav(subnav_id, true);
	});
	
	$('#navigation #nav li a').mouseout(function()
	{
		$(this).css('background-position', 'top left');
	});

	$("#navigation .subnav").mouseover(function()
	{
		$(this).stop();
		$(this).css('top', '54px');
		openNav = $(this).attr('id');
		
		var bttn_id = 'bttn-' + $(this).attr('id').replace('-subnav', '');
		$('#' + bttn_id + ' a').css('background-position', 'bottom left');
	});
	
	$("#navigation .subnav").mouseout(function()
	{
		toggleNav($(this).attr('id'), true);
		
		var bttn_id = 'bttn-' + $(this).attr('id').replace('-subnav', '');

		$('#' + bttn_id + ' a').css('background-position', 'top left');
	});
	
	// hide faq tabs
	$('.faq-tab').hide();
	$('.faq-tab:first').show();
});

function toggleNav(id, close)
{
	if (id == openNav && close == false)
	{
		$('#' + id).stop();
		$('#' + id).css('top', '54px');
		
		return;
	}
	
	if (openNav != null && id != openNav)
	{		
		// close the open sub nav item
		$('#' + openNav).animate({
			top: '25px'
		}, 'fast');
		
		openNav = null;
	}
	
	if (close == true)
	{
		// close the nav
		$('#' + openNav).animate({
			top: '25px'
		}, 'fast');
		
		openNav = null;
	}
	else
	{
		// slide it open
		$('#' + id).animate({
			top: '54px'
		}, 'fast');
		
		openNav = id;
	}
	
	return;
}

function changeTab(link, id)
{
	$("ul.tabs li").removeClass('selected');
	
	$($(link).parent()).addClass('selected');
	
	$('.faq-tab').hide();
	
	$('#' + id + '-tab').show();
}