function menu() {
	if (document.getElementById) {
		var obj = this;
		setTimeout(function() {
			obj.delayinit();
		}, 10);
	}
}
menu.prototype={
delayinit:function() {
	var obj=this;
	$('#vmenu ul>li a').each(function(i) {
		obj.initlink(this);
	});
	$('#vmenu li.l1>a').each(function(i) {
		this.l=false;
	});
	$('#vmenu li.l1>div.p').each(function(i) {
		new popup(obj,this);
		this.par=false;
	});
	this.currentmenu=false;
	this.timer=false;
},
clearuntil:function(div) {
	var cur=this.currentmenu;
	while(cur && cur!=div) {
		cur.close();
		cur=cur.par;
		if(cur) cur=cur.o;
	}
	this.currentmenu=div;
},
initlink:function(a) {
	a.p=false;
	a.app=this;
	a.l=a.parentNode.parentNode.parentNode;
	$(a).bind('mouseover',this.linkover);
	$(a).bind('mouseout',this.clear);
},
linkover:function() {
	var app=this.app;
	if(app.timer) {
		clearTimeout(app.timer);
		app.timer=false;
	}

	if(this.p) {
		if(this.p.visible) {
			app.clearuntil(this.p);
		} else {
			app.clearuntil(this.p.par?this.p.par.o:false);
		}
		if((!this.l) || this.l.o.visible) {
			this.p.show();
		}
	} else {
		if((!this.l) || this.l.o.visible) {
			app.clearuntil(this.l?this.l.o:false);
		}
	}
},
clear:function() {
	app=this.app;
	if(app.timer) {
		clearTimeout(app.timer);
	}
	app.timer=setTimeout(function() {
		app.timer=false;
		app.clearuntil(false);
	},1000);
}
}
function popup(app,div) {
	this.div=div;
	this.div.o=this;
	this.app=app;
	this.a=div.previousSibling;
	this.a.p=this;
	this.visible=false;
	this.par=div.parentNode;
	this.dietime=false;
	var jj=$(this.div);
	$('>ul>li>div.p',jj).each(function(i) {
		new popup(app,this);
	});
	var v,w=0;
	$('>ul>li>a',jj).each(function(i) {
		v=$(this);
		if(v.width()>w) w=v.width();
	});
	$('>ul>li>a',jj).each(function(i) {
		$(this).width(w);
	});
	this.div.style.display='none';
	this.div.style.visibility='visible';
}
popup.prototype={
hidesoon:function() {
	var obj=this;
	if(this.dietime) {
		clearTimeout(this.dietime);
	}
	if(this.visible) {
		this.dietime=setTimeout(function() {
			obj.dietime=false;
			obj.close();
		},1000);
	}
},
show:function() {
	var obj=this;
	if(this.dietime) {
		clearTimeout(this.dietime);
	}
	obj.open();
},
open:function() {
	if(this.dietime) {
		clearTimeout(this.dietime);
	}
	if(!this.app.currentmenu || this.app.currentmenu != this) {
		this.app.currentmenu=this;
		if(!this.visible) {
			this.visible=true;
			$(this.a).toggleClass('o',true);
			$(this.div).stop(true,true).show('normal');
		}
	}
},
close:function() {
	if(this.dietime) {
		clearTimeout(this.dietime);
	}
	if(this.visible) {
		this.visible=false;
		if(this.app.currentmenu==this) {
			this.app.currentmenu=false;
		}
		$(this.a).toggleClass('o',false);
		$(this.div).hide('normal');
	}
}
}
function animate(i){
	this.timeout=false;
	this.initted=false;
	this.start(i);
}
animate.prototype={
step:function(){
	var obj=this;
	this.image++;
	if(this.image>=this.images.length){
		this.image=0;
	}
	this.next=this.frame;
	this.frame=1-this.frame;
	this.frames[this.frame].css('z-index',33);
	this.frames[this.next].css('z-index',32);
	this.frames[this.frame].empty().append(this.images[this.image]);
	this.frames[this.frame].fadeIn(2000,function() { obj.frames[obj.next].hide(); });
	this.timeout=setTimeout(function(){ obj.step(); },5000);
},
stop:function(){
	if(this.timeout) {
		clearTimeout(this.timeout);
		this.timeout=false;
		this.frames[this.next].hide();
		this.frames[this.frame].hide();
	}
},
start:function(i){
	var x,ct,obj=this;
	this.i=i;
	if (!this.initted) {
		this.initted=true;
		this.frames=[];
		this.frames[0]=$('<div/>');
		this.frames[1]=$('<div/>');
		var l=$('#animate');
		$.each(this.frames,function(j) {
			this.addClass('flash');
			this.appendTo(l);
		});
	}
	this.images=[];
	for(x=0,ct=i.length;x<ct;x++){
		this.images[x]=new Image();
		this.images[x].src='/homepage.nb?nb%5Bop%5D=image&nb%5Bsize%5D=2&nb%5Bid%5D='+i[x];
	}
	this.image=0;
	this.frame=1;
	this.next=0;
	this.frames[1].css('z-index',33);
	this.frames[0].css('z-index',32);
	this.frames[1].empty().append(this.images[0]);
	this.frames[1].show();
	this.frames[0].hide();
	if(this.images.length>1) {
		this.timeout=setTimeout(function(){ obj.step(); },3000);
	}
}
}

