// Watermark script by Nick Allan

// ********************************************************************
// ********************* INSTRUCTIONS *********************************
// ********************************************************************

// ********************************************************************
// ************* LEAVE THE REST ALONE *********************************
// ********************************************************************
var theWaterMark = new Array();

navDOM = window.innerHeight;
isNS = (navigator.appName=="Netscape");

// set common object reference
if (!document.all) document.all = document;

/************************ CONSTRUCTOR *********************************

markW=div width
markH=div height
markX=x coord (percentage) - 0 = fully left, 99 = almost fully right (only if markLeft is 0)
markY=y coord (percentage)
markLeft=x coord
theDiv=name of div
markRefresh=how quickly to refresh the div
autoHide=make invisible when the top of the screen is in view
clampY = whether to stop the watermark from scrolling up at a particular pixel value

*/
function WaterMark(markW,markH,markX,markY,markLeft,theDiv,markRefresh,autoHide,clampY,clampX)
{
	this.markW = markW;
	this.markH = markH;
	this.markX = markX;
	this.markY = markY;
	this.markRefresh = markRefresh;
	this.markLeft = markLeft;
	this.autoHide = autoHide;
	this.clampY = clampY;
	if (!clampX) clampX = 0;
	this.clampX = clampX;
	
	this.theDiv  = (document.layers) ? (document.all[theDiv]) : (document[( 'getElementById' || 'all' )]( theDiv ));

	if (document.layers) this.theDiv.style = this.theDiv;

	if (!autoHide) 
	{
		this.SetVals();
		this.RefreshMark();
		this.theDiv.style.visibility = ((document.layers) ? "show" : "visible");
	}

}

// Discover where the watermark should be
WaterMark.prototype.SetVals = function() 
{
	var barW = 0; // scrollbar compensation for PC Nav
	var barH = 0;

	if (navDOM) 
	{
		var innerWidth = window.innerWidth;
		var innerHeight = window.innerHeight;

		if (document.height > innerHeight) barW = 20;
		if (document.width > innerWidth) barH = 20;
	} 
	else 
	{
		var innerWidth = document.body.clientWidth;
		var innerHeight = document.body.clientHeight;
	}

	this.newLeft = parseInt((this.markLeft == 0) ? (((innerWidth - this.markW)-barW-5) * (this.markX/100)) : this.markLeft);

	this.markTop = (((innerHeight - this.markH)-barH-5) * (this.markY/100));

}

// Refresh it
/*WaterMark.prototype.RefreshMark = function() 
{

	var newTop;

	if (((navDOM) ? pageYOffset : document.body.scrollTop) <= 10) 
	{
		if (this.autoHide) 
		{
			this.theDiv.style.visibility = (document.layers) ? "hide" : "hidden";
		}
	}
	else
		this.theDiv.style.visibility = (document.layers) ? "show" : "visible";

	this.theDiv.style.left = (this.markLeft == 0) ? (this.newLeft + ((navDOM) ? pageXOffset : document.body.scrollLeft)) : this.newLeft;
	newTop = this.markTop + ((navDOM) ? pageYOffset : document.body.scrollTop);
	this.theDiv.style.top = (this.clampY > 0 && newTop < this.clampY) ? this.clampY : newTop;

}*/

WaterMark.prototype.RefreshMark = function() 
{

	var newTop,newLeft;

	if (((navDOM) ? pageYOffset : document.body.scrollTop) <= 10) 
	{
		if (this.autoHide) 
		{
			this.theDiv.style.visibility = (document.layers) ? "hide" : "hidden";
		}
	}
	else
		this.theDiv.style.visibility = (document.layers) ? "show" : "visible";

	newLeft = (this.markLeft == 0) ? (this.newLeft + ((navDOM) ? pageXOffset : document.body.scrollLeft)) : this.newLeft;
	this.theDiv.style.left = (this.clampX > 0 && newLeft < this.clampX) ? this.clampX : newLeft;
	newTop = this.markTop + ((navDOM) ? pageYOffset : document.body.scrollTop);
	this.theDiv.style.top = (this.clampY > 0 && newTop < this.clampY) ? this.clampY : newTop;

}

function LoadMarks() 
{
	var markID = new Array();
	var forNS7;

	if (theWaterMark.length == 0) 
	{
		forNS7 = setTimeout("LoadMarks()",500);
		return;
	}
		
//	for (var i = 0; i < theWaterMark.length; i++)
	for (var i in theWaterMark)
	{
		theWaterMark[i].SetVals();
		markID[i] = setInterval ("theWaterMark[" + i + "].RefreshMark()",theWaterMark[i].markRefresh);
	}

}


