$(function(){
	
	$('.buying-guide .sub-content div:not(:first)').hide();
	$('.buying-guide .main-content li:first').addClass('selected');
	
	$('.renting-guide .sub-content div:not(:first)').hide();
	$('.renting-guide .main-content li:first').addClass('selected');
	
/*
	$('.contact-us .main-content ul.contact:first').after('<p id="open-map"><a href="#map">view map</a></p>');
	$('.contact-us .sub-content *').hide();
	$('.contact-us .sub-content').removeClass('map');
*/	
	$('.buying-guide .main-content li a').click(function(){
		$('.buying-guide .main-content li').removeClass('selected');
		$(this).parent().addClass('selected');
		var selectedId = $(this).attr('href');
		$(".buying-guide .sub-content div:not('" + selectedId + "')").hide(0);
		$('.buying-guide .sub-content ' + selectedId).fadeIn(700);
		return false;
	});
	
	$('.renting-guide .main-content li a').click(function(){
		$('.renting-guide .main-content li').removeClass('selected');
		$(this).parent().addClass('selected');
		var selectedId = $(this).attr('href');
		$(".renting-guide .sub-content div:not('" + selectedId + "')").hide(0);
		$('.renting-guide .sub-content ' + selectedId).fadeIn(700);
		return false;
	});
	
/*
	$('#open-map a').click(function(){
		$('.contact-us .sub-content').fadeOut(200, function(){
			$('.contact-us .sub-content').addClass('map');
			if ($('.contact-us #close-map').length == 0) {
				$('.contact-us #print-map').after('<a href="" id="close-map">Close</a>');
				$('.contact-us #close-map').hide();
			}
			$('.contact-us .sub-content *').show();
			$('.contact-us .sub-content').fadeIn(300);
			$('#close-map').click(function(){
				$('.contact-us .sub-content').fadeOut(200, function(){
					$('.contact-us .sub-content *').hide(function(){
						$('.contact-us .sub-content').removeClass('map');
						$('.contact-us .sub-content').fadeIn(300);
					});
				});
				return false;
			});
		});
		return false;
	});
*/	
	$('.homes-for-sale .sub-content li>a').mouseover(function(){
		$('.homes-for-sale .sub-content li .container').fadeOut('fast');
		if ($.browser.msie) $(this).siblings('div').show();
		$(this).siblings('div').fadeIn('fast');
		$(this).siblings('div').hover(function(){
		}, function(){
			if ($.browser.msie) $('.homes-for-sale .sub-content li .container').hide();
			$('.homes-for-sale .sub-content li .container').fadeOut('fast');
		});
		return false;
	});
	
	$('.homes-for-sale .main-content li a').hover(function(){
		var infopopId = $(this).attr('rel');
		if ($.browser.msie) $('li#' + infopopId).siblings().children('.container').hide();
		$('li#' + infopopId).siblings().children('.container').fadeOut('fast');
		if ($.browser.msie) $('li#' + infopopId + ' .container').show();
		$('li#' + infopopId + ' .container').fadeIn('fast');
		$('.homes-for-sale .sub-content li').hover(function(){
		}, function(){
			if ($.browser.msie) $('.homes-for-sale .sub-content li .container').hide();
			$('.homes-for-sale .sub-content li .container').fadeOut('fast');
		});
	});
	
	$('#location .lightbox').lightBox();

	if ($('.gallery').length) {
		$('.gallery').jMyCarousel({
			visible: '830px',
			circular: false,
			speed: 300
		});
	
		$('.gallery a').lightBox();
	
		$('.gallery a img').fadeTo(1,0.75);
	
		$('.gallery a img').hover(function() {
			$(this).fadeTo('fast',1);
		},
		function() {
			$(this).fadeTo('fast',0.75);
		}
		);
	}

	$('#frm-directions').submit(function(){
		usePointFromPostcode(this.saddr.value, setDirections);
		return false;
	});

});

