
var hexChars=new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');function createField(red,green,blue,width,height,spacing,func,picker){var r=red*51;var g=green*51;var b=blue*51;var elem=document.createElement("a");var x=(((red%3)*6)+green)*(width+spacing)+spacing;var y=((red>=3?6:0)+blue)*(height+spacing)+spacing;elem.style.backgroundColor="rgb("+r+","+g+","+b+")";elem.style.display="block";elem.style.position="absolute";elem.style.left=x+"px";elem.style.top=y+"px";elem.style.width=width+"px";elem.style.height=height+"px";elem.style.overflow="hidden";var hrefAt=document.createAttribute("href");hrefAt.value="javascript:"+func+"("+r+","+g+","+b+");";elem.setAttributeNode(hrefAt);var titleAt=document.createAttribute("title");titleAt.value=colorToHex(r,g,b);elem.setAttributeNode(titleAt);picker.appendChild(elem);}
function createColorPicker(blockWidth,blockHeight,blockSpacing,bgColor,func){var picker=document.createElement("div");var w=(blockWidth+blockSpacing)*18+blockSpacing;var h=(blockHeight+blockSpacing)*12+blockSpacing;picker.style.backgroundColor=bgColor;picker.style.width=w+"px";picker.style.height=h+"px";picker.style.position="absolute";for(var r=0;r<6;r++)
for(var g=0;g<6;g++)
for(var b=0;b<6;b++)
createField(r,g,b,blockWidth,blockHeight,blockSpacing,func,picker);return picker;}
function colorToHex(r,g,b){return'#'+byteToHex(r)+byteToHex(g)+byteToHex(b);}
function byteToHex(b){var major=parseInt(b/16);var minor=b%16;return""+hexChars[major]+hexChars[minor];}
