$(document).ready(function(){

  //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('');
      if( ((href.match('http://') || href.match('https://') ) && !href.match(base)) || href.match('.pdf') ){
        $(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; }
  });
  
  //input elements
  $("input[type='checkbox']").addClass("checkbox");
  $("input[type='radio']").addClass("radio");
  $("input[type='text'], input[type='password'], textarea")
    .focus(function(){ $(this).addClass("focus"); })
    .blur(function(){ $(this).removeClass("focus"); });
  
  //expandable box for home page
  qmessage = $.trim($(".homeblock.autotech textarea").val());
  $(".homeblock.autotech textarea")
    .focus(function(){
      qval = $.trim($(this).val());
      if(qval == qmessage){
        $(this).val("");
      }
    })
    .blur(function(){
      qval = $.trim($(this).val());
      if(qval == ""){
        $(this).val(qmessage);
      }
    });
  $(".homeblock.autotech button").click(function(){
    $(".homeblock.autotech button").css({
      width: '146px',
      backgroundImage: "url('"+themedir+"/css/images/button/send-question.gif')"
    });
    $(".homeblock.autotech textarea")
      .css({ display: 'block' })
      .animate({ height: '100px' }, 500, function(){
        $(".homeblock.autotech button").attr('type', 'submit');
      });
  });
  
  //about us
  $("#content_71 img:odd").addClass("right");
  
});

function selectDiagnose(which) {
  $("#link_diagnose a").removeClass("selected");
  $("#link_diagnose_"+which).addClass("selected").trigger("blur");
  $("#diagnose div").hide(200);
  $("#diagnose_"+which).show(200);
}
