var cadded = false;

function openmenu() {
	opened = -1;
	switchmenu(4);
}

function closemenu() {
	opened = 1;
	switchmenu(4);
}

function resizemenu() {
	opened = 0;
	switchmenu(0);
}

sfHover2 = function() {
	var sfEls = document.getElementById("t_menu").getElementsByTagName("div");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].className=sfEls[i].className.replace("over", "");
	}
}


function switchmenu(offset) {
	this.toparea_el = document.getElementById('toparea');
	this.tmenu_el = document.getElementById('t_menu');
	this.tmenu_opener = document.getElementById('menuopener');

	if(!this.sheight){
		this.toparea_el.className="smallmenu";
		this.sheight=parseInt(this.toparea_el.clientHeight) - offset;
	}
		this.toparea_el.className="bigmenu";
		if(this.toparea_el.clientHeight > this.tmenu_el.clientHeight){
			this.bheight=parseInt(this.toparea_el.clientHeight);
		}else{
			this.bheight=parseInt(this.tmenu_el.clientHeight);
		}

	if (opened == 1) {
		this.toparea_el.style.overflow="visible";
		this.toparea_el.className="smallmenu";
		this.tw=new Tween(this.toparea_el.style,'height',Tween.strongEaseOut,this.bheight,this.sheight,0.4,'px');
		this.tw2=new Tween(tmenu_opener.style,'top',Tween.strongEaseOut,this.bheight+7,this.sheight+7,0.4,'px');
		this.tw.start();
		this.tw2.start();
		this.tmenu_el.style.display="block";
		opened = -1;
		sfHover2();
	} else if(opened == -1) {
		this.toparea_el.style.overflow="hidden";
		this.toparea_el.className="bigmenu";
		this.tw2=new Tween(this.toparea_el.style,'height',Tween.strongEaseOut,this.sheight,this.bheight,0.4,'px');
		this.tw2.start();
		this.tmenu_el.style.display="block";
		opened = 1;
		sfHover2();
	} else {
		this.bheight=parseInt(this.tmenu_el.clientHeight);
		this.tw2=new Tween(this.toparea_el.style,'height',Tween.strongEaseOut,this.old_bheight,this.bheight,0.4,'px');
		this.tw2.start();		
		sfHover2();
	}
}