// Scrolling window code Copyright 2000-2009 © P.J.Chandler Everything Internet 
// Including pause/continue on cursor over events
// Scrolls sstep every sinterval
// Created     April 2000
// Modified 21 June 2000
// Modified 12 January 2009 Changed code for DOM2
// Modified 08 February 2009 Changed Code for IE,FF,Opera

// Requires the follwing in an HTML document:
// An image id="scrollwindow" to be the background area for the scroll
// An iframe id="scrollsrc" pointing to the HTML document with the scroll data
// Some javascript variables :
//	var ssrc = "HTML document with the scroll data";	// For Netscape
//	var sinterval = 50;		// Interval between calls to scroll cycle
//	var sstep = 1;			// Step taken each scroll cycle
//	var sdelay = 50;			// For Netscape only
//	var spadding = 10;
//	var sbgcolour = "transparent";
/* --------------------------------------------------------------------------- */
//Netscape resizing solution

if (NS4) {
orgWidth = window.innerWidth;
orgHeight = window.innerHeight;
onresize = reDo;
}
function reDo() {
if (innerWidth != orgWidth || innerHeight != orgHeight) location.reload();}

// Problem solved
/* --------------------------------------------------------------------------- */

// Setup variables and initialise scroll when page has completely loaded

var sourceplace = "scrollwindow";
var sourceid = "scrollsrc";
var stemp;
var sclock = "";
var upper = "";
var lower = "";
var sleft, stop, swidth ,sheight;
window.onload = scrollInit;
function scrollInit() {

if (document.images) {
// if you can't get at the data then it's not worth trying

stemp = document.images[sourceplace];

//if (stemp.x) {
//	sleft = stemp.x;
//	stop = stemp.y;
//	}
//	else	{
	stemp.theX = theX;
	stemp.theY = theY;
	sleft = stemp.theX();
	stop = stemp.theY();
//	}
swidth = stemp.width;
sheight = stemp.height;
makeScene();
}}
function scrollGetXY(sl,st) {
// Check if running under Mozilla type browser to get position quickly
var sl,st;
//if (stemp.x) {
//	sl = stemp.x;
//	st = stemp.y;
//	}
//	else	{
	sl = stemp.theX();
	st = stemp.theY();
//	}
}

function makeScene() {
	if (!NS4) {loadScenie();}
	if (NS4) {loadScenns();}
	setTimeout("window.onresize = again",10000);
}


// -- Actual scroll code for IE

function smovie() {

// -- realign scroll if the image has moved because of a window resize or something
	scrollGetXY(sleft,stop);

	document.getElementById("scene").style.left = sleft+"px";
	document.getElementById("scene").style.top = stop+"px";

	ac.style.top = (parseInt(ac.style.top)-sstep)+"px";
	mi.style.top = (parseInt(mi.style.top)-sstep)+"px";

	if (parseInt(lower.style.top) <= 0) {
		upper.style.top = (parseInt(upper.style.top)+upper.clientHeight*2)+"px";
		sswitch();
	}
}
// -- Actual scroll code for Netscape

function smovns() {
	scene.left = stemp.x;
	scene.top = stemp.y;
	actor.moveBy(0,-sstep);
	mirror.moveBy(0,-sstep);
	if (lower.top <=0) { 
		upper.moveBy(0,upper.clip.height*2);
		sswitch();
	}
}

function sswitch() {

	if (upper == actor) {
		upper = mirror;
		lower = actor;
		return true;
	}
	upper = actor;
	lower = mirror;
	return true;
}
function scrollScenie() {

var sce = "scene";


	sclock = setInterval("smovie()", sinterval);
}
function scrollScenns() {
	sclock = setInterval("smovns()", sinterval);
}
function startScroll() {
	if (!NS4) {scrollScenie();}
	else {scrollScenns();}
}
function stopScroll() {
	clearInterval(sclock);
	if (!NS4) {
	scene.style.pixelLeft = stemp.theX();
	scene.style.pixelTop = stemp.theY();}
	else {
	scene.left = stemp.x;
	scene.top = stemp.y;}
}

function again() {
	location.reload();
}
function loadScenie() {
mySource = document.getElementById(sourceid);

if (mySource.contentDocument){

	sceneContent = mySource.contentDocument.getElementsByTagName("BODY");
	}
else	if (mySource.Document) {

	sceneContent = mySource.Document.getElementsByTagName("BODY");
	}


	var scenehtml = '<DIV ID="actor" style="position:absolute;">' + sceneContent[0].innerHTML + '</DIV>';
	scenehtml += '<DIV ID="mirror" style="position:absolute;">' + sceneContent[0].innerHTML + '</DIV>';

var sc=document.createElement("div");
sc.id = "scene";
sc.style.position = "absolute";
sc.style.visibility = "hidden";
sc.innerHTML = scenehtml;


	sc.style.clip = "rect(0 " +swidth+ " " +sheight + " 0)";
	sc.style.width = swidth;
	sc.style.height = sheight;
	sc.style.left = sleft+"px";
	sc.style.top = stop+"px";
	sc.style.backgroundColor = sbgcolour;
	sc.style.visibility = imageOn;
	document.body.appendChild(sc);
	ac = document.getElementById("actor");
	ac.style.left = spadding+"px";
	mi = document.getElementById("mirror");
	mi.style.left = spadding+"px";
	ac.style.width = swidth-spadding-1;
	mi.style.width = swidth-spadding-1;
	ac.style.top = 0+"px";
	mi.style.top = mirror.clientHeight;
	ac.style.visibility =  imageOn;
	mi.style.visibility =  imageOn;
	sc = document.getElementById("scene");
	upper = ac;
	lower = mi;
	scrollScenie();
}
function loadScenns() {

	scene = new Layer(swidth);
	scene.visibility = imageOff;
	scene.clip.width = swidth;
	scene.clip.height = sheight;
	scene.height = sheight;
	scene.left = sleft;
	scene.top = stop;
	if (sbgcolour == "transparent") { scene.bgColor =null;}
	else {scene.bgColor = sbgcolour;}
	setTimeout("makeActor()",sdelay);
}
function makeActor() {
	actor = new Layer(swidth - spadding, scene);
	actor.clip.width = swidth - spadding;
	actor.src = ssrc;
	actor.left = spadding;
	actor.top = 0;
//	actor.onmouseover = stopScroll;
//	actor.onmouseout = scrollScenns;
	actor.onload = makeMirror;
}
function makeMirror() {
	mirror = new Layer(swidth - spadding, scene);
	mirror.clip.width = swidth - spadding;
	mirror.src = ssrc;
	mirror.left = spadding;
//	mirror.onmouseover = stopScroll;
//	mirror.onmouseout = scrollScenns;
	actor.visibility =  imageOn;
	mirror.onload = prepScroll;
}
function prepScroll() {
	mirror.top = mirror.clip.height;
	mirror.visibility =  imageOn;
	scene.visibility =  imageOn;
	upper = actor;
	lower = mirror;
	scrollScenns();
}

function theX() {
	thisX = this.offsetLeft;
	temp = this.offsetParent;
	while (temp != null) {
		thisX += temp.offsetLeft;
		temp = temp.offsetParent;
	}
	return thisX;
}

function theY() {	
	thisY = this.offsetTop;
	temp = this.offsetParent;
	while (temp != null) {
		thisY += temp.offsetTop;
		temp = temp.offsetParent;
	}
	return thisY;
}

