// MyScroll Object
// gives controls to a set of 2 layers for scrolling
// 19990410

// 20000718
// modified by Masahiko Ishida @ Architectural Systems Inc.
// I add a function to be able to load external file.
// However, I need this widget to be more useful...

// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/

function MyScroll(window,content,external) {
	this.window = window
	this.obj = window.obj + "MyScroll"
	eval(this.obj + "=this")
	if (!is.ns4 && external) {
		this.iframe = content
	}
	else {
		if (external) eval('this.content = '+content);
		else this.content = content;
	}
	this.inc = 8
	this.speed = 20
	this.activated = false
	this.activate()
}

MyScroll.prototype.activate = function()
{
	if (!this.iframe) {
		this.contentHeight = (is.ns) ? this.content.doc.height : this.content.elm.scrollHeight
		this.contentWidth = (is.ns) ? this.content.doc.width : this.content.elm.scrollWidth
		this.offsetHeight = this.contentHeight-this.window.h
		this.offsetWidth = this.contentWidth-this.window.w
		this.enableVScroll = (this.offsetHeight>0)
		this.enableHScroll = (this.offsetWidth>0)
	}
	this.activated = true;
}

MyScroll.prototype.up = function(inc,speed)
{
	var dx = (inc == null) ? this.inc : inc
	var sp = (speed == null) ? this.speed : speed
	if (!this.activated) { this.activate(); }
	if (this.iframe) { 
		this.iframescrollstart(0,-dx,sp)
	}
	else {
		if (this.enableVScroll) 
			this.content.slideTo(null,0,dx,sp)
	}
}
MyScroll.prototype.down = function(inc,speed)
{
	var dx = (inc == null) ? this.inc : inc
	var sp = (speed == null) ? this.speed : speed
	if (!this.activated) { this.activate(); }
	if (this.iframe) { 
		this.iframescrollstart(0,dx,sp)
	}
	else {
		if (this.enableVScroll)
			this.content.slideTo(null,-this.offsetHeight,dx,sp)
	}
}

MyScroll.prototype.left = function()
{
	if (!this.activated) { this.activate(); }
	if (this.iframe) {
		this.iframescrollstart(-this.inc,0,this.speed)
	}
	else {
		if (this.enableHScroll)
			this.content.slideTo(0,null,this.inc,this.speed)
	}
}

MyScroll.prototype.right = function()
{
	if (!this.activated) { this.activate(); }
	if (this.iframe) {
		this.iframescrollstart(this.inc,0,this.speed)
	}
	else {
		if (this.enableHScroll) this.content.slideTo(-this.offsetWidth,null,this.inc,this.speed)
	}
}

MyScroll.prototype.stop = function()
{
	if (this.iframe) {
		this.iframeScrollActive = false
	}
	else {
		this.content.slideActive = false
	}
}

MyScroll.prototype.iframescrollstart = function(dx,dy,speed)
{
	if (this.iframeScrollActive) return
	this.iframeScrollActive = true
	this.iframescroll(dx,dy,speed)
}

MyScroll.prototype.iframescroll = function(dx,dy,speed)
{
	if (!this.iframeScrollActive) return
	var frm = this.window.frame.frames[this.iframe]
	var posx = ((is.ie) ? frm.document.body.scrollLeft : frm.pageXOffset)+dx
	var posy = ((is.ie) ? frm.document.body.scrollTop : frm.pageYOffset)+dy
	
	frm.scroll((posx<0)?0:posx,(posy<0)?0:posy);
	if (this.iframeScrollActive) 
		setTimeout(this.obj+".iframescroll("+dx+","+dy+","+speed+")",speed)
}

MyScroll.prototype.load = function(url)
{
	this.activated = false;
	if (this.iframe) {
		this.window.elm.innerHTML = '<iframe name="'+this.iframe+'" width="'+this.window.w+'" height="'+this.window.h+'" src="'+url+'" frameborder="0" scrolling="no"></iframe>'
		//this.iframe.location.href = url
	}
	else { 
		this.content.elm.load(url, this.content.w)
		this.content.moveTo(0,0)
	}
}