﻿var iframe, main, n_wheight, n_step, n_timeout, n_interval, n_pos, n_cur, prior, n_astep, height, limitHeight;
function getElem(div) {
	return parent.document.getElementById ? parent.document.getElementById(div) : parent.document.all[div]
}

function init(p) {
	iframe= getElem('newsbox');
	main= parent.window.frames['newsbox'].document.getElementById('ezkell');
	n_wheight = parseInt(iframe.scrollHeight);  //600
	if (n_wheight <= 0)
	{
		setTimeout('init()',100)
		return;
	}
	n_step = 1;
	if (p)
		n_timeout= n_interval= prior= n_cur= 0;
	else
	{
		n_timeout=n_interval = n_pos = n_cur = prior = 0;
	}
	n_astep = Math.abs(n_step);
//	alert("nheight= "+n_wheight);
	height= parseInt(main.scrollHeight);//+10;
	limitHeight= parseInt(-(height/2));
//	alert("limit= "+limitHeight);
//	alert("height= "+height);
//	alert(main.innerHTML.toString())
//	alert(parent.document.getElementById('gyorsmenuk').scrollHeight)
//	alert(iframe.clientHeight)	
//	alert(parent.document.getElementById('gyorsmenuhely').style.height)
	
	if ( height/2 <= n_wheight )
	{
		var ojj= parent.window.frames['newsbox'].document.getElementById('tartalom_2');

		ojj.style.visibility= 'hidden';
	}
	else
	{
		if (p)
		{
			if (n_timeout != 0)
			{
				clearTimeout(n_timeout);
			}
			movedown(1);
		}
		else
		{
			if (n_timeout == 0)
				n_timeout= setTimeout("movedown(1)",50); 
		}
	}
	main.style.visibility= 'visible';
}


// internal control methods
function moveup(p) { 
	n_step = -n_astep; 
	if (prior <= p && n_interval == 0) {	
		prior = 0
		n_interval = setInterval("rollup()", 60) 
	}
} 

function movedown(p) { 
	n_step = n_astep; 
	if (prior <= p && n_interval == 0) {	
		prior = 0
		n_interval = setInterval("rolldown()", 60) 
	}
} 

function stop(p) { 
	if (prior < p) prior = p
	if (n_timeout != 0) {
		clearTimeout(n_timeout)
		n_timeout = 0
	}
	if (n_interval != 0) {
		clearInterval(n_interval)
		n_interval = 0
	}
}

var ajust = function () { 
	main.style.position= 'relative';
	main.style.top = n_pos ;
	//window.status=rate;
	//main.style.visibility= 'hidden'
	//iframe.style.pos= n_pos;
};

function rollup() {	
	if (n_pos < 0 && 0 <= n_pos + n_astep ) {
		n_pos = 0
		ajust()
		return stop(1)
	}
	else if ( n_pos == 0 ) {
		ajust()
	}
	else if ( n_pos < 0 ) {
		n_pos -= n_step;
		ajust();
	}
}

function rolldown() {	
	var delta = n_wheight - height;
	if (limitHeight <= n_pos && n_pos <= n_astep + limitHeight) {
		n_pos = 0
		ajust()
//		return stop(1)
	}
	else if ( n_pos == limitHeight ) {
		n_pos= 0;
		ajust();
	}
	else if ( n_pos <= 0 && limitHeight < n_pos ) {
		n_pos -= n_step
		ajust()
	}
}

function moveToTop() {
	n_pos= 0;
	ajust();
}