/**
 * Behaviors for venturehomesusa
 */
$(document).ready(function () {
  // Activate tabs?
  $("#main > ul.jtabs").tabs();

  // Clear newsletter sign up field on click
  $("#markupfactory-getnewslettersignup-email").click(function () { 
    var def = "Email Address"; // default value
    if (this.value === def) { this.value = ""; }
  });

  // Enable lightboxes on <a rel="lightbox">
  $('a[@rel*=lightbox]').lightBox();

  /**
   * Image swapper for listing details
   */
  (function () {
    var imageDiv = $(".images");
    var firstImg = $("#imageList li a")[0];

    /**
     * Replace the main image with the given element
     */
    var setMain = function (a) {
      $("#mainImage").fadeOut("fast", function () {
        $("#mainImage").html($(a).html()).fadeIn("fast"); 
      });
    }

    if (imageDiv.length === 1) {
      // Insert the first image as the main image
      setMain(firstImg);

      // Hide thumbnails if there is only one image
      if ($("#imageList li").length === 1) { $("#imageList").empty(); }

      // Observe clicks on the thumbnails
      $("#imageList li a").click(function (evt) {
        evt.preventDefault();
        setMain(this);
      });
    }
  })();
});

