var DDSPEED = 5; var DDTIMER = 15; window.onload=function(){ ddsetHandle('ss');ddsetHandle('re');ddsetHandle('rc');ddsetHandle('ad');} // set Event Handler // function ddsetHandle(id){ var h = document.getElementById(id + '-ddheader'); var c = document.getElementById(id + '-ddcontent'); h.onmouseover=function(){ ddMenu(h, c, 1); } h.onmouseout=function(){ ddMenu(h, c, -1); } c.onmouseover=function(){ cancelHide(h, c); } c.onmouseout=function(){ ddMenu(h, c, -1); } ddMenu(h, c, -1); } // main function to handle the mouse events // function ddMenu(h, c, d){ clearTimeout(h.timer); if(!c.maxh) { c.style.overflow = 'hidden'; if(c.id == 'hm-ddcontent'){ var a = c.style.width; c.style.width = 'auto'; c.maxh = c.offsetWidth; c.style.width = a; } else { var a = c.style.height; c.style.height = 'auto'; c.maxh = c.offsetHeight; c.style.height = a; } } if(d == 1){ if((c.maxh <= c.offsetHeight && c.id != 'hm-ddcontent') || (c.maxh <= c.offsetWidth && c.id == 'hm-ddcontent') || c.style.display != 'none'){return} clearInterval(c.timer); c.style.display = 'block'; if(c.id == 'hm-ddcontent'){ c.style.width = '1px'; } else { c.style.height = '1px'; } c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER); }else{ if(c.id != 'hm-ddcontent') { h.timer = setTimeout(function(){ddCollapse(c)}, Math.floor(Math.random() * 5000) + 10000); } else { h.timer = setTimeout(function(){ddCollapse(c)}, Math.floor(Math.random() * 3500) + 16500); } } } // collapse the menu // function ddCollapse(c){ c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER); } // cancel the collapse if a user rolls over the dropdown // function cancelHide(h, c){ var h = document.getElementById(id + '-ddheader'); var c = document.getElementById(id + '-ddcontent'); clearTimeout(h.timer); clearInterval(c.timer); if(c.offsetHeight < c.maxh){ c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER); } } // incrementally expand/contract the dropdown and change the opacity // function ddSlide(c,d){ var currh; var dist; var thres; if(c.id == 'hm-ddcontent'){ currh = c.offsetWidth; thres = 3; } else { currh = c.offsetHeight; thres = 3; } if(d == 1){ dist = (Math.round((c.maxh - currh) / DDSPEED)); }else{ dist = (Math.round(currh / DDSPEED)); } if(dist < thres && d != 1) { if(c.id == 'hm-ddcontent'){ c.style.width = '0px'; } else { c.style.height = '0px'; } c.style.display = 'none'; c.style.opacity = 0; clearInterval(c.timer); } else if(dist < thres && d == 1) { if(c.id == 'hm-ddcontent'){ c.style.width = c.maxh + 'px'; } else { c.style.height = c.maxh + 'px'; } c.style.opacity = 1; clearInterval(c.timer); } else { if(c.id == 'hm-ddcontent'){ c.style.width = currh + (dist * d) + 'px'; } else { c.style.height = currh + (dist * d) + 'px'; } c.style.opacity = currh / c.maxh; } }