$(document).ready(function() {  
  // "Highlights" carousel on the homepage
  
  $(window).load(function() {
    $("#highlights li").show();
    $("#carousel").jCarouselLite({ 
      speed: 2000, 
      visible: 1, 
      scroll: 1,
      btnGo: [
        "#external-carousel-control .highlight-1", 
        "#external-carousel-control .highlight-2", 
        "#external-carousel-control .highlight-3",
        "#external-carousel-control .highlight-4", 
        "#external-carousel-control .highlight-5", 
        "#external-carousel-control .highlight-6" 
      ],
      circular: false
    });
  })

  // Adding class to active "Highlights" navigation item
  $("#external-carousel-control a").click(function() {
    $("#external-carousel-control a").removeClass("active");
    $(this).addClass("active");
    return false;
  });
  
  // Archives dropdown for category listing
  $("#cat").change(function() {
    var baseUrl = $("#archives-list").attr('data-url');
    var currentValue = $(this).val();
    if (currentValue != -1) {
      window.location.href = baseUrl + "?cat=" + currentValue;
    }
  });
  
  // Archives dropdown for month listing
  $("#month-dropdown").change(function() {
    var currentValue = $(this).val();
    if (currentValue) {
      window.location.href = currentValue;
    }
  });
  
  // Hide input labels when input is focused and re-show if input is empty on blur
  $("input, textarea").focus(function() {
    var elementId = $(this).attr('id');
    $("label[for='" + elementId + "']").hide();
  });
  $("input, textarea").blur(function() {
    var element = $(this);
    var elementId = element.attr('id');
    if (element.val().trim() == '') { $("label[for='" + elementId + "']").show(); }
  });
  
  // File type icons!
  $("#page li a").each(function() {
    var link = $(this);
    var href = link.attr('href');
    
    if (href.match(/mp3$/)) {
      link.addClass('icon').addClass('music');
      return;
    }
    if (href.match(/pdf$/)) {
      link.addClass('icon').addClass('pdf');
      return;
    }
    if ((href.charAt(0) != '/') && (href.indexOf(window.location.host) == -1) && (href.indexOf('addthis') == -1) && (href.indexOf('amazon') == -1)) {
      link.addClass('icon').addClass('off-site');
    }
  });
  
});