$(document).ready(function() {
	
	$('.hide').hide();
	$('.show').show().css({display: 'block'});	
	
	// Main Navigation
	var $selectedNav = $('#navigation .selected');
	$selectedNav.next('.spacer').css({ backgroundPosition: '0 -108px' });
	$selectedNav.prev('.spacer').css({ backgroundPosition: '0 -108px' });
	
	$('#navigation a').hover(
		function() {
			var $selectedNav = $(this).parent();
			$selectedNav.next('.spacer').css({ backgroundPosition: '0 -108px' });
			$selectedNav.prev('.spacer').css({ backgroundPosition: '0 -108px' });
			
			if($selectedNav.next().next().hasClass('selected')) { $selectedNav.next('.spacer').css({ backgroundPosition: '0 -54px' }); }
			if($selectedNav.prev().prev().hasClass('selected')) { $selectedNav.prev('.spacer').css({ backgroundPosition: '0 -54px' }); }
		},
		function() {
			var $selectedNav = $(this).parent();
			$selectedNav.next('.spacer').css({ backgroundPosition: '0 0' });
			$selectedNav.prev('.spacer').css({ backgroundPosition: '0 0' });
			
			var $selectedNav = $('#navigation .selected');
			$selectedNav.next('.spacer').css({ backgroundPosition: '0 -108px' });
			$selectedNav.prev('.spacer').css({ backgroundPosition: '0 -108px' });
		}
	);

	// New window
	$('#twitter-feed a, a.newWindow').click(function() {
		window.open($(this).attr('href'), 'twitter');
		return false;
	});

	// Newsletter signup form
	$('#newsletter-signup .input input').focus(function() {
		$input = $(this);
		if($input.val() == $input.attr('title')) { $input.val(''); }
		if($input.hasClass('error')) { $input.removeClass('error'); }
	});
	
	$('#newsletter-signup .input input').blur(function() {
		$input = $(this);
		if($input.val() == '') { $input.val($input.attr('title')); }
	});

	// Homepage text
	$('#intro-text')
		.children(':first-child')
		.append('&nbsp;&nbsp;&nbsp;<a href="#" id="intro-read-more">Read more ></a>')
		.next()
		.hide()
		.css({paddingTop: '0'})
		.append('&nbsp;&nbsp;&nbsp;<a href="#" id="intro-read-again">Read again ></a>');

	$('#intro-read-more').click(function() {
		$(this).parent().hide().next().show();
		return false;
	});
	
	$('#intro-read-again').click(function() {
		$(this).parent().hide().prev().show();
		return false;
	});
	
	// Staff and Qualifications
	$('#staff-list').addClass('enabled');
	$('#staff-list .image').append('<div class="opacity-overlay"></div>');
	
	$('#staff-list .image').hover(
		function() { 
			$link = $(this);
			$link.children('div').hide();
			$link.css({backgroundPosition: 'bottom left'}).next().show(); 
		},
		function() { 
			$link = $(this);
			$link.children('div').show();
			$link.css({backgroundPosition: 'top left'}).next().hide(); 
		}
	);
	
	// Corporate Systems / Our Gym / Classes
	$('#corp-list .information, #gym-list .information, #class-list .information').hide();
	
	$('#corp-list .statement, #gym-list .statement, #class-list .link').click(function() {
	
		$clickedInfo = $(this).next();
		$openInfo = $clickedInfo.parent().parent().children().children('.selected');
		
		if($clickedInfo.is(':visible'))
		{
			$openInfo.removeClass('selected').slideUp();
		}
		else
		{
			$openInfo.removeClass('selected').slideUp();
			$clickedInfo.addClass('selected').slideDown();
		}
	});
	
	// FAQs
	$('#faqs-list .answer').hide();
	
	$('#faqs-list .question').click(function() {
	
		$clickedInfo = $(this).next();
		$openInfo = $('#faqs-list .selected');
		
		if($clickedInfo.is(':visible'))
		{
			$openInfo.removeClass('selected').slideUp();
		}
		else
		{
			$openInfo.removeClass('selected').slideUp();
			$clickedInfo.addClass('selected').slideDown();
		}
	});
	
	// Blog form fields
	$inputSelectors = $('#comment-name, #comment-email, #comment-url');
	$inputSelectors.each(function() { $this = $(this); if($this.val() == '') { $this.val($this.attr('title')); } });
	$inputSelectors.focus(function() { $this = $(this); if($this.val() == $this.attr('title')) { $this.val(''); } });
	$inputSelectors.blur(function() { $this = $(this); if($this.val() == '') { $this.val($this.attr('title')); } });
	
	// Personal Trainers Testimonials
	$('#right-section .links a').click(function() {
		$button = $(this);
		var value = parseInt($button.html());
		var parentId = $button.parent().parent().parent().attr('id');
		
		$("#"+parentId+" .selected").removeClass('selected');
		$("#"+parentId+" img[rel='image"+value+"']").addClass('selected');
		$button.addClass('selected');
		
		return false;
	});
	
});