
var headerIntervalId;
var testimonialIntervalId;
var activeHeader = -1;

$(document).ready(function() {

  // initiate header animation
  if (showAnimation) {
    animateHeader();
    headerIntervalId = setInterval("animateHeader()", 7000);
  }

  // menu drop-downs
  /*
  $("#leftcol li:not(.active)").hover(function() {
    $(this).find('ul').slideDown(300);
  }, function() {
    $(this).find('ul').slideUp(200);
  })
  */

  // search box text
  $("#sitesearch_input").focus(function() {
    if ($(this).val() == 'Search') {
      $(this).val('');
    }
  })
  $("#sitesearch_input").blur(function() {
    if ($(this).val() == '') {
      $(this).val('Search');
    }
  })

  // fancybox
  $(".image_link").fancybox({
    'zoomSpeedIn': 500,
    'zoomSpeedOut': 500
  });

  // alternate testimonials
  testimonialIntervalId = setInterval("animateTestimonials()", 15000);

})

function animateTestimonials() {
  $("#testimonial_slideshow").fadeOut(1800, function() {
    $("#testimonial_slideshow").load(path_to_site+'includes/ajax/testimonials.php', {
      'previous': $("#testimonial_id").val()
    }, function() {
      setTimeout('$("#testimonial_slideshow").fadeIn(1800);', 700);
    });
  });
}

function animateHeader() {
  // fade out old link
  $("#header" + activeHeader).animate({backgroundColor: '#656A6E'}, 1000);

  // get new link id
  activeHeader++;
  if (activeHeader == headerImages.length) {
    activeHeader = 0;
  }

  // fade in new link
  $("#header" + activeHeader).animate({backgroundColor: '#00573D'}, 1500);

  // create hidden layer for new image then fade in
  $("#header_image").html('<div id="header_hidden" style="height: 146px; display:none; background-image: url(' + path_to_site + 'uploads/headers/' + headerImages[activeHeader] + ');"></div>');
  $("#header_hidden").fadeIn(2000, function() {
    // set the original header background to this new image ready for the next fade
    $("#header_image").css('background-image', 'url(' + path_to_site + 'uploads/headers/' + headerImages[activeHeader] + ')');
  });
}
