$(function() {
    $("#menu li a").click(function() {
        
        // Figure out current list via CSS class
        var curList = $("#menu li a.current").attr("rel");
        
        // List moving to
        var $newList = $(this);
        
        // Set outer wrapper height to height of current inner list
        var curListHeight = $("#contents").height();
        $("#contents").height(curListHeight);
        
        // Remove highlighting - Add to just-clicked tab
        $("#menu li a").removeClass("current");
        $newList.addClass("current");
        
        // Figure out ID of new list
        var listID = $newList.attr("rel");
        
        if (listID != curList) {
            
            // Fade out current list
            $("#"+curList).fadeOut(80, function() {
                
                // Fade in new list on callback
if(window.attachEvent){
    $("#"+listID).fadeIn(120,function(){ this.style.removeAttribute("filter"); });
}
else if(window.addEventListener){
    $("#"+listID).fadeIn();
}
                // Adjust outer wrapper to fit new list snuggly
                var newHeight = $("#"+listID).height();
                $("#contents").animate({
                    height: newHeight
                });
            });
            
        }        
        
        // Don't behave like a regular link
        return false;
    });

});

$(document).ready(function(){
$("#fm li:last-child a").css("margin-bottom","0");
$("#cm li:last-child a").css("margin-bottom","0");
});

function anchor(targetID){
  if( !document.getElementById ) {return true;}
  var step=10;  //initial speed
  var max=400;  //max speed
  var accel=4;  //accelerate
  var interval=30;  //accel intarval
  var current_y = document.body.scrollTop  || document.documentElement.scrollTop;
  var element=document.getElementById(targetID);
  if (!element){return true;}
  var target_y = 0;
  for (i = element;i.offsetParent;i=i.offsetParent ){
    target_y += i.offsetTop;
  }
  var count=0;
  if ( current_y > target_y ){ step = -(step); accel = -(accel);}
  var timerid = setInterval( function(){
    if (step<max) step += (count*accel);
    if ( Math.abs(current_y-target_y) < Math.abs(step) ){
      window.scrollTo((document.body.scrollTop  || document.documentElement.scrollTop),target_y);
      clearInterval(timerid);
      return false;
    }else{
      window.scrollBy(0,step);
      current_y += step;
      count++;
    }
  },interval);
  return false;
}

window.onload = function() {
    var nodes = document.getElementsByTagName('a');
    for (var i=0; i<nodes.length; i++) {
        if (nodes[i].rel == 'external') {
            nodes[i].onclick = nodes[i].onkeypress = function() {
                window.open(this.href,'');
                return false;
            }
        }
    }
}


$(function() {
    $(".menulink").click(function() {
        // Figure out current list via CSS class
        var curList = $("#menu li a.current").attr("rel");
        // List moving to
        var $newList = $(this);
        // Set outer wrapper height to height of current inner list
        var curListHeight = $("#contents").height();
        $("#contents").height(curListHeight);
        // Remove highlighting - Add to just-clicked tab
        $("#menu li a").removeClass("current");
        $("#ex-m04 a").addClass("current");
        // Figure out ID of new list
        var listID = $newList.attr("rel");
        if (listID != curList) {
            // Fade out current list
            $("#"+curList).fadeOut(80, function() {
                // Fade in new list on callback
if(window.attachEvent){
    $("#"+listID).fadeIn(120,function(){ this.style.removeAttribute("filter"); });
}
else if(window.addEventListener){
    $("#"+listID).fadeIn();
}
                // Adjust outer wrapper to fit new list snuggly
                var newHeight = $("#"+listID).height();
                $("#contents").animate({
                    height: newHeight
                });
            });
            
        }        
        // Don't behave like a regular link
        return false;
    });
});
