/*---- accordion function ----*/
window.addEvent('domready', function() {
    var _hold = $('menu');
	if(_hold){
		var _list = _hold.getChildren('li');
		var _a = -1;
		_list.each(function(_el, _ind){
			_el._box = _el.getChildren('ul')[0];
			_el._btn = _el.getChildren('a')[0];
			if(_el._box){
				if(_el.hasClass('active')){
					_el._box.setStyles({display: 'block', overflow: 'visible'});
					_a = _ind;
				}
				else{
					_el._box.setStyles({display: 'none', overflow: 'hidden'});
				}
				_el._box.moo = new Fx.Tween(_el._box, {
					duration: 400,
					link:'cancel',
					'onComplete': function(_bx){
						if(_bx.getParent().hasClass('active')) _bx.setStyles({height: 'auto', overflow: 'visible'});
						else _bx.setStyles({display: 'none', height: 'auto'});
					}
				});
				_el._btn.onclick = function(){
					changeEl(_ind);
					return false;
				}
			}
		});
		function changeEl(_ind){
			if(_a != -1){
				_list[_a].removeClass('active');
				_list[_a]._box.setStyles({height: _list[_a]._box.offsetHeight+'px', overflow: 'hidden'})
				_list[_a]._box.moo.start('height', 0);
			}
			if(_ind != _a){
				_list[_ind].addClass('active');
				if(_list[_ind]._box.getStyle('display') == 'none'){
					_list[_ind]._box.setStyle('display', 'block');
					_list[_ind]._h = _list[_ind]._box.offsetHeight;
					_list[_ind]._box.setStyles({height: 0, overflow: 'hidden'});
				}
				_list[_ind]._box.moo.start('height', _list[_ind]._h + 'px');
				_a = _ind;
			}
			else{
				_a = -1;
			}
		}
	}
});


/*--- ie hover function ----*/
hover = function() {
	var nav = document.getElementById("menu");
	if(nav){
		var nodes = nav.getElementsByTagName("li")
		for (var i=0; i<nodes.length; i++) {
			nodes[i].onmouseover=function() {
				this.className+=" hover";
			}
			nodes[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" hover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", hover);
