var baseColor = {r:0,g:0,b:0};
var currentColor = {r:0,g:0,b:0};
var lastValues = [180,180];
$(document).ready(
function()
{
	$('#hue').Slider(
		{
			accept : '#hueIndic',
			onSlide : function( cordx, cordy,x, y)
			{
				setVertColor(parseInt(cordx * 255 / 100));
				setGradientColor();
			},
			onChange : function()
			{
				document.body.style.backgroundColor = 'rgb(' + currentColor.r + ',' + currentColor.g + ',' + currentColor.b + ')';
			}
		}
	);
	$("#text_container").hover(
	function() {
	  $('#press_enter').fadeIn(500);
	},
	function() {
	  $('#press_enter').fadeOut(300);
	  //document.getElementById('press_enter').style.color = colorBackup;
	});
}
);
function setVertColor(indic){
	var n=256/6, j=256/n, C=indic, c=C%n;
 
	baseColor = {
		r : parseInt(C<n?255:C<n*2?255-c*j:C<n*4?0:C<n*5?c*j:255),
		g : parseInt(C<n*2?0:C<n*3?c*j:C<n*5?255:255-c*j),
		b : parseInt(C<n?c*j:C<n*3?255:C<n*4?255-c*j:0)
	};
	//document.getElementById('color').style.backgroundColor = 'rgb(' + baseColor.r + ',' + baseColor.g + ',' + baseColor.b + ')';
}
 
function setGradientColor(){
	var r = Math.round((1-(1-(baseColor.r/255))*(lastValues[0]/255))*(255-lastValues[1]));
	var g = Math.round((1-(1-(baseColor.g/255))*(lastValues[0]/255))*(255-lastValues[1]));
	var b = Math.round((1-(1-(baseColor.b/255))*(lastValues[0]/255))*(255-lastValues[1]));
	document.body.style.backgroundColor = 'rgb(' + r + ',' + g + ',' + b + ')';
	currentColor = {r:r,g:g,b:b};
}
function rgb2hex(rgb) {
 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
 return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
function hex(x) {
  var hexDigits = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"); 
  return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
}
