/* ------ page (RM) ------ */

var scrolling_up = null;
var scrolling_down = null;

var max;
var min;

var top;

function init_page(menu_name)
{
	/* alert("init_page!!!!"); */
	
	var main_body_height = 375;

	// parent.document.getElementById("main_body").style.height = main_body_height;

	var scrolling = false;

	if (window.page_ifr.window.document.getElementById("paragraph_text"))
	{
		var paragraph_text_height = window.page_ifr.window.document.getElementById("paragraph_text").clientHeight;

		if (parseInt(paragraph_text_height) > parseInt(main_body_height) - 48)
		{
			document.getElementById("scroll_arrows").style.display = "block";
			document.getElementById("main_body_center").style.height = parseInt(main_body_height) - 30;
			scrolling = true;
		}
		else
		{
			document.getElementById("scroll_arrows").style.display = "none";
			document.getElementById("main_body_center").style.height = parseInt(main_body_height);
		}
		
		if (window.page_ifr.window.document.getElementById("paragraph_head"))
		{
			var paragraph_head_height = window.page_ifr.window.document.getElementById("paragraph_head").clientHeight;
			min = paragraph_head_height;
			window.page_ifr.window.document.getElementById("paragraph_text").style.top = min;
		}

		window.page_ifr.window.document.getElementById("paragraph_text").style.visibility = "visible";
	}
	else
	{
		document.getElementById("main_body_center").style.height = parseInt(main_body_height);
	}

	top = min;

	if (scrolling)
	{
		if (parent.browser == "MSIE")
		{
			window.onmousewheel = document.onmousewheel = wheel;
			window.page_ifr.onmousewheel = window.page_ifr.window.document.onmousewheel = wheel_page;
		}
		else
		{
			window.addEventListener('DOMMouseScroll', wheel, false);
		}

		max = (parseInt(window.page_ifr.window.document.getElementById("paragraph_text").clientHeight) * (-1)) + 305;
	}

	parent.document.getElementById("store_name").value = window.page_ifr.window.document.getElementById("current_user").value;

	parent.check_login();
}

function hide_arrows()
{
	/* alert("hide_arrows"); */

	document.getElementById("scroll_arrows").style.display = "none";
}

function scroll_down_on()
{
	if (scrolling_down == null) scrolling_down = setTimeout('scroll_down()', 50);
}

function scroll_down_off()
{
	if (scrolling_down != null)
	{
		clearTimeout(scrolling_down);
		scrolling_down = null;
	}
}

function scroll_down()
{
	if (top <= max)
	{
		// top = max;
		clearTimeout(scrolling_down);
		scrolling_down = null;
	}
	else
	{
		top = parseInt(top) - 5;
		scrolling_down = setTimeout('scroll_down()', 50);
	}

	window.page_ifr.window.document.getElementById("paragraph_text").style.top = top;
}

function scroll_up_on()
{
	if (scrolling_up == null) scrolling_up = setTimeout('scroll_up()', 50);
}

function scroll_up_off()
{
	if (scrolling_up != null)
	{
		clearTimeout(scrolling_up);
		scrolling_up = null;
	}
}

function scroll_up()
{
	if (top >= min)
	{
		// top = min;
		clearTimeout(scrolling_up);
		scrolling_up = null;
	}
	else
	{
		top = parseInt(top) + 5;
		scrolling_up = setTimeout('scroll_up()', 50);
	}

	window.page_ifr.window.document.getElementById("paragraph_text").style.top = top;
}

function arrow_up_normal(arrow)
{
	arrow.src = parent.baseURL + "img/scroll_up.gif";
}

function arrow_up_over(arrow)
{
	arrow.src = parent.baseURL + "img/scroll_up_over.gif";
}

function arrow_down_normal(arrow)
{
	arrow.src = parent.baseURL + "img/scroll_down.gif";
}

function arrow_down_over(arrow)
{
	arrow.src = parent.baseURL + "img/scroll_down_over.gif";
}

function wheel(event)
{
	if (parent.browser == "MSIE")
	{
		event = window.event;
	}
	if (event.wheelDelta) /* IE / Opera. */
	{ 
		delta = event.wheelDelta/120;
		/** In Opera 9, delta differs in sign as compared to IE. */
		if (window.opera) delta = -delta;
	}
	else if (event.detail) /* Mozilla */
	{ 
		delta = (-event.detail/3);
	}

	/** If delta is nonzero, handle it.
	 * delta is positive if wheel was scrolled up
	 * delat is negative if wheel was scrolled down
	 */
	if (delta)
			handle(delta);

	/** Prevent default actions caused by mouse wheel.
	 */
	if (event.preventDefault)
			event.preventDefault();
					
	event.returnValue = false;
}

function wheel_page(event)
{
	if (parent.browser == "MSIE")
	{
		event = window.page_ifr.window.event;
	}
	if (event.wheelDelta) /* IE / Opera. */
	{ 
		delta = event.wheelDelta/120;
		/** In Opera 9, delta differs in sign as compared to IE. */
		if (window.page_ifr.window.opera) delta = -delta;
    }
	else if (event.detail) /* Mozilla */
	{ 
		delta = (-event.detail/3);
	}

	/** If delta is nonzero, handle it.
	 * delta is positive if wheel was scrolled up
	 * delat is negative if wheel was scrolled down
	 */
	if (delta)
			handle(delta);
	
	/** Prevent default actions caused by mouse wheel.
	 */
	if (event.preventDefault)
			event.preventDefault();
					
	event.returnValue = false;
}

function handle(delta)
{
	if (delta < 0)
	{
		if (top > max)
		{
			delta = delta * 15;
			var new_top = parseInt(top) + delta;

			if (new_top < max)
			{
				new_top = max;
			}

			top = new_top;
			window.page_ifr.window.document.getElementById("paragraph_text").style.top = top;
		}
	}
	else
	{
		if (top < min)
		{
			delta = delta * 15;
			var new_top = parseInt(top) + delta;

			if (new_top > min)
			{
				new_top = min;
			}

			top = new_top;
			window.page_ifr.window.document.getElementById("paragraph_text").style.top = top;
		}
	}
}
