

var DropDown = {


	/* open_menu : function (e) {
		
		scrollDown (ulul.id, 0.0) ;
	}, */
	
	
	scrollDown : function (id, x) {
	
		/* var max = 100 ; */
		var ulul = document.getElementById (id) ;
		if (x == 0) {
			ulul.parentNode.onclick = function () { DropDown.scrollUp(ulul.id, 1) ; }
			//addEvent(ulul.parentNode, 'click', function () { DropDown.scrollUp(ulul.id, 1) ; });
			ulul.setAttribute ('oldBgColor', Fat.get_bgcolor(ulul.id)) ;
			var fade_to = Fat.get_bgcolor (ulul.parentNode.id) ;
			//opera.postError (duration) ;
			Fat.fade_element (ulul.id, '', this.duration, '#', fade_to) ;
		}
		x = parseFloat (x) ;
		x += this.step ;
		var y ;
		y = DropDown.scroll(x) ;
		
		var height = y * ulul.getAttribute('maxHeight') ;
		
		if (x < 1.0) {
			ulul.style.height = height + 'px' ;
			setTimeout ("DropDown.scrollDown ('"+id+"', '"+x+"')", this.timestep) ;
		} else {
			/* ulul.style.backgroundColor='transparent' ; */
		}
	},
	
	scrollUp : function (id, x) {
		var min = 0 ;

		var ulul = document.getElementById (id) ;
		
		if (x == 1) {
			ulul.parentNode.onclick = function () { DropDown.scrollDown(ulul.id, 0) ; }
			//opera.postError (duration) ;
			Fat.fade_element (ulul.id, '', this.duration, '#', ulul.getAttribute ('oldBgColor')) ;
		}	
		
		x = parseFloat (x) ;
		x -= this.step ;
		var y ;
		y = DropDown.scroll(x) ;
		
		var height = y * ulul.getAttribute('maxHeight') ;
		/* alert (height)  */;
		if (x > 0.0) {
			ulul.style.height = height + 'px' ;
			setTimeout ("DropDown.scrollUp ('"+id+"', '"+x+"')", this.timestep) ;
		} else {
		}
	},
	
	scroll : function (x) {
		return -2*x*x*x + 3*x*x ;
	},


	load : function () {
		var ddClassName = 'dropdown' ;
		var ddSubElementName = 'ul' ;
		this.timestep = 10 ;
		this.step = 0.01 ;
		this.duration = (1/this.step) * this.timestep + 500;
		
		var a = getElementsByClassName (ddClassName) ;
		for (var i = 0; i < a.length; i++) {
				if (!a[i].id)
					a[i].id = "menu" +  Math.random() ;
				var ulul = a[i].getElementsByTagName(ddSubElementName)[0] ;
				if (!ulul) {
					ulul = a[i].parentNode.getElementsByTagName(ddSubElementName)[0] ;
				}
				if (!ulul.id) 
					ulul.id = "sub" +  (Math.random() * 100) ;		
				ulul.setAttribute('maxHeight', DropDown.getHeight(ulul)) ;	
				ulul.style.height = '0' ; // hide initially
				a[i].onclick = function(e) { 
					var oNode = window.event ? window.event.srcElement : e.currentTarget;
					DropDown.scrollDown(oNode.getElementsByTagName(ddSubElementName)[0].id, 0.0) ; 
				} ;
				
		}
	},
	
	getHeight : function (el) {
		if (window.getComputedStyle)	
			return window.getComputedStyle(el,"").getPropertyValue('height').replace('px', '') ;	
		else if (el.offsetHeight) 
			return el.offsetHeight ;		
	}

}

function addEvent(obj, evType, fn){
	if(obj.addEventListener){
		obj.addEventListener(evType, fn, false); 
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent('on'+evType, fn);
		return r;
	} else {
		return false;
	}
}

function getElementsByClassName(_clsName) {

	var els = document.getElementsByTagName('*');
	var matches = new Array();
	var regexp = new RegExp("(^|\\s)" + _clsName + "(\\s|$)");
	
	for(var i = 0; i < els.length; i++) {
		if(regexp.test(els.item(i).className)) 
			matches.push(els.item(i));
	}
	return matches;
}

