_d=document,_s='style',_oP='offsetParent',_iH='innerHTML';
function ColorPicker(img,f,E,i,c,p,t,_d){
	_d=document;E=_d.documentElement,t=3;if(!E)return;
	function convert(l,b,t){l=parseInt(l,b).toString(t);return(t!=0x10)?l:l.replace(/^((.{4})|(.{2}))$/, function(a,b,c){return'00'+(c||'00'+b);});}

	function cf(k,i,h,j){
		if((h=k.match(/(\d+)[, ]+(\d+)[, ]+(\d+)/)))for(i=t,k='#'+convert(h[1]<<16|h[2]<<8|h[3],10,0x10);i;)c[i][_iH]=h[i--];
		else for(i=t,h=convert(k.substr(1),0x10,10);i;h>>=8)c[i--][_iH]=h&0xff
		c[0][_iH]=k.toUpperCase();
	}
	function cp(i,j,k,s,h,l){
		function td(x,y,z){return'<td onmouseout="this[_s].backgroundImage=\'\'" style="background:#'+x+x+y+y+z+z+'"></td>';}
		for(h='0369acf'.split(''),i=0,s='';x=h[i++];s+='</tr>')for(j=0,s+='<tr>'+td(x,x,x);y=h[j++];)for(k=0;z=h[k++];)s+=td(x,y,z)
		return '<ul><li></li><li></li><li></li><li></li></ul><table>'+s+'</table>';
	}
	with( ( p=_d.createElement('div') ) ){
		setAttribute('id','picker');
		innerHTML=cp();
		onmouseover=function(e){
			e=e||event; e=e.srcElement||e.target;
			if ( !/td/i.test( e.nodeName ) ) return;
			e[_s].backgroundImage='url("'+img.src+'")'
			cf(e[_s].backgroundColor);
		}
	}
	_d.body.appendChild(p);
	for(i=0,j=0xff,c=p.getElementsByTagName('li');j>0;j<<=8)with(c[++i].style)color=borderColor='#'+convert(j,10,0x10)

	Picker={showPicker:function(e,x,mX,mY){
			e=e||event;	with(p[_s]){display='block';top = _d.body.scrollTop+654+'px';left = e.clientX+'px';}
			c[1][_iH]='red'; c[2][_iH]='green'; c[3][_iH]='blue'; c[0][_iH]='hex'; _d.onmousedown=function(e,x,y) {
				e=e||event; e=e.target||e.srcElement;
				if(/^td/i.test(e.nodeName) && (e=e[_oP][_oP].id) && /^pick/i.test(e) && f)f(c[0][_iH],c[1][_iH],c[2][_iH],c[3][_iH]);
				p[_s].left=-1000+'px';
				_d.onmousedown=null;
			}
		}
	}
}
function updateFieldColor(hex,r,g,b,x) {
	(x=y.getElementsByTagName('input')[0]).type=='button'?x[_s].backgroundColor=hex:'';
	(x=y.getElementsByTagName('input')[1]).type=='text'?x.value=hex:'';
}

onload=function(){
	ColorPicker(img,updateFieldColor);

	for(i=0;t=_d.getElementById('picker436').getElementsByTagName('input')[i++];)
		t.onclick=/^but/i.test(t.type)?function(e){Picker.showPicker(e);y=this.parentNode.parentNode;}:null;
	for(i=0;t=_d.getElementById('picker437').getElementsByTagName('input')[i++];)
		t.onclick=/^but/i.test(t.type)?function(e){Picker.showPicker(e);y=this.parentNode.parentNode;}:null;
}

function setColors(){
	x=document.getElementById('pickerTable').getElementsByTagName('input');
	y=(t=document.getElementById('example')).getElementsByTagName('td');
	for(var i=0;i<y.length;i++){
		if(x[0].value)y[i].style.backgroundColor=x[0].value;
		if(x[2].value) y[i].style.color=x[2].value;
	}
	if (x[4].value)t.style.backgroundColor=x[4].value;
}
var img = new Image();
img.src='/resources/gfx_projects/tlo.gif';
