$(document).ready(function(){
  
  //ie functionality
  if( $.browser.msie ){
    $("input[type='radio'], input[type='checkbox']").addClass("radiochecks");
  	$("#content_3 li")
      .mouseover(function(){ $(this).addClass("hover"); })
  		.mouseout(function(){ $(this).removeClass("hover"); });
  }
  
  //nav selections
  $("#content_3 li ul li.selected").parent().parent().addClass("selected");

  //make external links open in a new window
  $("a").each(function(){
    if( $(this).attr('href') ){
      href = $(this).attr('href');
      base = basedir.split('http://').join('').split('https://').join('');
      stuff = href.split(basedir).join('');
      if( ((href.match('http://') || href.match('https://')) && !href.match(base)) || stuff.match("[.]") ){
        $(this).click(function(){
          window.open($(this).attr('href'));
          return false;
        });
      }
    }
  });
  
  //button events
  $("button")
    .mouseover(function(){ $(this).addClass("hover") })
    .mouseout(function(){ $(this).removeClass("hover") });
  
  //confirmation alerts
  $(".confirm").click(function(){
    action = $(this).attr("title").substr(0,1).toLowerCase() + $(this).attr("title").substr(1);
    if( !confirm("Are you sure you want to "+action+"?") ){ return false; }
  });
  
  //fix checkbox/radio inputs
  $("input[type='checkbox']").addClass("checkbox");
  $("input[type='radio']").addClass("radio");
  
  //text/textarea events
  $("input[type='text'], input[type='password'], textarea")
    .focus(function(){
      $(this).addClass("focus");
      $("form:has(.focus)").addClass("focus");
    })
    .blur(function(){
      $(this).removeClass("focus");
      $("form:not(:has(.focus))").removeClass("focus");
    });
  
  //font size buttons
  resizables = "p, ul, ol, block";
  $("#textsize-plus").click(function(){
    curSize = $("#mainbar p").css("fontSize");
    curSize = curSize.split('px').join('');
    if( curSize < 15 ){
      curSize++;
      $("#mainbar, #sidebar").find(resizables).css("fontSize",curSize+"px");
    }
  });
  $("#textsize-minus").click(function(){
    curSize = $("#mainbar p").css("fontSize");
    curSize = curSize.split('px').join('');
    if( curSize > 11 ){
      curSize--;
      $("#mainbar, #sidebar").find(resizables).css("fontSize",curSize+"px");
    }
  });
  
});
