$(document).ready(function() {
	// hover function for inputs and images
	$('.hover').hover(function() {
		$(this).attr('src', $(this).attr('src').replace(/\.(\w{3})/g, "Hover.$1"));
	}, function() {
		$(this).attr('src', $(this).attr('src').replace(/Hover\.(\w{3})/g, ".$1"));
	});

	// finder stuff
	crosss = "/assets/images/core/finder/cross.gif";
	downArrow = "/assets/images/core/finder/down.gif";
	openText = "Click here to open the search bar";
	closeText = "Click here to close to search bar";

	$('#cross, #searchInner h2').addClass('withJs');

	function closeIt() {
		$('#searchInner form').slideUp('fast');
		$('#cross').attr({ src: downArrow, alt: openText }).removeClass('open');
		$.cookie('propertySearch', 'closed');
	}

	function openIt() {
		$('#searchInner form').slideDown('fast');
		$('#cross').attr({ src: crosss, alt: closeText }).addClass('open');
		$.cookie('propertySearch', 'open');
	}

	$('#searchInner h2').addClass('withJs');

	propertySearchOpen = true;

	if ($.cookie('propertySearch') == 'closed') {
		propertySearchOpen = false;

	} // this is brill Dave!

	if (!propertySearchOpen) {
		$('#searchInner form').hide();
		$('#cross').attr('src', downArrow);
	} else {
		$('#cross').addClass('open');
	}

	$('#cross, #searchInner h2').click(function() {
		if ($('#cross').hasClass('open')) {
			closeIt();
		} else {
			openIt();
		}
	});

	$('#galleryWrap').each(function(i) {
		$(this).flash({
			swf: '/assets/swf/imageGallery.swf',
			width: 576,
			height: 486,
			flashvars: {
				xmlSrc: $(this).attr("data-xmlSrc")
			}
		})
	});

	// sign up page

	if ($('#lAll').length) {

		$('#lChoose').attr('checked', 'checked');
		hidden = false;

		$("input[name='lWhich']").change(function() {
			if (!hidden) {
				$('#hideOptional').slideUp('fast');
				hidden = true;
			} else {
				$('#hideOptional').slideDown('fast');
				hidden = false;
			}

		});

	}

});