var target = "";
var mouse_x = 0;
var mouse_y = 0;

function initialize()
{
	hide_color_table();
	
	document.onmousemove = on_mouse_move;

	if ( document.layers ) document.captureEvents( Event.MOUSEMOVE );
}

function on_mouse_move( e )
{	
	mouse_x = get_mouse_x( e );
	mouse_y = get_mouse_y( e );
}

function show_color_table( t )
{
	var color_table = get_color_table();
	target = t;
	
	color_table.style.display = "block";
	color_table.style.position = "absolute";
	color_table.style.top = mouse_y;
	color_table.style.left = mouse_x + 10;
	
	var target_color = document.getElementsByName( t + "_color" )[ 0 ].value;

	preview_color( target_color );
}

function hide_color_table()
{
	get_color_table().style.display = "none";
}

function preview_color( color )
{
	document.getElementById( "color_sample" ).style.backgroundColor = color;
	document.getElementById( "color_code" ).innerHTML = color;
}

function select_color( color )
{
	document.getElementsByName( target + "_color" )[ 0 ].value = color;
	document.getElementById( target + "_color_sample" ).style.backgroundColor = color;
	
	document.clear;
}

function update_color( t )
{
	color = document.getElementsByName( t + "_color" )[ 0 ].value;
	document.getElementById( t + "_color_sample" ).style.backgroundColor = color;
}

function get_color_table()
{
	return document.getElementById( "color_table" );
}

function get_mouse_x( e )
{
	if ( window.opera ) return e.clientX;
	else if ( document.all ) return document.body.scrollLeft + event.clientX;
	else if ( document.layers || document.getElementById ) return e.pageX;
}

function get_mouse_y( e )
{
	var scrolltop = document.body.scrollTop || document.documentElement.scrollTop;
	
	if ( window.opera ) return e.clientY;
//	else if ( document.all ) return document.body.scrollTop + event.clientY;
	else if ( document.all ) return scrolltop + event.clientY;
	else if ( document.layers || document.getElementById ) return e.pageY;
}