var top = 0;
var old_pos = 0;

function startPolling(){ setInterval("poll()",500) }

function poll() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		var position = document.body.scrollTop;
	} else {
		var position = window.pageYOffset;
	}

	if ( old_pos > position ) {
		slideUp();
	} else {
		slideDown();
	}
	
	return true;

}


function init(){
	if(document.getElementById){
		obj = document.getElementById("dinner_div");
		obj.style.top = "-200px";
		obj.style.left = document.getElementById("main_tab").offsetLeft + document.getElementById("main_tab").offsetWidth + 10;

		top = document.getElementById("main_tab").offsetTop - 8;
		
		startPolling();
	}
}

function slideDown(){
	if(document.getElementById){

		if (navigator.appName == "Microsoft Internet Explorer") {
			var position = document.body.scrollTop;
		} else {
			var position = window.pageYOffset;
		}

		top_pos = position;
		if ( top_pos < top ) { top_pos = top; }
		
		if(parseInt(obj.style.top) < top_pos ){
			dist = (top_pos - parseInt(obj.style.top)) / 4;

			if ( dist < 4 ) { dist = 4; }
			if ( dist > 30 ) { dist = 30; }
						
			obj.style.top = parseInt(obj.style.top) + dist + "px";
			setTimeout("slideDown()",50);
		} else {
			old_pos = position;
		}
	}
}

function slideUp(){
	if(document.getElementById){
		if (navigator.appName == "Microsoft Internet Explorer") {
			var position = document.body.scrollTop;
		} else {
			var position = window.pageYOffset;
		}

		top_pos = position;
		if ( top_pos < top ) { top_pos = top; }
		
		if(parseInt(obj.style.top) > top_pos ){
			dist = (parseInt(obj.style.top) - top_pos) / 4;

			if ( dist < 4 ) { dist = 4; }
			if ( dist > 30 ) { dist = 30; }
						
			obj.style.top = parseInt(obj.style.top) - dist + "px";
			setTimeout("slideUp()",50);
		} else {
			old_pos = position;
		}
	}
}
