// Homepage Image Rotator
function homepage_image_fader(){
    $('.color').hide();

    var image_grid_length = $(".image_grid").length - 1;
    var color_images = $('.image_grid .color');
    var fade_length = 6000;

    function fade_images(){
      var random_number = Math.floor( Math.random() * image_grid_length );
      var random_image = color_images.not('.active').eq(random_number);

      color_images.filter('.active').fadeOut(fade_length).removeClass('active');
      $(random_image).fadeIn(fade_length).addClass('active');
      setTimeout( fade_images, fade_length);
    }

    fade_images();
}

$(document).ready( function(){
  $("#search").focus(function() {
    if($(this).val() == "Search")
      $(this).val('');
  });

  $("#search").blur(function() {
    if($(this).val() == "")
      $(this).val('Search');
  });

  $('.tabs').tabs();
  $('.tabs a:first').click();
  $('a[href^="#"]', '.tab-content, .content').click(function() {
      $('a[href="'+$(this).attr('href')+'"]', '.tabs').click();
      return false;
  });

  $('li:last-child').addClass('last');
  $('h3:first-child, h2:first-child', '#main').addClass('first');

  homepage_image_fader();

  $(".home #callout div").not(':first').hide();
  $(".home #callout").cycle({
      pause: true,
      timeout: 15000
  });

  $('a[rel=external], a[href*="wufoo"], a[href*="kcpinternational.net"], a[href*="kcpstudentlife.com"]' ).click(function() {
      if($(this).hasClass('small')){
          window.open(this.href, null, 'height=760, width=680, toolbar=0, location=0, status=0, scrollbars=1, resizable=0');
      } else {
          window.open(this.href);
      }

      return false;
  });

  if(window.location.hash) {
      $("a[href='"+window.location.hash+"']").click();
  }
});


