$(document).ready(function() {

  /**
  * Toggle Global Search Message : http://docs.jquery.com/Tutorials:5_Quick_jQuery_Tips
  **/
  function populateElement(selector, defvalue) {
    $(selector).each(function() {
      if($.trim(this.value) == "") {
        this.value = defvalue;
      }
    });
    $(selector).focus(function() {
      if(this.value == defvalue) {
        this.value = "";
        $(".search-box input.text").removeClass("inactive");
        $(".search-box input.text").addClass("active");
        $(".search-box").removeClass("inactive");
        $(".search-box").addClass("active");
      }
    });
    $(selector).blur(function() {
      if($.trim(this.value) == "") {
        this.value = defvalue;
        $(".search-box input.text").removeClass("active");
        $(".search-box input.text").addClass("inactive");
        $(".search-box").removeClass("active");
        $(".search-box").addClass("inactive");
      }
    });
  }
  $(".search-box input.text").addClass("inactive");
  $(".search-box").addClass("inactive");
  populateElement('.search-box input.text', 'Search news headlines for...');
  
  
  /**
  * Sparklines for Trending Topics : http://omnipotent.net/jquery.sparkline/
  **/
  // $(function() {
  //   $('.spark-bar').sparkline('html', {type: 'bar', height: '16px', zeroAxis: true, barColor: '#B0BACD'});  
  //   $('.spark-line').sparkline('html', {height: '17px', width: '50px', minSpotColor: false, maxSpotColor: false, spotColor: false});
  // });
  
  
  /**
  * jQuery Tabs : http://jqueryfordesigners.com/jquery-tabs/
  **/
  $(function () {
      var tabContainers = $('div.tabs > div');
      $('div.tabs ul.tabNavigation a').click(function () {
          tabContainers.hide().filter(this.hash).show();
          $('div.tabs ul.tabNavigation a').removeClass('selected');
          $(this).addClass('selected');
          // $.sparkline_display_visible();  // Renders sparklines on tab switch.  Sparkline code must load first or else this won't work.
          return false;
      }).filter(':first').click();
  });
  
  
  /**
  * Set class on link types for styling : http://cool-javascripts.com/jquery/add-icons-to-your-links-automatically-using-jquery-css.html
  **/
  
  // This sets the class for general link (and in the future, file) types
  $("a[href^='/article/']").addClass("article");
  $("a[href^='/photo/']").addClass("photo");// .prepend("<span class=\"type\">(Photo)</span>");
  
  /*  This is more specificly targeted */
  $(".module.topic .photo .title").prepend("<b class=\"type\">(Photo)</b> ");
  $(".module.results .photo .title").prepend("<b class=\"type\">(Photo)</b> ");
  
  
  /**
  * Max Image Size (http://thejudens.com/eric/2009/07/jquery-image-resize/)
  **/
  /*
  $(".centered").each(function() {
      var maxWidth = 640; // Max width for the image
      var maxHeight = 480;    // Max height for the image
      var ratio = 0;  // Used for aspect ratio
      var width = $(this).width();    // Current image width
      var height = $(this).height();  // Current image height
      
      // Check if the current width is larger than the max
      if(width > maxWidth){
          ratio = maxWidth / width;   // get ratio for scaling image
          $(this).css("width", maxWidth); // Set new width
          $(this).css("height", height * ratio);  // Scale height based on ratio
          height = height * ratio;    // Reset height to match scaled image
          width = width * ratio;    // Reset width to match scaled image
      }
      
      // Check if current height is larger than max
      if(height > maxHeight){
          ratio = maxHeight / height; // get ratio for scaling image
          $(this).css("height", maxHeight);   // Set new height
          $(this).css("width", width * ratio);    // Scale width based on ratio
          width = width * ratio;    // Reset width to match scaled image
      }
  });
  */
  
  /**
  * Center Image : http://plugins.jquery.com/project/elementcenter/
  * NOTE:  Must be called after the image size code or else it centers from the wrong point.
  **/
  // $(".centered").center();


});