/*
 * Bar Control
 */


var MenuPanel = 
{
	now : function(){
		var d = new Date();
		return d * 1 / 1000;
	},
	val : 0,
	starttime : 0,
	timerid  : false, //  current timer id
	elm : null,
	open : 0,
	marginheight: 80,
	ef : false,
	bh : false,
	clear_timer : function()
		{
			if (this.timerid){
				clearTimeout(this.timerid);
				this.timerid = false;
			}
			this.starttime = 0;
		},
	set_height : function(marginheight)
		{
			if (!this.ef){
				this.ef = document.getElementById("sframe");
			}
			if (!this.bh){
				this.bh = document.getElementById("barheader");
			}
			if (this.ef && this.bh){
				this.ef.style.top = (48 + marginheight) + "px";
				this.bh.style.height = (48 + marginheight) + "px";
				this.resizeFrame(marginheight);
			}
		},
	hide : function()
		{
			if (this.timeid) return false;
			if (this.marginheight == 0) return false;
			if (!this.timerid){
				this.starttime = this.now();
				this.timerid = setTimeout("MenuPanel.hiderun()", 15);
			}
		},
	hiderun : function()
		{
			var current = (this.now() - this.starttime);
			if (current >= 0.333){
				// end
				this.set_height(0);
				this.open = 0;
				this.clear_timer();
			}else{
				this.set_height(80 * (1 - current * 3) );
				// scroll
				this.timerid = setTimeout("MenuPanel.hiderun()", 15);
			}
		},
	show : function()
		{
			if (this.timerid) return false;
			if (this.marginheight == 80) return false;
			this.starttime = this.now();
			this.set_height(0);
			this.timerid = setTimeout("MenuPanel.showrun()", 15);
		},
	showrun : function()
		{
			var current = (this.now() - this.starttime);
			if (current >= 0.333){
				// end
				this.set_height(80);
				this.open = 1;
				this.clear_timer();
			}else{
				// scroll
				this.set_height(80 * current * 3);
				this.timerid = setTimeout("MenuPanel.showrun()", 15);
			}
		},
	toggle : function()
		{
			if (this.open){
				this.hide();
			}else{
				this.show();
			}
		},
	resizeFrame : function(marginheight)
		{
			var my_width = 0, my_height = 0;
			if (marginheight < 0) marginheight = this.marginheight;
			this.marginheight = marginheight;
			if (typeof(window.innerWidth ) == 'number')
			{
				my_width = window.innerWidth;
				my_height = window.innerHeight;
			}else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
			{
				my_width = document.documentElement.clientWidth;
				my_height = document.documentElement.clientHeight;
			}else if (document.body && (document.body.clientWidth || document.body.clientHeight)){
				my_width = document.body.clientWidth;
				my_height = document.body.clientHeight;
			}
			if (my_width){
				var s = document.getElementById("sframe");
				if (s){
					s.height = "" + (my_height - 48 - marginheight) + "px";
					s.width = "" + (my_width - 0) + "px";
				}
			}
		}
}


/*
 * funcs
 */

function scroll_to_top()
{
	document.body.scrollTop = 0;
}





