I have a sliding navbar that works fine until the mouse is moved too quickly over the links. Each link expands onmouseover and contracts onmouseout. The problem is, the onmouseout event is missed sometimes and then the link doesn't contract. Does anyone have a way to ensure that links are always conctracted when the mouse leaves? I've been trying to fix this for hours with no luck.
navbar = {
links: [],
init: function() {
var Navigation = document.getElementById('navbar');
cleanWhitespace(Navigation);
for(i = 0; i < Navigation.getElementsByTagName('div').length; i++) {
this.links[i] = Navigation.getElementsByTagName('div')[i];
this.links[i].expanding = false;
this.links[i].onmouseover = function(){navbar.slide(this, 1);navbar.cancel(this)};
this.links[i].onmouseout = function(){
this.hide = setTimeout((function(link){return function() {navbar.slide(link, -1);}}(this)), 50);}
for(c = 0; c < this.links[i].childNodes.length; c++) {
if(this.links[i].childNodes[c].nodeType == 1) {
this.links[i].childNodes[c].onmouseover = function() {
navbar.cancel(this.parentNode);}}}}},
slide: function(link, d) {
if(link.expanding == false) {
if(d > 0) link.expanding = true;
link.expander = setInterval((function(link, d){
return function() {
if(d > 0 && link.offsetWidth <= 158 || d < 0 && link.offsetWidth >= 91 && link.expanding == false) {
link.style.width = (link.offsetWidth + 18 * d) + "px";}
else {
clearInterval(link.expander);
if(d > 0) link.expanding = false;}
}}(link, d)), 25);}
},
cancel: function(link) {
clearTimeout(link.hide);
link.exapnding = false;;}
}