// Pre-Load Images
if (document.images)
   {
		MKS_Logo_Big = new Image(258,158)
		MKS_Logo_Big.src = "../images/MKS_Logo_Big.gif"
		
		MKS_Logo_Small = new Image(200,81)
		MKS_Logo_Small.src = "../images/MKS_Logo_Small.gif"
		
		brick = new Image(156,97)
		brick.src = "../images/brick.gif"
		
		bricktall = new Image(156,1000)
		bricktall.src = "../images/bricktall.gif"
		
		Panel = new Image(454,63)
		Panel.src = "../images/Panel.gif"
		
		BTNoff = new Image(135,33)
		BTNoff.src = "../images/btnOFF.gif"
		
		BTNon = new Image(135,33)
		BTNon.src = "../images/btnON.gif"
		
		BTNover = new Image(135,33)
		BTNover.src = "../images/btnOVER.gif"
   }

var ns4 = document.layers;
var ie4 = document.all;
var nn6 = document.getElementById && !document.all;

function showlinks(objID) {
	objIDname = objID + "links"
	if (ns4) {
		document.objIDname.visibility = "show";
	}
	if (ie4) {
		document.all[objIDname].style.visibility = "visible";
	}
	if (nn6) {
		document.getElementById(objIDname).style.visibility = "visible";
	}
}

function lightup(imgName)
	{
	  if (document.images)
	   {
	     imgOver=eval("BTNover.src");
	     document[imgName].src= imgOver;
	   }
	}

function turnoff(imgName)
	{
	  if (document.images)
	   {
	     imgOff=eval("BTNoff.src");
	     document[imgName].src= imgOff;
	   }
	}

function gogreen(imgName)
	{
	  if (document.images)
	   {
	     imgGo=eval("BTNon.src");
	     document[imgName].src= imgGo;
	   }
	}

floatX=0;
floatY=0;
layerwidth=170;
layerheight=378;
halign="left";
valign="top";
delayspeed=3;

// This script is copyright (c) Henrik Petersen, NetKontoret
// Feel free to use this script on your own pages as long as you do not change it.
// It is illegal to distribute the script as part of a tutorial / script archive.
// Updated version available at: http://www.echoecho.com/toolfloatinglayer.htm
// This comment and the 4 lines above may not be removed from the code.

NS6=false;
IE4=(document.all);
if (!IE4) {NS6=(document.getElementById);}
NS4=(document.layers);

function adjust() {
if ((NS4) || (NS6)) {
if (lastX==-1 || delayspeed==0)
{
lastX=window.pageXOffset + floatX;
lastY=window.pageYOffset + floatY;
}
else
{
var dx=Math.abs(window.pageXOffset+floatX-lastX);
var dy=Math.abs(window.pageYOffset+floatY-lastY);
var d=Math.sqrt(dx*dx+dy*dy);
var c=Math.round(d/10);
if (window.pageXOffset+floatX>lastX) {lastX=lastX+delayspeed+c;}
if (window.pageXOffset+floatX<lastX) {lastX=lastX-delayspeed-c;}
if (window.pageYOffset+floatY>lastY) {lastY=lastY+delayspeed+c;}
if (window.pageYOffset+floatY<lastY) {lastY=lastY-delayspeed-c;}
}
if (NS4){
document.layers['floatlayer'].pageX = lastX;
document.layers['floatlayer'].pageY = lastY;
}
if (NS6){
document.getElementById('floatlayer').style.left=lastX;
document.getElementById('floatlayer').style.top=lastY;
}
}
else if (IE4){
if (lastX==-1 || delayspeed==0)
{
lastX=document.body.scrollLeft + floatX;
lastY=document.body.scrollTop + floatY;
}
else
{
var dx=Math.abs(document.body.scrollLeft+floatX-lastX);
var dy=Math.abs(document.body.scrollTop+floatY-lastY);
var d=Math.sqrt(dx*dx+dy*dy);
var c=Math.round(d/10);
if (document.body.scrollLeft+floatX>lastX) {lastX=lastX+delayspeed+c;}
if (document.body.scrollLeft+floatX<lastX) {lastX=lastX-delayspeed-c;}
if (document.body.scrollTop+floatY>lastY) {lastY=lastY+delayspeed+c;}
if (document.body.scrollTop+floatY<lastY) {lastY=lastY-delayspeed-c;}
}
document.all['floatlayer'].style.posLeft = lastX;
document.all['floatlayer'].style.posTop = lastY;
} 
setTimeout('adjust()',50);
}

function define()
{
if ((NS4) || (NS6)) 
{ 
if (halign=="left") {floatX=ifloatX};
if (halign=="right") {floatX=window.innerWidth-ifloatX-layerwidth-20};
if (halign=="center") {floatX=Math.round((window.innerWidth-20)/2)-Math.round(layerwidth/2)};
if (valign=="top") {floatY=ifloatY};
if (valign=="bottom") {floatY=window.innerHeight-ifloatY-layerheight};
if (valign=="center") {floatY=Math.round((window.innerHeight-20)/2)-Math.round(layerheight/2)};
}
if (IE4) 
{
if (halign=="left") {floatX=ifloatX};
if (halign=="right") {floatX=document.body.offsetWidth-ifloatX-layerwidth-20}
if (halign=="center") {floatX=Math.round((document.body.offsetWidth-20)/2)-Math.round(layerwidth/2)}
if (valign=="top") {floatY=ifloatY};
if (valign=="bottom") {floatY=document.body.offsetHeight-ifloatY-layerheight}
if (valign=="center") {floatY=Math.round((document.body.offsetHeight-20)/2)-Math.round(layerheight/2)}
}
}

// This is called from the Body OnLoad event.
// It ensures that when the page loads, the "OrigText" DIV is visible,
// 		and it also initializes the currDiv variable,
// 		which then becomes global in scope,
// 		making it available to the changePicText() function.
// currDiv holds the ID of the text Div which is currently visible

// String Functions
function Len(str) {  return String(str).length;  }

function Left(str, n) {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
}

function Right(str, n) {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
}

function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }


// Keep in mind that strings in JavaScript are zero-based, so if you ask
// for Mid("Hello",1,1), you will get "e", not "H".  To get "H", you would
// simply type in Mid("Hello",0,1)

// You can alter the above function so that the string is one-based.  Just
// check to make sure start is not <= 0, alter the iEnd = start + len to
// iEnd = (start - 1) + len, and in your final return statement, just
// return ...substring(start-1,iEnd)

function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
*/
{
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}

function setToggle(id) {
	var browserWindowHeight = window.document.documentElement.clientHeight;
	if ( browserWindowHeight < 467 )
	{
		var domStyle = findDOM("bodybox",1);
		domStyle.top = 0+"px";
	}
	else
	{
		var domStyle = findDOM("bodybox",1);
		domStyle.top = parseInt(((browserWindowHeight-460)/4),10)+"px";
	}
//	var textDOM = id+"Text";
	var domStyleText = findDOM('CAcoButtonText',1);
	document.images[id].src = "../images/CAcoButtonON.gif";
	domStyleText.visibility = "visible";
	currID = "CAco";
}
	
function toggleCU(state) {
	if (state == "in") { 
		fileStr = "../images/ExtrudeButtonON.gif";
	}
	else
	{
		fileStr = "../images/ExtrudeButtonOFF.gif";
	}
	document.images.ExtrudeButton.src = fileStr;
}

function changeTMB(TMBid) {
	img = "../images/"+TMBid+".jpg";
	alttitle = "Go to "+TMBid.toUpperCase();
	newlink = TMBid+"/index.htm";
//	alert(img+"\n"+alttitle+"\n"+newlink);
	document.images.TMBpix.src = img;
	document.images.TMBpix.alt = alttitle;
	document.images.TMBpix.title = alttitle;
	document.links.TMBlink.href = newlink;
}

function reSetPage() {
	var browserWindowHeight = window.document.documentElement.clientHeight;
	if ( browserWindowHeight < 467 )
	{
		var domStyle = findDOM("bodybox",1);
		domStyle.top = 0+"px";
	}
	else
	{
		var domStyle = findDOM("bodybox",1);
		domStyle.top = parseInt(((browserWindowHeight-460)/4),10)+"px";
	}
}


function buttonON(id) {
	if (currID !== "CAco" && id !== "CAco" && currID != id)
	{
		img = "../images/"+currID+"ButtonOFF.jpg";
		document.images[currID+"Button"].src = img;
		img = "../images/"+id+"ButtonON.jpg";
		document.images[id+"Button"].src = img;
		var domStyleNew = findDOM(id+"ButtonText",1);
		var domStyleOld = findDOM(currID+"ButtonText",1);
//		alert(domStyleOld);
		domStyleNew.visibility = "visible";
		domStyleOld.visibility = "hidden";
		currID = id;
	}
	else if (currID !== "CAco" && id == "CAco")
	{
		img = "../images/"+currID+"ButtonOFF.jpg";
		document.images[currID+"Button"].src = img;
		img = "../images/"+id+"ButtonON.gif";
		document.images[id+"Button"].src = img;
		var domStyleNew = findDOM(id+"ButtonText",1);
		var domStyleOld = findDOM(currID+"ButtonText",1);
		domStyleNew.visibility = "visible";
		domStyleOld.visibility = "hidden";
		currID = id;
	}
	else if (currID == "CAco" && id !== "CAco")
	{
		img = "../images/"+currID+"ButtonOFF.gif";
		document.images[currID+"Button"].src = img;
		img = "../images/"+id+"ButtonON.jpg";
		document.images[id+"Button"].src = img;
		var domStyleNew = findDOM(id+"ButtonText",1);
		var domStyleOld = findDOM(currID+"ButtonText",1);
		domStyleNew.visibility = "visible";
		domStyleOld.visibility = "hidden";
		currID = id;
	}
	else
	{
		return;
	}
}

function toggle(id) {
	if (currToggle == "OFF") 
	{
		img = "../images/"+id+"ON.src";
		document.images["EXTRUDE"].src = img;
		currToggle = "ON"
	}
	else
	{
		img = "../images/"+id+"OFF.src";
		document.images["EXTRUDE"].src = img;
		currToggle = "OFF";
	}
}

// This sets the visibility of the main image and the associated text DIV to "visible",
// 		it also sets the previous text DIV to "hidden"
// This is done using the currDiv global variable (which we initialized above)
// when we enter the function, currDiv holds the ID of the text DIV currently being displayed (i.e., "visible")
// 		we use that ID to find the currently-displayed text DIV and set it to "hidden"
// 		then we set the incoming text DIV to "visible" and store its ID in currDiv
// when we leave the function, currDiv holds the new ID of the text DIV currently being displayed
function changePicText(imgID,textID,tmb) {
		var domStyleOld = findDOM(currDiv,1);
		var domStyleNew = findDOM(textID,1);
		var domStyleOldTmbn = findDOM(currTmb,1);
		var domStyleNewTmbn = findDOM(tmb,1);
		img = eval(imgID + ".src");
		document.images["bigPicture"].src = img;
		domStyleOld.visibility = "hidden";
		domStyleNew.visibility = "visible";
		domStyleOldTmbn.borderColor = "#ffffff";
		domStyleNewTmbn.borderColor = "#000000";
		currDiv = textID;
		currTmb = tmb;
	}
	
function openWin(id) {
	var str = document.images.bigPicture.src;
	var loc = -1;
	for (i=Len(str); i > 0; i--)
	{
		if ("." == Mid(str, i, 1))
	    {
			loc = i;
			break;
	    }
	}
	strNum = Mid(str, loc-2, 2);
	window.open("pages/"+strNum+".htm","BigPix","width=525,height=720,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no");
}

function openWin2(id) {
	var str = document.images.bigPicture.src;
	var loc = -1;
	for (i=Len(str); i > 0; i--)
	{
		if ("." == Mid(str, i, 1))
	    {
			loc = i;
			break;
	    }
	}
	strNum = Mid(str, loc-2, 2);
	window.open("pages/"+strNum+".htm","BigPix","width=525,height=820,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no");
}

// I don't actually call the toggleVisibility() function,
// 		but I wrote the routine as an exercise and left it here as an example.
// It does not use the findDOM() function to check for older browsers;
// instead it assumes IE5.5+ or NS6+ and uses the "document.getElementById"
// 		method of accessing the DOM. 
function toggleVisibility(objectID) {
	state = document.getElementById(objectID).style.visibility;
	if (state == 'hidden' || state == 'hide') document.getElementById(objectID).style.visibility = 'visible';
	else {
		if (state == 'visible' || state == 'show') document.getElementById(objectID).style.visibility = 'hidden';
		else document.getElementById(objectID).style.visibility = 'visible';
	}
}

function setVisibility(objectID,state,tmb,cuimg) {
		var domStyleNew = findDOM(objectID,1);
		var domStyleNewTmb = findDOM(tmb,1);
		domStyleNew.visibility = state;
		domStyleNewTmb.borderColor = "#000000";
		currDiv = objectID;
		currTmb = tmb;
		currCU = cuimg;
}
