// Allow Ajax Submittable Forms
jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})

jQuery.fn.submitWithAjax = function () {  
  this.submit(function () {  
    $.post($(this).attr('action'), $(this).serialize(), null, "script");  
    return false;  
  });  
};

//DISPLAY FLASH NOTICES
function notify(notice) { 
	$('#flash_notice').html(notice);	
	$('#flash_notice').show().fadeTo(600,1,function(){
		//delay and fadeout
		$(this).fadeTo(2500,1,function(){$(this).fadeTo(600,0,function(){$(this).hide();})});
	});
}

$(document).ready(function(){
	
	// Main Nav Hovers
	function showOverlay() { $(this).children('ul').show(); $(this).children('a').addClass('hover'); }
	function hideOverlay() { $(this).children('ul').hide(); $(this).children('a').removeClass('hover'); }
	
	if ( $.browser.msie && $.browser.version < "7.0" ) { } else {
		$('#nav ul li.hover_pane').hoverIntent({    
			sensitivity: 3, // number = sensitivity threshold (must be 1 or higher) 
			interval: 200, 
			over: showOverlay,
			timeout: 500, // number = milliseconds delay before onMouseOut    
			out: hideOverlay // function = onMouseOut callback (REQUIRED)    
		});
	}
	
	// SEARCH BOX TOGGLE
	$("#search_trigger").toggle(function(){
		$(this).addClass("active"); 
	}, function () {
		$(this).removeClass("active");
	});

	$("#search_trigger").click(function(){
		if ($('#toggle_container').css('top') == "20px") { $('#toggle_container').animate({top: '-20px'}, 500); }
		if ($('#toggle_container').css('top') == "-20px") { $('#toggle_container').animate({top: '20px'}, 500); }
	});

		
	// INPUT FIELDS - REMOVE TEXT ON FOCUS
	// simulate browser autocomplete
	$('input').searchField();
	$('textarea').searchField();


	//SIDEBAR-RIGHT FORMS TOGGLE
	$('.accordian a').click(function(){
		$(this).parent().siblings('.accordian').children('div').slideUp("slow");
		$(this).parent().siblings('.accordian').children('a').removeClass("active");
		
		$(this).siblings('div').slideToggle("slow");
		$(this).toggleClass("active");
		$(".flash_notice").remove();
		$(".flash_error").remove();
		return false;
	});
	$('#sidebar-right form').submitWithAjax();

	//CHECKBOXES
	$('input[type=checkbox], input[type=radio]').livequery(function(){ $(this).checkBox(); });
		
		
	//SIDEBAR SUB PROPERTIES ACCORDIAN
	$('ul.sub li a.subproperty_link').click(function(){
		$(this).parent().parent().siblings('li').children('ul.subheading').slideUp("slow");
		$(this).parent().parent().siblings('li').removeClass('open');
		$(this).parent().parent().children('ul.subheading').slideToggle("slow");
		$(this).parent().parent().toggleClass("open");
		return false;
	});
		
});




