
	function ball_menu_item(container) {
		this.container = container;
		
		this.ball = null;
		this.ball_active = null;
		
		this.shadow = null;
		this.shadow_high = null;
		
		this.ico = null;
		
		this.locked = false;
		
		this.hover = false;
		this.lift = false;
		this.bef_opacity = 0;
		this.opacity = 0;
		this.top = 0;
		this.bef_top = 0;
		this.mass = 0;
		this.push = 0;
		this.jumps = 0;
		this.max = 40;
		
		this.simple = (/MSIE 6/i.test(navigator.userAgent)) || (/MSIE 7/i.test(navigator.userAgent));
	}
	
	ball_menu_item.prototype.construct = function() {
		if (this.container.className != "active active_force") {
			
			var current, stack = new Array();
			stack[0] = this.container;
			
			while (stack.length > 0) {
				current = stack.pop();
				
				if (current.tagName.toUpperCase() == "SPAN") {
					switch (current.className) {
						case "ball" :
							this.ball = current;
							break;
							
						case "ball ball_active" :
							this.ball_active = current;
							break;
							
						case "shadow" :
							this.shadow = current;
							break;
							
						case "shadow shadow_high" :
							this.shadow_high = current;
							break;
							
						default :
							if (current.className.length >= 3 && current.className.substr(0, 3) == "ico")
								this.ico = current;
							break;
					}
				}
				
				if (current.childNodes.length > 0) {
					var f;
					for (f = 0; f < current.childNodes.length; f++)
						if (current.childNodes[f].nodeType == 1) stack[stack.length] = current.childNodes[f];
				}
			}
			
			var self = this;
			this.container.onmouseover = function() {
				self.hover = true;
				self.lift = true;
			}
			this.container.onmouseout = function(trgEvent) {
				var evt = trgEvent == null ? event : trgEvent;
				var target = evt.toElement == null ? evt.relatedTarget : evt.toElement;
				
				while (target != null && target != self.container) target = target.parentNode;
				
				if (target == null) {
					self.hover = false;
					self.mass = 0;
					self.jumps = 0;
				}
			}
		
		} else {
			this.locked = true;
		}
	}
	
	ball_menu_item.prototype.loop = function() {
		if (!this.locked) {
			this.bef_opacity = this.opacity;
			this.bef_top = this.top;
			
			if (this.hover || this.lift) {
				this.opacity += 15;
				if (this.opacity > 100) {
					this.opacity = 100;
					this.lift = false;
					this.push = 0;
					if (!this.hover) {
						this.mass = 0;
						this.jumps = 0;
					}
				}
			} else {
				this.opacity += -10;
				if (this.opacity < 0) this.opacity = 0;
			}
			
			if (this.hover || this.lift) {
				this.mass += 1.9;
				if (this.mass > 8) this.mass = 8;
			} else {
				if (this.top != 0 || this.mass != 0) {
					//this.push += 0.1;
					this.mass += - 1.1;
				}
			}
			
			this.top += this.mass;
			if (this.top <= 0) {
				this.top = 0;
				this.push = 0;
				if (this.jumps < 1) {
					this.mass = this.mass * - 0.8;
					this.jumps++;
				} else {
					this.mass = 0;
				}
				
			} else if (this.top > this.max) {
				this.top = this.max;
			}
		}
	}
	
	ball_menu_item.prototype.update = function() {
		if (!this.locked) {
			if (this.bef_top != this.top || this.bef_opacity != this.opacity) {
				if (!this.simple) {
					this.ball_active.style.opacity = this.opacity / 100.0;
					this.ball_active.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/web/vetnemo/gfx/ball_a.png')Alpha(opacity=" + this.opacity + ")";
				}
				
				var ratio = this.top / this.max;
				
				this.shadow.style.opacity = 1.0 - ratio;
				this.shadow_high.style.opacity = ratio;
				
				if (!this.simple) {
					this.shadow.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/web/vetnemo/gfx/sh_low.png')Alpha(opacity=" + ((1.0 - ratio) * 100) + ")";
					this.shadow_high.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/web/vetnemo/gfx/sh_high.png')Alpha(opacity=" + (ratio * 100) + ")";
				} else {
					this.shadow.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/web/vetnemo/gfx/sh_low.png')";
					this.shadow_high.style.display = "none";
				}
				
				this.ball.style.bottom = (43 + this.top) + "px";
				this.ball_active.style.bottom = (43 + this.top) + "px";
				this.ico.style.bottom = (43 + this.top) + "px";
				
				this.container.className = this.hover ? "active" : "";
			}
		}
	}
	
	
	function ball_menu() {
		this.items = null;
		this.update_flag = false;
	}
	
	ball_menu.prototype.construct = function() {
		this.items = new Array();
	}
	
	ball_menu.prototype.add_container = function(container) {
		var ref = new ball_menu_item(container);
		this.items[this.items.length] = ref;
		ref.construct();
		return ref;
	}
	
	ball_menu.prototype.add_menu = function(container) {
		var f;
		for (f = 0; f < container.childNodes.length; f++) {
			if (container.childNodes[f].nodeType == 1 && container.childNodes[f].tagName.toUpperCase() == "LI") 
				this.add_container(container.childNodes[f]);
		}
	}
	
	ball_menu.prototype.loop = function() {
		var f;
		for (f = 0; f < this.items.length; f++)
			this.items[f].loop();
	}
	
	ball_menu.prototype.update = function() {
		if (!this.update_flag) {
			this.update_flag = true;
			
			var f;
			for (f = 0; f < this.items.length; f++)
				this.items[f].update();
			
			this.update_flag = false;
			
			return true;
		}
		
		return false;
	}
