$(document).ready(function() {

	// flash messages
	setTimeout(function() {
		$(".flash").fadeOut("slow", function () {
		$(".flash").slideUp('slow');
	}); }, 2000);
	
	// login form
	$(".loginlink").attr("href", $(".loginlink").attr('href') + "modal").colorbox({
		width:375,
		scrolling:false,
		opacity:.50
	}, function(){
		$("#login #email input").focus();
	});
	
	$(".dropnav li").hover(
		function() { 
			$(this).addClass("active").children(".subnav").fadeIn("fast");
		},
		function() { 
			$(this).removeClass("active").children(".subnav").fadeOut("fast");
		}
	);

	// login submit
	$(".modalcontent #loginbttn").live("click", function() {
		$.ajax({
			type: "POST", 
			url: "/account/login/modal",
			data: $("#login fieldset form").serialize(),
			beforeSend: function(){ // on send actions
				$("#login .loading").height($("#login fieldset").height());
				$("#login fieldset").fadeOut("fast");				
				$("#login .loading").fadeIn("fast");
			},
			complete: function(){ // on complete actions
				$.fn.colorbox.resize();
			},
			success: function(html){ // success store returned data in html
				$("#cboxLoadedContent").html(html);
				$.fn.colorbox.resize();
		 	}
		 });	
	});
	
	// enable inquire link for modal form
	$(".inquire").colorbox({scrolling:false, opacity:.50});
	
	// inquire submit
	$("#inquire_form #inquirebttn").live("click", function() {
		$.ajax({
			type: "POST", 
			url: $("#inquire_form form").attr("action"),
			data: $("#inquire_form form").serialize(),
			beforeSend: function(){ // on send actions
				$("#inquire_form .loading").height($("#inquire_form fieldset").height());
				$("#inquire_form fieldset").fadeOut("fast");
				$("#inquire_form .loading").fadeIn("fast");
			},
			complete: function(){ // on complete actions
				$("#inquire_form .loading").hide();
				$.fn.colorbox.resize();
			},
			success: function(html){ // success store returned data in html
				$("#cboxLoadedContent").html(html);
				$.fn.colorbox.resize();
		 	}
		 });	
	});
	
	// notice close
	$("#browseralert .close").click(function (){
		$("#browseralert").slideUp("fast").fadeOut("fast");
		$.ajax({
			type: "POST", 
			url: "/properties/hide_notice/ajax"
		});	
		return false;
	});
	
});

// Pre-Load images
// Use: jQuery.preLoadImages("image1.gif", "/path/to/image2.png");
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
