// Copyright é 2005 Spaero. All rights reserved.

/*if (navigator.appName == "Netscape")
{
	netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
	window.scrollbars.visible = !window.scrollbars.visible;
	netscape.security.PrivilegeManager.revertPrivilege("UniversalBrowserWrite")
}*/

var loop, timer;
var scrollDist = 330;
var scrollY = 221;
var oCont = new Array();
var oMain = new Array();
var oScroll = new Array();

function makeObj(obj)
{
	this.el = document.getElementById(obj);
	this.css = document.getElementById(obj).style;
	this.scrollHeight = this.el.offsetHeight;
	this.up = goUp;
	this.down = goDown;
	this.moveIt = moveIt; 
	this.obj = obj + "Object";
	eval(this.obj + "=this");
	return this
}

function scrollInit()
{
	var last;
	var arg = oLayers.length;
	for (i = 0; i < arg/3; i++)
	{
		oMain[i] = new makeObj(oLayers[i*3]);
		oCont[i] = new makeObj(oLayers[i*3 + 1]);
		oScroll[i] = new makeObj(oLayers[i*3 + 2]);
		oScroll[i].moveIt(0,0);
		last = i
	}
	oMain[last].css.visibility = 'visible';
	textScrl = new makeObj('textScroll');
	scrollNoScroll();
/*	if ('pct') oPict = makeObj('pct');
	if (oIcons)
	{
		for (i = 0; i < oIcons.length; i++)
		{
			id = 'icn' + i;
			j = (i == (oIcons.length - 1)) ? 0 : i + 1;
			document.getElementById(id).style.visibility = (j == 0) ? 'hidden' : 'visible';
			document.getElementById(id).innerHTML = '<A HREF="#" ONCLICK="swapImg(' + j + ', ' + i + '); return false"><IMG SRC="' + oIcons[j] + '" WIDTH=97 HEIGHT=73 BORDER=0 ALT=""></A>'
		}
	}*/
	openLayer();
}

function openLayer()
{
	var loaded = false;
	for (i = 0; i < oMain.length; i++)
	{
		if (oMain[i]) loaded = true;
		else loaded = false;
	}
	if(!loaded)
	{
		setTimeout('openLayer()', 1000)
	}
	else
	{
		oMain[0].css.visibility = 'visible';
		document.getElementById('textBtnUp').style.visibility = (oScroll[0].scrollHeight < oCont[0].scrollHeight) ? 'hidden' : 'visible';
		document.getElementById('textBtnDown').style.visibility = (oScroll[0].scrollHeight < oCont[0].scrollHeight) ? 'hidden' : 'visible';
		textScrl.css.visibility = (oScroll[0].scrollHeight < oCont[0].scrollHeight) ? 'hidden' : 'visible';
	}
}

function showLayers(ind)
{
	var arg = oMain.length;
	for (i = 0; i < arg; i++)
	{
		oMain[i].css.visibility = 'hidden'
	}
	oMain[ind].css.visibility = 'visible';
	scrollNoScroll()
}

function moveIt(y)
{
	this.y = y;
	this.css.top = this.y
}

function goDown(move, num)
{
	if (this.y > -this.scrollHeight + oCont[num].scrollHeight)
	{
		y = (this.y + move > -this.scrollHeight + oCont[num].scrollHeight) ? this.y + move : -this.scrollHeight + oCont[num].scrollHeight;
		this.moveIt(y);
		yTxt = scrollY + Math.round((-this.y)*scrollDist/(this.scrollHeight - oCont[num].scrollHeight));
		textScrl.moveIt(yTxt);
		if(loop) setTimeout(this.obj + '.down(' + move + ', ' + num + ')',25)
	}
}

function goUp(move, num)
{
	if (this.y < 0)
	{
		y = (this.y + move < 0) ? this.y + move : 0;
		this.moveIt(y);
		yTxt = scrollY + Math.round((-this.y)*scrollDist/(this.scrollHeight - oCont[num].scrollHeight));
		textScrl.moveIt(yTxt);
		if(loop) setTimeout(this.obj + '.up(' + move + ', ' + num + ')', 25)
	}
}

function scroll(speed, ind)
{
	speed = (navigator.appName == "Netscape") ? speed*2 : speed;
	if (!ind)
	{
		arg = oMain.length;
		for (ind = 0; ind < arg; ind++)
		{
			if (oMain[ind].css.visibility == 'visible') break
		}
	}
	loop = true;
	if (speed < 0) oScroll[ind].down(speed, ind);
	else oScroll[ind].up(speed, ind)
}

function scrollSclr(ind)
{
	scrollNoScroll();
	if (!ind)
	{
		arg = oMain.length;
		for (ind = 0; ind < arg; ind++)
		{
			if (oMain[ind].css.visibility == 'visible') break
		}
	}
	yTxt = scrollY + Math.floor((-oScroll[ind].y)*scrollDist/(oScroll[ind].scrollHeight - oCont[ind].scrollHeight));
	textScrl.moveIt(yTxt)
}

function noScroll()
{
	loop = false;
	if(timer) clearTimeout(timer)
}

function scrollNoScroll(id)
{
	arg = oMain.length;
	if (!id)
	{
		for (id = 0; id < arg; id++)
		{
			if (oMain[id].css.visibility == 'visible') break
		}
	}
	document.getElementById('textScroll').style.visibility = (oScroll[id].scrollHeight < oCont[id].scrollHeight) ? 'hidden' : 'visible'
}

function goBack()
{
	if (history.length > 1) history.back();
	document.getElementById('backInact').style.visibility = (window.history.length > 1) ? 'hidden' : 'visible';
//	document.write(history.length)
}


function swapImg(i, num)
{
	oPict.el.innerHTML = null;
	oPict.el.innerHTML = '<IMG SRC="' + pictures[i] + '" WIDTH=400 HEIGHT=300 ALT="">';
	id = 'icn' + num;
	document.getElementById(id).innerHTML = '';
	document.getElementById(id).innerHTML = '<A HREF="#" ONCLICK="swapImg(' + current + ', ' + num + '); return false"><IMG SRC="' + oIcons[current] + '" WIDTH=97 HEIGHT=73 BORDER=0 ALT=""></A>';
	current = i;
}

onload = scrollInit;
