var monitor = false;
var sStr = "";
var NS = (document.layers)?true:false;
var IE = (document.all)?true:false;
var NS6 = (!NS && !IE)?true:false;
var IE5 = (document.all && document.getElementById)?true:false;
//var scrollerArray = new Array();

window.onresize = resizeScrollers;

function resetScroll(id)
{
	var obj = eval(getScroller(id));
	obj.scrolling = false;
}

function scroller(x,y,w,h,id,content)
{
	this.x = x;
	this.y = y;
	this.startY = y;
	this.w = w;
	this.h = h;
	this.id = id;
	this.content = content;
	this.scrolling = false;

	this.move = move;
	this.HTML = writeScrollerHTML;
	this.loadPage = loadPage;
	this.resetClip = resetClip;
	this.resize = resizePage;
}

function resizePage()
{

	if(NS)
	{
		history.go(0);
	}
	else if(IE || NS6)
	{
		this.h = getY();
		this.layer.style.clip = "rect("+Math.abs(this.startY-this.y)+"px "+this.w+"px "+(Math.abs(this.startY-this.y) + this.h)+"px 0px)"
		this.scrollDown.style.top = this.startY + this.h
	}
}

function move(up)
{

	if(this.realHeight > this.h) //otherwise, no scrolling
	{
		var limit = ((up)?this.startY:this.startY + this.h - this.realHeight); //stop values
		var dy = (NS6)?10:4; //amount to scroll each time
		var objLayer
		if(NS)
		{
			objLayer = this.layer

		}
		else
		{
			objLayer = this.layer.style
		}

		if(up)
		{
			if(this.y + dy < limit)
			{
				this.y += dy;
				objLayer.top = this.y;
			}
			else
			{
				this.y = limit;
				objLayer.top = this.y;
			}
		}
		else
		{
			if(this.y - dy > limit)
			{
				this.y -= dy;
				objLayer.top = this.y;
			}
			else
			{
				this.y = limit;
				objLayer.top = this.y;
			}
		}
		 //SET CLIPPING
		if(NS)
		{
			this.layer.clip.height = this.h;
			this.layer.clip.width = this.w;
			this.layer.clip.top = Math.abs(this.startY-this.y);
			this.layer.clip.left = 0;
		}
		else
		{
			this.layer.style.clip = "rect("+Math.abs(this.startY-this.y)+"px "+this.w+"px "+(Math.abs(this.startY-this.y) + this.h)+"px 0px)"
		}
		if(this.scrolling)
				setTimeout("getScroller(" + this.id + ").move(" + up + ")",10)

	}
}

function writeScrollerHTML()
{

	if(IE || NS6)
		outStr("<div id=\"scroller"+this.id+"\" style=\"position:absolute; z-index:2; top:"+this.y+"px; left:"+this.x+"px; visibility:visible; clip:rect(0px "+this.w+"px "+this.h+"px 0px);\">");
	else if(NS)
		outStr('<layer name="scroller'+this.id+'" top='+this.y+' left='+this.y+' z-index=2>');
	outStr("<img src=\"/images/spacer.gif\" width=\""+this.w+"\" height=\"1\" border='0'><br>")
	outStr(this.content)

	if(IE || NS6)
		outStr("</div>");
	if(NS)
		outStr("</layer>");

	this.layer = getLayer("scroller" + this.id);
	var obj = eval("this.layer" + ((NS)?"":".style"));
	obj.top = this.y;
	obj.left = this.x;
	obj.width = this.w;
	if(NS)
		this.realHeight = this.layer.clip.height;
	if(IE || NS6)
	{
		this.realHeight = this.layer.offsetHeight;
	}
	if(NS || !IE)
		obj.height = this.h; // < ? doh!
	if(NS)
	{
		this.layer.clip.height = this.h;
		this.layer.clip.width = this.w;
		this.layer.clip.top = 0;
		this.layer.clip.left = 0;
	}

	// Scroll up button
	if(IE || NS6)
		outStr("<div id=\"ScrollUp"+this.id+"\" style=\"position:absolute; z-index:3; visibility:visible; top:"+(this.y-13)+"px; left:"+this.x+"px;\">");
	if(NS)
		outStr('<layer name="ScrollUp'+this.id+'" top='+(this.y-13)+' left='+this.x+' z-index=3>');
	outStr("<a href=\""+((NS && getOS() != "Macintosh")?"javascript:resetScroll("+this.id+")":"javascript://")+"\" onMouseUp=\"resetScroll('"+this.id+"')\" onMouseOut=\"resetScroll('"+this.id+"')\" onMouseDown=\"getScroller("+this.id+").scrolling=true;getScroller("+this.id+").move(true);return false;\"><img src=\"/images/pushpanel-up0.gif\" border=\"0\"></a><br>");
	if(IE || NS6)
		outStr("</div>")
	if(NS)
		outStr("</layer>")

	this.scrollUp = getLayer("ScrollUp"+this.id);
	// Scroll down button
	if(IE || NS6)
		outStr("<div id=\"ScrollDown"+this.id+"\" style=\"position:absolute; z-index:3; visibility:visible; top:"+(this.y + this.h)+"px; left:"+this.x+"px;\">");
	if(NS)
		outStr('<layer name="ScrollDown'+this.id+'" top='+(this.y + this.h)+' left='+this.x+' z-index=3>');
	outStr("<a href=\""+((NS && getOS() != "Macintosh")?"javascript:resetScroll("+this.id+")":"javascript://")+"\" onMouseUp=\"resetScroll('"+this.id+"')\" onMouseOut=\"resetScroll('"+this.id+"')\" onMouseDown=\"getScroller("+this.id+").scrolling=true;getScroller("+this.id+").move(false);return false;\"><img src=\"/images/pushpanel-dn0.gif\" border=\"0\"></a>");
	if(IE || NS6)
		outStr("</div>")
	if(NS)
		outStr("</layer>")
	this.scrollDown = getLayer("ScrollDown"+this.id);
}

function addScroller(x,y,w,h,id,content)
{
	scrollerArray[scrollerArray.length] = new scroller(x,y,w,h,id,content);
}

function getScroller(id)
{
	for(var i = 0; i < scrollerArray.length; i++)
	{
		if(id == scrollerArray[i].id)
			return scrollerArray[i];
	}
	return null;
}

function writeScrollers()
{
	if(IE || NS6)
	{
		document.write('<div id="cont" style="visibility:visible; position:absolute; height:1px; width:1px; top:0px; left:-500px;">')
		document.write('<IFRAME name="bufferFrame" id="bufferFrame"></IFRAME></div>')
	}
	for(var i = 0; i < scrollerArray.length; i++)
	{
		scrollerArray[i].HTML();
	}
}

function resizeScrollers()
{
	for(var i = 0; i < scrollerArray.length; i++)
	{
		scrollerArray[i].resize();
	}
}


function getLayer(l_id)
{
	if(NS)
	{
		return eval("document.layers['"+l_id+"']");
	}
	else if(IE)
	{
		return eval("document.all['" + l_id + "']");
	}
	else if(NS6)
	{
		return eval("document.getElementById('"+ l_id +"')");
	}
}

function outStr(str)
{
	document.writeln(str);
}

function outStrS(str)
{
	sStr += str;
}



// Loadsource functions
var loadingObj = null;
function loadPage(url)
{
	loadingObj = this;
	if(NS)
	{
		this.layer.visibility = "hide";
		this.layer.load(url,this.w)
	}
	else if(IE)
	{

		bufferFrame.document.location.replace(url)
	}
	else if(NS6)
		document.getElementById('bufferFrame').src=url;
}

function activate()
{
	if(loadingObj)
	{
		if(IE)
		{
			loadingObj.layer.innerHTML = document.bufferFrame.document.body.innerHTML
		}
		else if(NS6)
		{
			loadingObj.layer.innerHTML = document.getElementById('bufferFrame').contentDocument.body.innerHTML
			loadingObj.realHeight = 5000 //loadingObj.layer.offsetHeight //document.getElementById('bufferFrame').contentDocument.body.offsetHeight;
			//alert(loadingObj.layer.offsetHeight)
		}
		else if(NS)
		{
			loadingObj.realHeight = loadingObj.layer.document.height;
		}

		if(IE5 || (IE && getOS() == "Macintosh"))
		{
			loadingObj.realHeight = loadingObj.layer.offsetHeight;

		}
		else if(!IE5 && IE)
		{
			loadingObj.realHeight = bufferFrame.document.body.scrollHeight;
		}

		loadingObj.resetClip();
	}
	
	//alert(loadingObj.realHeight)
	loadingObj = false;
}

var opLayer = null;
function resetClip()
{
	if(NS)
	{
		this.layer.top = this.startY;
		this.y = this.startY;
		this.scrolling = true;
		this.move(false)
		this.scrolling = false;
		this.scrolling = true;
		this.move(true)
		this.scrolling = false;
		opLayer = this;
		setTimeout('opLayer.layer.visibility="show"',100);
	}
	else if(IE || NS6)
	{
		this.layer.style.clip = "rect(0px "+this.w+"px "+(this.h)+"px 0px)";
		this.layer.style.top = this.startY;
		this.y = this.startY;
	}
}
// End loadsource

function getWindowHeight() {
	var hojd

	if (NS) {
		hojd = self.innerHeight
	}
	else if (IE) {
		hojd = parent.document.body.offsetHeight
	}
	else if (NS6) {
			hojd = window.innerHeight
	}
	return hojd
}


function getY() {
	var hojd, y
	y = 270
	if (NS) {
		if (getOS() == "Macintosh")
			y = getWindowHeight() - 104
		else
			y = getWindowHeight() - 110
	}
	else if (IE) {
		if (getOS() == "Macintosh")
			y = getWindowHeight() - 230
		else
		{
			y = getWindowHeight() - 240
		}
	}
	else if (NS6) {
			if (getOS() == "Macintosh")
				y = getWindowHeight() - 104
			else
				y = getWindowHeight() - 110
	}
	else y = 270
	return y-80
}

function getOS() {
  if(navigator.userAgent.indexOf('Win') != -1)
    { var OpSys = "Windows"; }
  else if(navigator.userAgent.indexOf('Mac') != -1)
    { var OpSys = "Macintosh"; }
  else { var OpSys = "other"; }
  return OpSys;
}
