
//--- browser checking
userAgent = navigator.userAgent.toLowerCase();
ns4 = (document.layers) ? true:false
ie4 = (document.all && userAgent.indexOf("mac")==-1) ? true:false
w3c = (document.documentElement) ? true:false;

//--- init function for each page
function initialize(pImgArray)
{
	//--- get window size
	if (ns4)
	{	windowwidth  = window.innerWidth;
		windowheight = window.innerHeight;
	}
	else if (ie4)
	{	windowwidth  = document.body.clientWidth;
		windowheight = document.body.clientHeight;
	}

	//--- create pointer variables
	if (ns4) 
	{	
		subhead   = document.subheadDiv;
		img1  	  = document.imageDiv1;		theImage1  = img1.document.jumpImg1;
		img2  	  = document.imageDiv2;		theImage2  = img2.document.jumpImg2;
		img3  	  = document.imageDiv3;		theImage3  = img3.document.jumpImg3;
	}
	else if (ie4)
	{	
		subhead   = subheadDiv.style;
		img1      = imageDiv1.style;		theImage1  = document.jumpImg1;
		img2      = imageDiv2.style;		theImage2  = document.jumpImg2;
		img3      = imageDiv3.style;		theImage3  = document.jumpImg3;
	}
	
	//--- get random image (make sure dimensions are the same as ns4 fails
	//--- to get new width and height after src changed)
	var imgPath = "../global/images/";
	var irnd = -1;
	var pImgArrayLen = pImgArray.length;
	while ( irnd < 0 || irnd > pImgArrayLen )
		irnd = Math.round(Math.random() * pImgArrayLen) + 1;
	theImage1.src = theImage2.src = theImage3.src = imgPath + pImgArray[irnd-1];

	//--- get image size
	imgWidth  = parseInt(theImage1.width);	
	imgHeight = parseInt(theImage1.height);

	//--- define pseudo clip with current image size (IE workaround)
	if (ie4)
	{
		clipTo(img1,0,imgWidth,imgHeight,0);	
		clipTo(img2,0,imgWidth,imgHeight,0);
		clipTo(img3,0,imgWidth,imgHeight,0);
	}

	//--- define height of visible clip area
	clipWidth  = parseInt(120);
	clipHeight = parseInt(80);

	if (ns4) { clipHeight-=5; }

	//--- process all images
    for (ii = 1; ii <= 3; ii++)
	{
		eval('img' + ii + '.xpos = parseInt(img' + ii + '.left);');
		eval('img' + ii + '.ypos = parseInt(img' + ii + '.top);');

		//--- get x and y shift
		var xp = -1;
		var yp = -1;
		while (xp < 0 || xp > imgWidth - clipWidth)
			xp = Math.round((Math.random() * 1000) % imgHeight);
      
	    if (ns4)
		{
		   while (yp < 0 || yp > imgHeight - clipHeight - 5)
			   yp = Math.round((Math.random() * 1000) % imgWidth);
	    }
		else
		{
			while (yp < 0 || yp > imgHeight - clipHeight)
				yp = Math.round((Math.random() * 1000) % imgWidth);
		}

		//--- shift image and clip to defined dimension
		eval('moveBy(img' + ii + ',xp*(-1),yp*(-1));');

		//--- combinded with dot.gif of image2 set to greater dimensinon
		//if (ii == 2 && ns4)
		//	eval('clipBy(img' + ii + ',yp,(imgWidth - clipWidth - xp + (theImage2.width - imgWidth))*(-1),(imgHeight - clipHeight - yp + (theImage2.height - imgHeight))*(-1),xp);');
		//else

		eval('clipBy(img' + ii + ',yp,(imgWidth - clipWidth - xp)*(-1),(imgHeight - clipHeight - yp)*(-1),xp);');
		eval('showObject(img' + ii + ');');
	}
}

function layerWrite(id,nestref,text)
{
	if (ns4)
	{
		var lyr = (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document;
        lyr.open();
        lyr.write(text);
        lyr.close();
	}
	else if (ie4) 
	{
		document.all[id].innerHTML = text;
	}
}

function moveBy(obj,x,y) 
{
	obj.xpos += x;
	obj.left = obj.xpos;
	obj.ypos += y;
	obj.top = obj.ypos;
}

function moveTo(obj,x,y)
{
	obj.xpos = x;
	obj.left = obj.xpos;
	obj.ypos = y;
	obj.top = obj.ypos;
}


function clipValues(obj,which) {
        if (ns4) {
                if (which=="t") return obj.clip.top
                if (which=="r") return obj.clip.right
                if (which=="b") return obj.clip.bottom
                if (which=="l") return obj.clip.left
        }
        else if (ie4) 
		{
                var clipv = obj.clip.split("rect(")[1].split(")")[0].split("px")
                if (which=="t") return Number(clipv[0])
                if (which=="r") return Number(clipv[1])
                if (which=="b") return Number(clipv[2])
                if (which=="l") return Number(clipv[3])
        }
}

function clipTo(obj,t,r,b,l) {
        if (ns4) {
                obj.clip.top = t
                obj.clip.right = r
                obj.clip.bottom = b
                obj.clip.left = l
        }
        else if (ie4) obj.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"
}

function clipBy(obj,t,r,b,l) {
        if (ns4) {
                obj.clip.top = clipValues(obj,'t') + t
                obj.clip.right = clipValues(obj,'r') + r
                obj.clip.bottom = clipValues(obj,'b') + b
                obj.clip.left = clipValues(obj,'l') + l
        }
        else if (ie4) 
		{	
			obj.clip = "rect("+Number(this.clipValues(obj,'t')+t)+"px "+Number(this.clipValues(obj,'r')+r)+"px "+Number(this.clipValues(obj,'b')+b)+"px "+Number(this.clipValues(obj,'l')+l)+"px)";
		}
}

function showObject(obj)
{
	if (ns4) obj.visibility	 = "show";
    else if (ie4) obj.visibility = "visible";
}

function hideObject(obj)
{
	if (ns4) obj.visibility = "hide";
    else if (ie4) obj.visibility = "hidden";
}


//--- custom functions / objects

function TextEffect(pTxtArray)
{
	this.rnd = -1;
	while (this.rnd < 0 || this.rnd > pTxtArray.length-1)
		this.rnd = Math.round(Math.random() * pTxtArray.length - 1) + 1;
	this.txtString = pTxtArray[this.rnd];
	this.len = this.txtString.length;
	this.pos = 0;
	this.txtStringOut = "";
	this.tmpArray = this.txtString.split('');
	this.textEffectWrite = textEffectWrite;	
	this.textEffectWrite();
}

function textEffectWrite()
{	
	if (this.pos == this.len) { clearTimeout("textEffectWrite()"); return; }
			
	this.txtStringOut += this.tmpArray[this.pos];
	layerWrite("subheadDiv",null,'<font size="+1" color="#003366">[</font><span class="subheadline">' + this.txtStringOut + '</span><font size="+1" color="#003366">]</font>'); 

	this.pos++;
	setTimeout('myText.textEffectWrite()',1);
}
