//something like 

if (document.layers) {window.location="mixer_tc_ns4.html"} // just that one redirect for NS4 folks

function make_objects () {
	infoDivObj = new getObj('infoDiv');
}//made objs

function getObj(name)	{

  	if (document.getElementById) { return document.getElementById(name).style; }
  	if (document.all) { return document.all[name].style; }
	
	
}// got objs

function makeColorObj(name) {

	this.name = name;
	this.hex = "CC";
	this.dec = 204;
	this.lock = 0;
	return this;
	
}

redObj = new makeColorObj("red");
greenObj = new makeColorObj("green");
blueObj = new makeColorObj("blue");

colorObj = new Object();
colorObj.red = redObj; colorObj.green = greenObj; colorObj.blue = blueObj;
var thingToColor = "body";

//***********************OK that's object creation ***********************************************



function main (currentColor, decColor) {
	if (colorObj[currentColor].lock) {return 0};
	colorObj[currentColor].name = currentColor;
	colorObj[currentColor].dec = decColor;
	colorObj[currentColor].hex =  getHexColor(decColor);

	//alert ("So far this color is " + colorObj[currentColor].name + " " + colorObj[currentColor].dec + " "+colorObj[currentColor].hex);

	setBoxes (currentColor);
	setItemColor();
	moveArrows(currentColor, decColor);
	makeyuv ();

}//main



function setItemColor () {

	allcol = colorObj.red.hex + colorObj.green.hex  + colorObj.blue.hex;
	if (thingToColor == "body") {
		document.bgColor= eval(hexformat);
		return;
	}
	//else set text color
	infoDivObj.color= eval(hexformat);
	//document.fgColor= eval(hexformat);
}//set color


function setBoxes (currentColor) {

	hexformat= "\"\#" + colorObj.red.hex + colorObj.green.hex  + colorObj.blue.hex + "\"";
	decformat= colorObj.red.dec + "\, " + colorObj.green.dec + "\, " + colorObj.blue.dec;
	if (colorObj[currentColor].lock) {return 0};
	document.forms[1].elements[currentColor + "hexbox"].value = colorObj[currentColor].hex;
	document.forms[1].elements[currentColor + "decbox"].value = colorObj[currentColor].dec;

	if (thingToColor == "body") {
		document.alldisplay.rgbval.value=(decformat);
		document.alldisplay.hexval.value=(hexformat);
		return 0;
	}
	document.forms[2].elements['textHexValue'].value=(hexformat);
	document.forms[2].elements['textRgbValue'].value=(decformat);

}//set boxes

function getHexColor (decColor) {

var hexnumbers = "0123456789ABCDEF";

	hexColor = Math.floor(decColor / 16);
	hexdig10 = hexnumbers.substring(hexColor,hexColor+1);
	hexColor *=16;
	hexColor = decColor - hexColor;
	hexdig01 = hexnumbers.substring(hexColor,hexColor+1);
	hexColor = hexdig10 + hexdig01;
	return hexColor;

} //get hex

function moveArrows (col, topPos) {

arrowHeight = ((255 - ( eval(topPos) ) ) -130); // takes  height into calcs for pos

	if (document.getElementById) {
		moverObj = document.getElementById(col + "_arrow").style
		moverObj.top = arrowHeight + "px"
	}
	else {
		//****that should really be the test as to which code gets loaded, unless we get into some freakish mac ie thing
		//alert ("doink");
		"document." + col + "_arrow.top = topPos"
	}
}//fn

function makeyuv () {
	var rdecset = colorObj.red.dec;
	var gdecset = colorObj.green.dec;
	var bdecset = colorObj.blue.dec;
	var Y;
 	var Cb;
 	var Cr;
	
	MatrixR = 0.299;
	MatrixG = 0.587;
	MatrixB = 0.114;
	Y = Math.round (( ( (MatrixR * rdecset) + (MatrixG * gdecset) + (MatrixB * bdecset) ) * (235-16) / 255) + 16);
	Cb = Math.round ((0.5 / (1 - MatrixB) * (bdecset - ((MatrixR * rdecset) + (MatrixG * gdecset) + (MatrixB * bdecset))) * (240-16) / 255) + 128);
	Cr = Math.round ((0.5 / (1 - MatrixR) * (rdecset - ((MatrixR * rdecset) + (MatrixG * gdecset) + (MatrixB * bdecset))) * (240-16) / 255) + 128);
//function as pasted from Vince Cerundolo @ discreet

	document.alldisplay.Yval.value=Y;
	document.alldisplay.Cbval.value=Cb;
	document.alldisplay.Crval.value=Cr;
}

function DoLock (lockcol) {

	if (colorObj[lockcol].lock == 0) {
		document.forms[1].elements[lockcol + "statbox"].value = "Lock at " + colorObj[lockcol].dec
		colorObj[lockcol].lock =1;
		return 0;
	}
	document.forms[1].elements[lockcol + "statbox"].value = "Unlocked"
	colorObj[lockcol].lock =0;
}
