$(function() {
	/**
		Home Slideshow
	**/
	var home = $('#home-banners');
	var home_speed_fade = 1200;
	var home_speed_switch = 5000;
	if(home.length > 0) {
		setInterval(function() {
			var current = $('img:visible',home);
			current.fadeOut(home_speed_fade);
			next = current.next();
			if(next.length == 0) {
				next = $('img:eq(0)',home);
			}
			next.fadeIn(home_speed_fade);
		},home_speed_switch);
	}
	/**
		Menu Dropdowns
	**/
	$('#menu div.left div.block').hover(function() {
		element = $('div',this);
		element.removeClass();
		if(element.parent().is(':first-child')) {
			element.addClass('first');
		}
		if($('a',element.parent()).hasClass('selected')) {
			element.addClass('selected');
		}
		element.show();
	},function() {
		var element_id = $(this).html().toLowerCase().replace(/ /g,'_');
		$('div',this).hide();
	});
	/**
		Homeowner: How does it work? Image enlarge
	**/
	$('div.homeowner-how-small').click(function() {
		var image_url = $('img',this).attr('src').replace('-small','-large');
		$('<div id="modal_bg"></div>').click(function() {
			$('#modal_content').fadeOut(function() { $(this).remove(); });
			$(this).fadeOut(function() { $(this).remove(); });
		}).appendTo('body').fadeIn();
		var top = ($(window).height()/2)-((parseInt($(this).attr('data-large-height'))+20)/2)
		$('<div id="modal_content" style="width: 600px;margin-left: -300px;top: '+top+'px;"><img src="'+image_url+'"><p><span class="close" onclick="$(\'#modal_bg\').click();">(Close)</span>'+$('img',this).attr('title')+'</p></div>').appendTo('body').fadeIn();
	});
});
