// When link is rolled over, element will animate to the css in style klass
function add_class_animation_to(link, element, klass){
 //alert("adding class animation to " + element + " on " + link + " mouseover to class " + klass);
 var animator = Animator.apply(element, klass);
 Event.observe(link, "mouseover", function(e){animator.seekTo(1);});
 Event.observe(link, "mouseout", function(e){animator.seekTo(0);});
}

function is_internal(link){
  return (link.href && link.href.indexOf('#') != -1) && ( (link.pathname == location.pathname) || ('/'+link.pathname == location.pathname) );
}

function internal_anchor_name_for(link){
  return link.hash.substr(1);
}

// Smoothly scroll all internal anchored links
function smoothly_scroll_internal(link){
  if(is_internal(link)){
    Event.observe(link, 'click', function(e){new Effect.ScrollTo( internal_anchor_name_for(link) )});
    link.onclick=function(){return false};
  } 
}

// Animate all links, and smoothly scroll internal ones
$$('a').each(function(link){
  var do_not_animate = /do_not_animate/i;
  if(!do_not_animate.exec(link.className)){
    add_class_animation_to(link, link, 'hover');
    smoothly_scroll_internal(link);
  }
});

// Write out some css to kill the :hover action on various a links to avoid a stuttered animation
document.write("<style type='text/css'> #nav li a:hover { color: #046380; } </style> ");
document.write("<style type='text/css'> #footer a:hover { color: #555; } </style> ");

// Animate any fades to zero opacity after a few seconds
$$('.flash').each(function(flash){
 var animator = new Animator({ duration: 1000 }).addSubject(new NumericalStyleSubject(
    flash, 'opacity', 0.4, 0));
    setTimeout(animator.seekTo(1), 4000);
});
