var headerIntervalId;
var testimonialIntervalId;
var activeHeader = -1;

var headerImages = new Array('header1.jpg','header2.jpg','header3.jpg', 'header4.jpg');

$(document).ready(function() {

  // initiate header animation
  animateHeader();
  headerIntervalId = setInterval("animateHeader()", 8000);

  // 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');
    }
  })

  // alternate testimonials
  testimonialIntervalId = setInterval("animateTestimonials()", 15000);

})

function animateTestimonials() {
  $("#qoute_slideshow").fadeOut(1800, function() {
    $("#qoute_slideshow").load(path_to_site+'testimonials.php', {
      'previous': $("#testimonial_id").val()
    }, function() {
      setTimeout('$("#testimonial_slideshow").fadeIn(1800);', 700);
    });
  });
}

function animateHeader() {
  // get new link id
  activeHeader++;
  if (activeHeader == headerImages.length) {
    activeHeader = 0;
  }

  // highlight the active link
  var activeLink = activeHeader + 1;  // hack because it doesn't appear to like #slideshow_link0
  $("#slideshow_links li a").removeClass('active');
  $("#slideshow_link"+activeLink+" > a").addClass('active');

  // create hidden layer for new image then fade in
  $("#slideshow_image").html('<div id="slideshow_hidden" style="height: 214px; display:none; background-image: url(' + path_to_site + 'images/' + headerImages[activeHeader] + '); background-repeat:no-repeat;"></div>');
  $("#slideshow_hidden").fadeIn(3000, function() {
    // set the original header background to this new image ready for the next fade
    $("#slideshow_image").css('background-image', 'url(' + path_to_site + 'images/' + headerImages[activeHeader] + ')');
  });
}

function animateTestamonials () {


      /*$("#qoute_slideshow").fadeOut(1800, function() {
        $("#qoute_slideshow").load(path_to_site+'testimonials.php', {
          'previous': $("#testimonial_id").val()
        }, function() {
          setTimeout('$("#testimonial_slideshow").fadeIn(1800);', 700);
        });
      });*/

} // end animateTestamonials
