function sdmenu(id) { if (!document.getelementbyid || !document.getelementsbytagname) return false; this.menu = document.getelementbyid(id); this.submenus = this.menu.getelementsbytagname("div"); this.remember = false; this.speed = 3; this.markcurrent = true; this.onesmonly = false; } sdmenu.prototype.init = function() { var maininstance = this; for (var i = 0; i < this.submenus.length; i++) this.submenus[i].getelementsbytagname("span")[0].onclick = function() { maininstance.togglemenu(this.parentnode); }; if (this.markcurrent) { var links = this.menu.getelementsbytagname("a"); for (var i = 0; i < links.length; i++) if (links[i].href == document.location.href) { links[i].classname = "current"; break; } } if (this.remember) { var regex = new regexp("sdmenu_" + encodeuricomponent(this.menu.id) + "=([01]+)"); var match = regex.exec(document.cookie); if (match) { var states = match[1].split(""); for (var i = 0; i < states.length; i++) this.submenus[i].classname = (states[i] == 0 ? "collapsed" : ""); } } }; //download by http://www.jb51.net sdmenu.prototype.togglemenu = function(submenu) { if (submenu.classname == "collapsed") this.expandmenu(submenu); else this.collapsemenu(submenu); }; sdmenu.prototype.expandmenu = function(submenu) { var fullheight = submenu.getelementsbytagname("span")[0].offsetheight; var links = submenu.getelementsbytagname("a"); for (var i = 0; i < links.length; i++) fullheight += links[i].offsetheight; var moveby = math.round(this.speed * links.length); var maininstance = this; var intid = setinterval(function() { var curheight = submenu.offsetheight; var newheight = curheight + moveby; if (newheight < fullheight) submenu.style.height = newheight + "px"; else { clearinterval(intid); submenu.style.height = ""; submenu.classname = ""; maininstance.memorize(); } }, 30); this.collapseothers(submenu); }; sdmenu.prototype.collapsemenu = function(submenu) { var minheight = submenu.getelementsbytagname("span")[0].offsetheight; var moveby = math.round(this.speed * submenu.getelementsbytagname("a").length); var maininstance = this; var intid = setinterval(function() { var curheight = submenu.offsetheight; var newheight = curheight - moveby; if (newheight > minheight) submenu.style.height = newheight + "px"; else { clearinterval(intid); submenu.style.height = ""; submenu.classname = "collapsed"; maininstance.memorize(); } }, 30); }; sdmenu.prototype.collapseothers = function(submenu) { if (this.onesmonly) { for (var i = 0; i < this.submenus.length; i++) if (this.submenus[i] != submenu && this.submenus[i].classname != "collapsed") this.collapsemenu(this.submenus[i]); } }; sdmenu.prototype.expandall = function() { var oldonesmonly = this.onesmonly; this.onesmonly = false; for (var i = 0; i < this.submenus.length; i++) if (this.submenus[i].classname == "collapsed") this.expandmenu(this.submenus[i]); this.onesmonly = oldonesmonly; }; sdmenu.prototype.collapseall = function() { for (var i = 0; i < this.submenus.length; i++) if (this.submenus[i].classname != "collapsed") this.collapsemenu(this.submenus[i]); }; sdmenu.prototype.memorize = function() { if (this.remember) { var states = new array(); for (var i = 0; i < this.submenus.length; i++) states.push(this.submenus[i].classname == "collapsed" ? 0 : 1); var d = new date(); d.settime(d.gettime() + (30 * 24 * 60 * 60 * 1000)); document.cookie = "sdmenu_" + encodeuricomponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.togmtstring() + "; path=/"; } };