(function(window, document, $){

$(document).ready(function() {

	function toggleSearch() {
		$('.search').toggleClass('hidden');
		$('.search .more a').toggleClass('hidden');
	}

	$('.search .more a').bind('click', toggleSearch);

	$('.list article').live('click', function() {
		window.location = $(this).find('a').attr('href');
	});
	
	$('.list article').live('mouseover mouseout', function() {
		$(this).toggleClass('hover');
	});

	$('.box h2').live('mouseover mouseout', function() {
		$(this).toggleClass('hover');
	});

	$('h2.clickable').live('click', function() {
		if ($(this).parent().hasClass('search')) {
			toggleSearch();
		}
		else {
			window.location = $(this).parent().find('a').attr('href');
		}
	});
	
	$('.more a').bind('mouseover mouseout', function() {
		var title = $(this).parent().parent().find('h2.clickable');
		title.toggleClass('hover', !title.hasClass('hover'));
	})

	$('.gallery a').live('click', function(event) {
		var that = this,
			oldimg = $('.image img'),
			newimg;

		event.preventDefault();
		oldimg.detach();
		newimg = $('<img />').attr('src', $(that).attr('href').replace("properties_thumb", "properties"))
			.attr('alt', oldimg.attr('alt'))
			.attr('width', oldimg.attr('width'))
			.attr('height', oldimg.attr('height'));

		newimg.bind('load', function() {
			$('.image').append(newimg);
			$('.gallery .current').removeClass('current');
			$(that).addClass('current');
		});


		newimg.each(function() {
			if (this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) 
				$(this).trigger('load');
		});

	});

});

})(this, this.document, jQuery);

