/* 
t = frames per second 
z = minimum Z-depth of menu
s = seconds of animation / cannot be 0

a = "c" = hover css CLASS style (???)

n = UL id name to use for menu 
g = boolean: is "DropUp" vs. "DropDown"
h = array[]
c = array[]

p = UL id name to use for menu 
f = boolean: is mouseOver vs. mouseOut event
*/

var menu=function(){	

	// START IE 7 DOES NOT SUPPORT ANIMATION
	if (BrowserDetect.browser=="Explorer" && BrowserDetect.version < 8)
	{
		var t=1;
		var z=500;
		var s=1;
		var a;
		var g;
	} else {
		var t=30;
		var z=500;
		var s=2;
		var a;
		var g;
	};
	// END IE 7 CHECK

	// START INSTANTIATE
	function dd(n, g){
		this.n=n;
		this.h=[];
		this.c=[];
		this.g=g;
	};
	// END INSTANTIATE
	
	// START INIT FUNCTION
	dd.prototype.init=function(p,c){
		a = c;
		//if(this.g == true){c.style.top = '-'+c.offsetHeight+'px'}
		var w = document.getElementById(p);
		var s = w.getElementsByTagName('ul');
		var l = s.length;
		var i = 0;

		for(i;i<l;i++){
			var h=s[i].parentNode;
			this.h[i]=h;
			this.c[i]=s[i];
			//BUILD ARRAY FROM UL			
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		};
	};
	// END INIT FUNCTION

	// START GROW FUNTION
	dd.prototype.st=function(x,f){

		var c = this.c[x];
		var h = this.h[x];
		var p = h.getElementsByTagName('a')[0];

		/*
				if(this.g == true){
					c.style.top = '-'+c.offsetHeight+'px';
				};
		*/

		clearInterval(c.t);
		c.style.overflow='hidden';

		if(f){
			p.className+=' '+a;			
			
			if(!c.mh){
				c.style.display='block';
				//c.style.top = '-'+c.offsetHeight+'px';
				c.style.height='';
				c.mh=c.offsetHeight;

				// START IF IT'S SCROLL-UP, THEN POSITIONS ABOVE MENU
				if(this.g == true){c.style.top = '-'+c.mh+'px'}
				// END IF IT'S SCROLL-UP

				c.style.height=0;
			};
			if(c.mh==c.offsetHeight){
				c.style.overflow='visible';
			} else {
				c.style.zIndex = z;
				z++;
				c.t = setInterval(function(){sl(c,1)},t)
			};
		} else {
			p.className=p.className.replace(a,'');
			c.t=setInterval(function(){sl(c,-1)},t);
		};

	};
	// END GROW FUNTION

	// START SHRINK BACK DOWN
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		
		c.style.height=h+(d*f)+'px';
		
	}
	// END SHRINK BACK DOWN

	return{dd:dd}
}();


