var headerIntervalId;
var testimonialIntervalId;

var headerImages = new Array('slide1_office.jpg', 'slide2_pulsestore.jpg', 'slide3_support.jpg', 'slide4_manage.jpg');

$(document).ready(function() {
  // initiate header animation
  animateHeader();
  if (slide === true){
    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');
    }
  });

  // $('a.fancybox').fancybox({width:450, height:500, padding:0, type:'ajax'});

  // 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(slide) {
  // 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: 188px; display:none; background-image: url(' + path_to_site + 'images/' + headerImages[activeHeader] + ');"></div>');
  $("#slideshow_hidden").fadeIn(2000, 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

