// JavaScript Document

$(document).ready(function(){

  $(".menu_img").each(function() {
	var img = $(this);
	if(img.length > 0){
      var imgFile = img.attr('src');
	  var preloadImage = new Image();
	  var new_src;
	  // attempt both replacements, only one will take.
      var imgExt = /[1](\.\w{3})/;
      new_src = imgFile.replace(imgExt,'2$1');	  
	  imgExt = /[3](\.\w{3})/;	  
      preloadImage.src = new_src.replace(imgExt,'4$1');
		
	  $(this).hover(
		function() {
			img.attr('src', preloadImage.src);
		},
		function () {
			img.attr('src', imgFile);
		}
	  ); // end hover
	} // end if
  }); // end each
  
  /* grab the image maps */
  $("area").each(function(){
	var my_unit = $(this).attr('class');
    $(this).hover(
	  function(){
		map_hover_in(my_unit);
	  },
	  function(){
		map_hover_out(my_unit);
	  }
	); // end hover							
  }); // end each
  
  /* grab the links ontop of the map */
  $(".north, .south").each(function(){
	var my_unit = $(this).attr('id');
	// preload some images. they're not actually used here
	var preloadImage = new Image();
	preloadImage.src="/residences/floorplans/thumbs/"+my_unit+".jpg";
	
    $(this).hover(
	  function(){
		map_hover_in(my_unit);
	  },
	  function(){
		map_hover_out(my_unit);
	  }
	); // end hover							
  }); // end each
});

function map_hover_in(my_unit){
	$('\#'+my_unit).addClass("bold");	
	var imageFile = "/residences/floorplans/thumbs/"+my_unit+".jpg";
	$("#img_preview").attr('src',imageFile);
	return false;
}
function map_hover_out(my_unit){
	$('\#'+my_unit).removeClass("bold");
	return false;
}

