/*
	Copyright (c) Art. Lebedev Studio | http://www.artlebedev.ru/
	Andrew Shitov | ash@design.ru
*/

function HSV2RGB (H, S, V)
{
	var R, G, B;

	if (!S)
	{
		R = G = B = V;
	}
	else
	{
		H /= 360;
		S /= 100;
		V /= 100;

		var vH = H * 6;
		var vI = Math.floor (vH);
		var V1 = H * (1 - S);
		var V2 = (V * (1 - S * (vH - vI)));
		var V3 = (V * (1 - S * (1 - (vH - vI))));


		switch (vI)
		{
			case 0:
				R = V; G = V3; B = V1; break;
			case 1:
				R = V2; G = V; B = V1; break;
			case 2:
				R = V1; G = V; B = V3; break;
			case 3:
				R = V1; G = V2; B = V; break;
			case 4:
				R = V2; G = V1; B = V; break;
			default:
				R = V; G = V1; B = V2; break;
		}
	}


	var xR = dec2hex (Math.floor (R * 255));
	var xG = dec2hex (Math.floor (G * 255));
	var xB = dec2hex (Math.floor (B * 255));
	var xRGB = xR + xG + xB;
	return xRGB;
}

function dec2hex (dec)
{
	var hexChars = "0123456789ABCDEF";
	var a = dec % 16;
	var b = (dec - a) / 16;
	hex = '' + hexChars.charAt (b) + hexChars.charAt (a);
	return hex;
}

function AlterColor()
{	
	var logodiv = document.getElementById ('ArtLebedevLogo');
	if (logodiv) logodiv.style.backgroundColor = '#' + HSV2RGB (
			Math.floor (360 * Math.random()), 
			30 + Math.floor (70 * Math.random()), 
			30 + Math.floor (50 * Math.random()));
	
}
