// Menu manipulation ------------------------------------------------------- //
// 07/23/10 ---------------------------------------------------------------- //
$(document).ready(function() {
         
  // Set headernav widths based on anchor tag widths plus breathing room
  $("#header-nav li a").each(function() {    
    $(this).width($(this).outerWidth()+20);
  });
  
  // Set mainnav widths based on anchor tag widths
  $("#wrapper-navigation a.main-item").each(function() {    
    $(this).parent().width($(this).innerWidth()+2);
  });
  
  // Set a mainnav background upon mouseover
  $("#wrapper-navigation a.main-item").mouseover(function() {  
    $(this).parent().css("background-image", "url(/images/menu_selected_li.jpg)");
  });
  
  // Remove a mainnav background upon mouseout
  $("#wrapper-navigation a.main-item").mouseout(function() {  
    $(this).parent().css("background-image", "none");
  });
  
  // Calculate the height of the dropdowns and add transparency
  $(".sf-menu li ul").each(function () {
  var menuHeight = 0;
  menuHeight = $(this).children().size();
  $(this).height((menuHeight*25)-12);
  $(this).fadeTo('fast', 0.9);
  });
  
  // Calculate the width of the dropdown items
  $(".sf-menu li ul li a").each(function () {
  $(this).width($(this).parent().innerWidth()-20);
  }); 
  
  // By default, hide all images
  $(".interior-carousel-container").hide();
  
});
// ------------------------------------------------------------------------- //

// Carousel Implementation ------------------------------------------------- //
// 09/17/10 ---------------------------------------------------------------- //
// We use the initCallback callback to assign functionality to the controls.
function carousel_initCallback(carousel) {
 
  // On Init, show all images
  $(".interior-carousel-container").show();
  
  // Slide is shown associated with the selector.
  jQuery(".carousel-selector ul li a.selector").bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr("id")));
        return false;
    });
  
  // Pause autoscrolling if the user moves with the cursor over the clip.
  jQuery("#wrapper-interior-carousel").hover(function() {
      carousel.startAuto(0);
  }, function() {
      carousel.startAuto(8);
  });
  jQuery("#wrapper-home-carousel").hover(function() {
      carousel.startAuto(0);
  }, function() {
      carousel.startAuto(8);
  });
  
  // Next button scrolls to next slide
  jQuery('#next_button').bind('click', function() {
      if (!(jQuery(".carousel-selector ul li a.selected").attr("id") == carousel.size())) {
        carousel.next();
      }
      return false;
  });
  // Previous button scrolls to next slide
  jQuery('#previous_button').bind('click', function() {
      carousel.prev();
      return false;
  });
};

// Based on which slide is shown, highlight that selector.
function carousel_itemFirstInCallback(carousel, item, idx, state) {
  //var index = idx % carousel.size();
  //if (index == 0) { index = carousel.size();
  jQuery(".carousel-selector ul li a").removeClass();
  jQuery(".carousel-selector ul li a#" + (idx)).addClass("selected");
  return false;
};

// Interior Carousel Initialization
jQuery(document).ready(function() {
    jQuery("#interior-carousel").jcarousel({
        auto: 8,
        scroll: 1,
        wrap: "last",
        animation: 1500,
    
        initCallback: carousel_initCallback,
        itemFirstInCallback: carousel_itemFirstInCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
});

// Home Carousel Initialization
jQuery(document).ready(function() {
    jQuery("#home-carousel").jcarousel({
        auto: 8,
        scroll: 1,
        wrap: "last",
        animation: 1500,
    
        initCallback: carousel_initCallback,
        itemFirstInCallback: carousel_itemFirstInCallback
    });
});
// ------------------------------------------------------------------------- //

// Contact Signup Form Footer ---------------------------------------------- //
// 07/15/10 ---------------------------------------------------------------- //
$(document).ready(function() {
        
  // At load, hide the contact form
  $("#footer-contact").hide();
      
  // When 'Contact' link clicked, show contact form and hide footer navigation
  $("#footer-contact-button").click(function() {
    $("#footer-contact").show();
    $("#footer-middle").hide();
  });
  
  // When 'Close' button clicked, hide contact form and show footer navigation
  $("#footer-close-button").click(function() {
    $("#footer-middle").show();
    $("#footer-contact").hide();
  });
  
  // Change the look of the footer submit button upon press
  $("#footer-contact-form .submit").mousedown(function() {
    $(this).removeClass('submit-rest');
    $(this).addClass('submit-pressed');
  });
  $("#footer-contact-form .submit").mouseout(function() {
    $(this).removeClass('submit-pressed');
    $(this).addClass('submit-rest');
  });
  $("#footer-contact-form .submit").mouseup(function() {
    $(this).removeClass('submit-pressed');
    $(this).addClass('submit-rest');
  });
  
  // First Name footer field Manipulation
  if ($("#footer-contact .footerfname").val() == "") {
    $("#footer-contact .footerfname").val("First Name");
    $("#footer-contact .footerfname").css("color", "#788289");
  }
  $("#footer-contact .footerfname").focus(function() {
  if ($("#footer-contact .footerfname").val() == "First Name") {
      $("#footer-contact .footerfname").val("");
    $("#footer-contact .footerfname").css("color", "#3A444B");
  }
  });
  $("#footer-contact .footerfname").focusout(function() {
  if ($("#footer-contact .footerfname").val() == "") {
      $("#footer-contact .footerfname").val("First Name");
    $("#footer-contact .footerfname").css("color", "#788289");
  }
  });
  
  // Last Name footer field Manipulation
  if ($("#footer-contact .footerlname").val() == "") {
    $("#footer-contact .footerlname").val("Last Name");
    $("#footer-contact .footerlname").css("color", "#788289");
  }
  $("#footer-contact .footerlname").focus(function() {
  if ($("#footer-contact .footerlname").val() == "Last Name") {
      $("#footer-contact .footerlname").val("");
    $("#footer-contact .footerlname").css("color", "#3A444B");
  }
  });
  $("#footer-contact .footerlname").focusout(function() {
  if ($("#footer-contact .footerlname").val() == "") {
      $("#footer-contact .footerlname").val("Last Name");
    $("#footer-contact .footerlname").css("color", "#788289");
  }
  });
  
  // Email footer field Manipulation
  if ($("#footer-contact .footeremail").val() == "") {
    $("#footer-contact .footeremail").val("Email Address");
    $("#footer-contact .footeremail").css("color", "#788289");
  }
  $("#footer-contact .footeremail").focus(function() {
  if ($("#footer-contact .footeremail").val() == "Email Address") {
      $("#footer-contact .footeremail").val("");
    $("#footer-contact .footeremail").css("color", "#3A444B");
  }
  });
  $("#footer-contact .footeremail").focusout(function() {
  if ($("#footer-contact .footeremail").val() == "") {
      $("#footer-contact .footeremail").val("Email Address");
    $("#footer-contact .footeremail").css("color", "#788289");
  }
  });
  
});
// ------------------------------------------------------------------------- //

// Contact Signup Form Body ---------------------------------------------- //
// 07/16/10 ---------------------------------------------------------------- //
$(document).ready(function() {
        
  // First Name body field Manipulation
  if ($(".SubmitForm .fname").val() == "") {
    $(".SubmitForm .fname").val("First Name");
    $(".SubmitForm .fname").css("color", "#788289");
  }
  $(".SubmitForm .fname").focus(function() {
  if ($(".SubmitForm .fname").val() == "First Name") {
      $(".SubmitForm .fname").val("");
    $(".SubmitForm .fname").css("color", "#3A444B");
  }
  });
  $(".SubmitForm .fname").focusout(function() {
  if ($(".SubmitForm .fname").val() == "") {
      $(".SubmitForm .fname").val("First Name");
    $(".SubmitForm .fname").css("color", "#788289");
  }
  });
  
  // Last Name body field Manipulation
  if ($(".SubmitForm .lname").val() == "") {
    $(".SubmitForm .lname").val("Last Name");
    $(".SubmitForm .lname").css("color", "#788289");
  }
  $(".SubmitForm .lname").focus(function() {
  if ($(".SubmitForm .lname").val() == "Last Name") {
      $(".SubmitForm .lname").val("");
    $(".SubmitForm .lname").css("color", "#3A444B");
  }
  });
  $(".SubmitForm .lname").focusout(function() {
  if ($(".SubmitForm .lname").val() == "") {
      $(".SubmitForm .lname").val("Last Name");
    $(".SubmitForm .lname").css("color", "#788289");
  }
  });
  
  // Email body field Manipulation
  if ($(".SubmitForm .email").val() == "") {
    $(".SubmitForm .email").val("Email Address");
    $(".SubmitForm .email").css("color", "#788289");
  }
  $(".SubmitForm .email").focus(function() {
  if ($(".SubmitForm .email").val() == "Email Address") {
      $(".SubmitForm .email").val("");
    $(".SubmitForm .email").css("color", "#3A444B");
  }
  });
  $(".SubmitForm .email").focusout(function() {
  if ($(".SubmitForm .email").val() == "") {
      $(".SubmitForm .email").val("Email Address");
    $(".SubmitForm .email").css("color", "#788289");
  }
  });
  
});
// ------------------------------------------------------------------------- //

// Superfish Dropdown Menu ------------------------------------------------- //
// 07/19/10 ---------------------------------------------------------------- //
$(document).ready(function() { 
  $('ul.sf-menu').superfish(); 
}); 
// ------------------------------------------------------------------------- //

// Content Tabs ------------------------------------------------------------ //
// 07/19/10 ---------------------------------------------------------------- //
jQuery(function() {
  if ($('#content-twothird-tabs').length != 0) {
    jQuery('#content-twothird-tabs').tabs();
    if (!(jQuery('#photos-tab').parent().css('visibility','hidden').is(':hidden'))) {
      jQuery('#photos-tab').parent().css('visibility','visible');
      jQuery('#content-twothird-tabs').tabs({ selected: 3 });
    }
    else 
    {
      jQuery('#content-twothird-tabs').tabs();
    }
  }
});
// ------------------------------------------------------------------------- //
