// jQuery for article pages
$(document).ready(function(){

  // link to this article
  $("#link_to_this").show();
  $("a.ltt_link_to").click(function() {
    $(this).hide();
    $(".ltt_dropdown").show("fold",{size:30},"slow", function() {
      $(".ltt_dropdown .content").css({'visibility' : 'visible'});
    });
    return false;
  });
  $(".ltt_close").click(function(){
    $(".ltt_dropdown .content").css({'visibility' : 'hidden'});
    $(".ltt_dropdown").hide("fold",{size:30},"slow", function() {
      $("a.ltt_link_to").fadeIn("slow");
    });
    return false;
  });

  // adjust text size
  $("#adjust_text_size").show();
  $("#adjust_text_size a").click(function() {
    var change = "";
    var minSize = "10"; // nothing below 10px
    var maxSize = "18"; // nothing above 18px
    var triggerId = $(this).attr('id');
    var currentSize = $('.body_content').css("font-size");
    var textSize = parseFloat(currentSize, 10);
    var unitOfMeasurement = currentSize.slice(-2);			
    $("#adjust_text_size a").removeClass("disabled");
    if(triggerId == "increase") {
      if(textSize != maxSize) {
        textSize += 2;
        change = true;
      }
    } else {
      if(textSize != minSize) {
        textSize -= 2;
        change = true;
      }
    };
    if(textSize == maxSize || textSize == minSize) {
      $(this).addClass("disabled");
    }
    if(change) {
      $('.body_content').css("font-size", textSize + unitOfMeasurement);
    }
    return false;
  });
	
  // help hover tooltips
  var hide = false;
  $(".help_bubble").hover(
  function() { //over
    var hoverId = $(this).attr('id');
    var thisDiv = "#"+hoverId+" span";
    if (hide) clearTimeout(hide);
    $(thisDiv).fadeIn();
  },
  function() { //out
    var hoverId = $(this).attr('id');
    var thisDiv = "#"+hoverId+" span";
    hide = setTimeout(function() {
      $(thisDiv).fadeOut("slow");
    }, 250);
  });

  // recommendation tool tip
  function login_mouse_over() { 
    $('.must_login').fadeIn('normal');
  }
  function login_mouse_out()  {
    setTimeout( function() {
      $('.must_login').fadeOut('normal');
    }, 2000);
  }
  var login_config = {sensitivity:3, interval:200, over:login_mouse_over, timeout:500, out:login_mouse_out};
  $(".recommendations").hoverIntent(login_config)
  /*
  $('.must_login a.close').click(function() {
    $('.must_login').hide();
    return false;
  });
  */
  function help_mouse_over() {
    $('.rec_help').fadeIn('normal');
  }
  function help_mouse_out() {
    $('.rec_help').fadeOut('normal');
  }
  var help_config = {sensitivity:3, interval:200, over:help_mouse_over, timeout:500, out:help_mouse_out};
  $("a.recommendation_link").hoverIntent(help_config)
  /*
  $('.rec_help a.close').click(function() {
    $('.rec_help').hide();
    return false;
  });
  */
	
  // enlarge images
  $("img.click_to_enlarge").show();
  $.Lightbox.construct({
    download_link: false,
    show_extended_info: true,
    show_helper_text: false,
    show_linkback: false,
    speed: 200
  });
	
  // sub-article expanding buttons
  $('#subarticle_subs ul').kwicks({  
    max: 360,
    duration: 400
  });

});
