
function Scroller(sDivName, sObjName, lTakeOffTop, lTakeOffBottom) {

	function m_init()
	{
		this.macstr='MacPPC';
		this.ismac = (navigator.platform == this.macstr);
		this.styleRef=(document.layers)?"":".style";
		this.divObj=this.findObj(this.name);
		//position layer
		eval("this.divObj"+this.styleRef+".top=this.takeOffTop");
		this.divHeight=(document.layers)?parseInt(this.divObj.document.height):((document.all)?parseInt(this.divObj.clientHeight):parseInt(this.divObj.offsetHeight));
		this.availableScrollingHeight=((document.all)?((this.ismac)?parseInt(document.body.offsetHeight):parseInt(document.body.scrollHeight)):parseInt(document.height))-this.takeOffTop-this.takeOffBottom-this.divHeight;
		this.startPos=this.takeOffTop;
		this.endPos=this.availableScrollingHeight+this.takeOffTop;
		this.initialised=true;
		if (!document.all)
		{
			eval("this.interval=setInterval(\'"+this.objName+".main()\',this.callRate)");//this.callRate
		}
	}

	function m_findObj(n,d) { 
		var p,i,x;  
		if(!d) d=document; 
		if((p=n.indexOf("?"))>0&&parent.frames.length) 
		{
		    	d=parent.frames[n.substring(p+1)].document; 
			n=n.substring(0,p);
		}
		//Case IE
		if(!(x=d[n])&&d.all) 
			x=d.all[n]; 
		for (i=0;!x&&i<d.forms.length;i++) 
			x=d.forms[i][n];
		//Case NN
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
			x=this.findObj(n,d.layers[i].document);
		//Case NN6
		if(!x && d.getElementById) 
			x=d.getElementById(n); 
		return x;
	}

	function m_main()
	{
		var s = "this.currentY=parseInt(this.divObj"+this.styleRef+".top)";
		eval(s);

		this.scrollTop = (document.all)?parseInt(document.body.scrollTop):parseInt(window.pageYOffset);
		var newTargetY = this.scrollTop +(this.startPos)
			
		if ( this.currentY != newTargetY ) {

			if ( newTargetY != this.targetY ) {

				this.targetY = newTargetY
				if (this.availableScrollingHeight>0)
					this.slideInit( )
		
			}
		if (this.availableScrollingHeight>0)
			this.slide()
		}
	}

	function m_slideInit()
	{
		var now	= new Date( )
		this.A		= this.targetY - this.currentY
		this.B		= Math.PI / ( 2 * this.slideTime )
		this.C		= now.getTime( )

		if (Math.abs(this.A) > this.availableScrollingHeight) {
			this.D = this.A > 0 ? this.targetY - this.availableScrollingHeight : this.targetY + this.availableScrollingHeight
			this.A = this.A > 0 ? this.availableScrollingHeight : -this.availableScrollingHeight
		} else {
			this.D = this.currentY
		}
	}

	function m_slide()
	{
		var now	= new Date( )
		var newY	= this.A * Math.sin( this.B * ( now.getTime( ) - this.C ) ) + this.D
		newY		= Math.round( newY )

		if (( (this.A > 0) && (newY > this.currentY) && (newY<=this.endPos)) ||
			( (this.A < 0) && (newY < this.currentY) && (newY<=this.endPos) )) {
				eval("this.divObj"+this.styleRef+".top=newY")
		}
		if ((newY==this.targetY)&& (this.interval)&&(document.all))
		{
			clearInterval(this.interval)
		}
	}

	function m_scroll()
	{
		if ((document.all)&&(this.initialised))
		{
			if (this.interval)
			{	
				clearInterval(this.interval)
			}
			var s = "this.interval=setInterval(\'"+this.objName+".main()\',this.callRate)";
			eval(s);
		}
	}

	// note the object is assuming that the magins of the HTML page are set to 0
	
	//Properties
	this.objName = sObjName;
	this.name = sDivName;
	this.takeOffTop = (lTakeOffTop!=null)?parseInt(lTakeOffTop):0;			//default value to 0
	this.takeOffBottom = (lTakeOffBottom!=null)?parseInt(lTakeOffBottom):0;	//default value to 0

	this.startPos;
	this.endPos;
	this.styleRef;
	this.divObj	;
	this.availableScrollingHeight;
	this.divHeight;
	this.callRate = 1;
	this.slideTime = 1000;
	this.A;
	this.B;
	this.C;
	this.D;
	this.interval;
	this.initialised;
	
	
	//methods
	this.init = m_init;	
	this.findObj = m_findObj;
	this.main = m_main;
	this.slide = m_slide;
	this.slideInit = m_slideInit;
	this.scroll = m_scroll;
}



function loadImages() {
	//pre-caches all images
	var imageNames = new Array('about', 'cv', 'music', 'theatre', 'photographs', 'links', 'familytree');
	var images = new Array();
	
	for (var i = 0 ; i < imageNames.length ; i++) {
		images[i] = new Image()
		images[i].src = imagePath + imageNames[i] + '.gif';
	}
}

function getCurrentPage() {
	var url = location.href;
	url = url.substring(url.lastIndexOf('/') + 1);
	url = url.substring(0, url.indexOf('.'));
	
	if (url.length == 0 || url == 'index' || url == 'stage') {
		url = 'about';}
	return url;		
}

function rollTo(s) {
	if (s.length == 0) {
		s = current;}
	document['page_logo'].src = imagePath + s + '.gif';
}

function positionMenu() {
	var staticId = 'scrmen';
	var s = '';
	var offSet = 2;
	if (navigator.appName == "Netscape") {
		s = 'document.' + staticId + '.top = window.pageYOffset + offSet';
	} else {
		s = 'document.all(\'' + staticId + '\').style.pixelTop = document.body.scrollTop + offSet';
	}
	eval(s);
}

function scrollmenu() {
	setTimeout("positionMenu()", 1);
}

function page_init() {
	loadImages();
	current = getCurrentPage();
	rollTo('');
	g_scr.init()
}

var imagePath = './images/menu/';
var current;
var g_scr = new Scroller('scrmen','g_scr',15,15);
