var pichiobj;
var picloobj;
var fadebusy;
function b4stgdFade(picnum) {
	if (fadebusy)
		return;

	fadebusy = 1;

	pichiobj = document.getElementById('highphoto');
	picloobj = document.getElementById('lowphoto');

	picloobj.src = eval('pgb4_' + picnum + '.src');
	pichiobj.src = eval('pgstgd_' + picnum + '.src');
	setOpacity(pichiobj, 0);

	for (var i=0;i<21;i++) {
		setTimeout('setOpacity(pichiobj, '+i+')', ((100 * i) + 750));
	}

	setTimeout('clearFadeBusy()', ((100 * i) + 750));
}

function clearFadeBusy() {
	fadebusy = 0;
}

function setOpacity(element, alpha) {
	var style = element.style;
	if( style.MozOpacity != undefined ) { //Moz and older
		style.MozOpacity = alpha/20;
	}
	else if( style.filter != undefined ) { //IE
		style.filter = "alpha(opacity=' + alpha * 5 + ')";
		element.filters.alpha.opacity = ( alpha * 5 );
	}
	else if( style.opacity != undefined ) { //Opera
		style.opacity = alpha/20;
	}
}

var n4, ie, n6;
var doc1, doc2, doc3, sty;

if (document.layers) {
	doc1 = "document.";
	doc2 = ".document.";
	doc3 = "";
	sty = "";
	n4 = true;
} else if (document.all) {
	doc1 = "document.all.";
	doc2 = "";
	doc3 = "";
	sty = ".style";
	ie = true;
} else if (document.getElementById) {
	doc1 = "document.getElementById('";
	doc2 = "')";
	doc3 = "')";
	sty = "').style";
	n6 = true;
}

var pgtnboxobj, pgtntextobj;
var scrollspeed = 40;
var loaded = 0;
var loop = 0;
var minwidth, containerbox, textbox;

function createObject (elem, container) {
	if (document.all) {
		this.element = document.all[elem];
		this.styleElem = this.element.style;
		this.elemwidth = this.element.offsetWidth;
		this.clipwidth = this.element.offsetWidth;
	}

	else if (document.getElementById) {
		this.element = document.getElementById(elem);
		this.styleElem = this.element.style;
		this.elemwidth = this.element.offsetWidth;
		this.clipwidth = this.element.offsetWidth;
	}

	else if (container) {
		container = doc1+container+".";
		this.element = eval (container+doc1+elem);
		this.styleElem = eval (container+doc1+elem);
		this.elemwidth = this.styleElem.document.width;
		this.clipwidth = this.styleElem.clip.width;
	}

	else {
		return false;
	}

	this.scrollthis = scrollThis;
	this.scrollleft = scrollLeft;
	this.scrollright = scrollRight;
	this.scrollit = scrollIt;
	this.positionit = positionIt;
	return this;
}

function scrollThis (xpos, ypos) {
	this.x=xpos;
	this.y=ypos;

	this.styleElem.left = xpos+'px';
	this.styleElem.top = ypos+'px';
}

function scrollLeft (incr) {
	minwidth = this.elemwidth - containerbox.clipwidth;

	if (this.x > -minwidth) {
		this.scrollthis (this.x-incr, 0);
	} else {
		clearInterval(this.intervalID);
		loop = 0;
	}
}

function scrollRight (incr) {
	if (this.x < 0) {
		this.scrollthis (this.x-incr, 0);
	} else {
		clearInterval(this.intervalID);
		loop = 0;
	}
}

function scrollIt (elem, incr) {
	containerbox = eval (elem + "boxobj");
	textbox = eval (elem + "textobj");

	if ((loaded == 1) && (loop == 0)) {
		loop = 1;

		if (incr > 0) {
			textbox.intervalID=setInterval("textbox.scrollleft ("+incr+")", scrollspeed);
		} else {
			textbox.intervalID=setInterval("textbox.scrollright ("+incr+")", scrollspeed);
		}
	}
}

function positionIt (elem, posx, posy) {
	textbox = eval (elem + "textobj");

	if (loaded == 1) {
		textbox.scrollthis (posx, posy);
	}
}

function initMover(pgtntext) {
	pgtnboxobj = new createObject ('pgtnbox');
	pgtntextobj = new createObject (pgtntext, 'pgtnbox');

	pgtntextobj.scrollthis (0, 0);

	loaded = 1;
}

function startScroll (dir) {
	if (dir == 'left') {
		scrollIt ('pgtn', -10);
	} else {
		scrollIt ('pgtn', 10);
	}
}

function stopScroll () {
	clearInterval(pgtntextobj.intervalID);
	loop = 0;
}
