	var stop=null;
	hist_HSV = new Array;
	cache_affiche = "a";
	function newcolorpick(color,name,att)
	{
		var html = '<'+'input type="text" name="'+name+'" id="'+name+'" value="'+color+'" style="cursor:pointer;" onkeyup="javascript:update_colorpicker(\''+name+'\',this.value,1);" onclick="javascript:cacher_afficher_colorpicker(\''+name+'\');"'+att+' /><'+'div class="colorpicker" id="colorpicker_'+name+'">	<'+'div class="selecteur" id="selecteur_'+name+'">        <'+'div class="couleurs" onmousedown="javascript:onmousedown_clp(event,\''+name+'\',\'sv\');" onmousemove="javascript:select_colorpicker(event,\''+name+'\',\'sv\');"  id="couleurs_'+name+'">            <'+'div class="couleurs_curs" id="couleurs_curs_'+name+'"><'+'/div>        <'+'/div>        <'+'div class="multicolore" onmousedown="javascript:onmousedown_clp(event,\''+name+'\',\'h\');" onmousemove="javascript:select_colorpicker(event,\''+name+'\',\'h\');" id="multicolore_'+name+'">            <'+'div class="multicolore_curs" id="multicolore_curs_'+name+'"><'+'/div>        <'+'/div>    <'+'/div>    <'+'div class="options" id="options_'+name+'">        <'+'div class="apercu" id="apercu_'+name+'"><'+'/div>        <'+'span class="champ"><'+'label for="r_'+name+'">R:<'+'/label><'+'input type="text" style="width:50px;" id="r_'+name+'" onkeyup="javascript:update_rgb_colorpicker(\''+name+'\');" name="r_'+name+'" /><'+'/span>        <'+'span class="champ"><'+'label for="r_'+name+'">G:<'+'/label> <'+'input type="text" style="width:50px;" id="g_'+name+'" onkeyup="javascript:update_rgb_colorpicker(\''+name+'\');" name="g_'+name+'" /><'+'/span>        <'+'span class="champ"><'+'label for="r_'+name+'">B:<'+'/label> <'+'input type="text" style="width:50px;" id="b_'+name+'" onkeyup="javascript:update_rgb_colorpicker(\''+name+'\');" name="b_'+name+'" /><'+'/span>        <'+'span class="champ"><'+'label for="r_'+name+'">Hex:<'+'/label> <'+'input type="text" style="width:50px;" id="hex_'+name+'" onkeyup="javascript:update_colorpicker(\''+name+'\',this.value,1);" name="hex_'+name+'" /><'+'/span>    <'+'/div><div class="clean"><'+'/div>    <'+'a class="fermer" onclick="javascript:cacher_afficher_colorpicker(\''+name+'\');">Fermer<'+'/a><'+'/div>';
		document.write(html);
		hist_HSV[name] = new Array;
		hist_HSV[name] = [0,0,100];
		$('colorpicker_'+name).top=findPos($(name))+'px';
		$('colorpicker_'+name).left=findPos($(name))+'px';
		cacher_afficher_colorpicker(name);
		update_colorpicker(name,color,1);
		return true;
	}
	function addEvent(obj,event,fct)
	{
			if( obj.attachEvent)
			{
				obj.attachEvent('on' + event,fct);
			}
			else
			{
				obj.addEventListener(event,fct,true);
			}
	}
	function findPos(obj)
	{
		var curleft = curtop = 0;
		if(obj.offsetParent)
		{
			curleft = obj.offsetLeft;
			curtop = obj.offsetTop;
			while(obj = obj.offsetParent)
			{
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			}
		}
		return [curleft,curtop];
	}
	function cacher_afficher_colorpicker(name)
	{
		var clp = $('colorpicker_'+name).style;
		if(clp.display!='none')
		{
			clp.display="none";
		}
		else
		{
			clp.display="block";
		}
		if(cache_affiche!=name && $('colorpicker_'+cache_affiche))
		{
			$('colorpicker_'+cache_affiche).style.display="none";
		}
		cache_affiche = name;
		return true;
	}
	function onmousedown_clp(event,elmt,svh)
	{
		stop = svh;
		select_colorpicker(event,elmt,svh);
	}
	function onmouseup_clp()
	{
		stop = null;
	}
	function select_colorpicker(event,elmt,svh)
	{
			if(stop)
			{
				event.returnValue = false; //Pour Internet Explorer
				if( event.preventDefault ) event.preventDefault();
				if(svh=='sv' && stop=='sv')
				{
					var eX = 0;
					var eY = 0;
					var element = $('couleurs_'+elmt);
					do
					{
						eX += element.offsetLeft;
						eY += element.offsetTop;
						element = element.offsetParent;
					}
					while( element && element.style.position != 'absolute');
					var x = (event.clientX + (document.documentElement.scrollLeft + document.body.scrollLeft))-eX;
					var y = (event.clientY + (document.documentElement.scrollTop + document.body.scrollTop))-eY;
					h = hist_HSV[elmt][0];
					s = x/1.8;
					v = 100-y/1.8;
					color = hsv2hex([h,s,v]);
					update_colorpicker(elmt,color,0,'sv',0);
				}
				if(svh=='h' && stop=='h')
				{
					var eY = 0;
					var element = $('multicolore_'+elmt);
					do
					{
						eY += element.offsetTop;
						element = element.offsetParent;
					}
					while( element && element.style.position != 'absolute');
					var y = (event.clientY + (document.documentElement.scrollTop + document.body.scrollTop))-eY;
					if(y<0)
					{
						y=0;
					}
					if(y>180)
					{
						y=180;
					}
					h = y*2;
					s = hist_HSV[elmt][1];
					v = hist_HSV[elmt][2];
					color = hsv2hex([h,s,v]);
					update_colorpicker(elmt,color,0,'h',y);
				}
			}
	}
	function hsv_max_min(hsv)
	{
		var h = hsv[0];
		var s = hsv[1];
		var v = hsv[2];
		if(h>360)
		{
			h=360;
		}
		if(h<0)
		{
			h=0;
		}
		if(s>100)
		{
			s=100;
		}
		if(s<0)
		{
			s=0;
		}
		if(v>100)
		{
			v=100;
		}
		if(v<0)
		{
			v=0;
		}
		return [h,s,v];
	}
	function update_rgb_colorpicker(name)
	{
		var r = $('r_'+name).value;
		var g = $('g_'+name).value;
		var b = $('b_'+name).value;
		update_colorpicker(name,rgb2hex([r,g,b]),1);
	}
	function update_colorpicker(name,color,m,svh,h)
	{
		if(color.charAt(0) == '#')
		{
			color = color.substr(1);
		}
		hsv_color = hsv_max_min(hex2hsv(color));
		if(color.length==6)
		{
			$('hex_'+name).value='#'+color;
			$(name).value='#'+color;
			$('apercu_'+name).style.backgroundColor='#'+color;
				hist_HSV[name] = [hist_HSV[name][0],hsv_color[1],hsv_color[2]];
				$('couleurs_'+name).style.backgroundColor='#'+hsv2hex([hist_HSV[name][0],100,100]);
			if(svh=="h")
			{
				$('couleurs_'+name).style.backgroundColor='#'+hsv2hex([h*2,100,100]);
				hist_HSV[name] = [h*2,hsv_color[1],hsv_color[2]];
				$('multicolore_curs_'+name).style.top=h-4+"px";
			}
			else if(svh=="sv")
			{
				$('couleurs_curs_'+name).style.left=1.8*hsv_color[1]-5+"px";
				$('couleurs_curs_'+name).style.top=180-1.8*hsv_color[2]-5+"px";
			}
			if(m==1)
			{
				$('couleurs_'+name).style.backgroundColor='#'+hsv2hex([hsv_color[0],100,100]);
				hist_HSV[name] = [hsv_color[0],hsv_color[1],hsv_color[2]];
				$('multicolore_curs_'+name).style.top=hsv_color[0]/2-4+"px";
				$('couleurs_curs_'+name).style.left=1.8*hsv_color[1]-5+"px";
				$('couleurs_curs_'+name).style.top=180-1.8*hsv_color[2]-5+"px";
			}
			rgb = hex2rgb(color);
			$('r_'+name).value=rgb[0];
			$('g_'+name).value=rgb[1];
			$('b_'+name).value=rgb[2];
		}
		return(color);
	}
	/********************
	**** Conversions ****
	********************/
	function hsv2hex(h)
	{
		return rgb2hex(hsv2rgb(h));
	}
	function hex2hsv(h)
	{
		return rgb2hsv(hex2rgb(h));
	}
	function hex2rgb(hex)
	{
		if (hex.substring(0, 1) == '#')
		{
			hex = hex.substring(1);
		}
		return [
		parseInt(hex.substring(0, 2), 16),
		parseInt(hex.substring(2, 4), 16),
		parseInt(hex.substring(4, 6), 16)
		];
	}
	function rgb2hex(rgb)
	{
		var red = rgb[0];
		var green = rgb[1];
		var blue = rgb[2];
		var hex = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
		var rgb_a = new Array();
		var k = 0;
		for(var i=0;i<16;i++)
		{
			for(var j=0;j<16;j++)
			{
				rgb_a[k] = hex[i]+hex[j];
				k++;
			}
		}
		return(rgb_a[red]+rgb_a[green]+rgb_a[blue]);
	}
	function hsv2rgb(r)
	{
		var R, B, G, S = r[1] / 100, V = r[2] / 100, H = r[0] / 360;
		if (S > 0)
		{
			if (H >= 1)
			{
				H = 0;
			}
			H = 6 * H;
			F = H - Math.floor(H);
			A = Math.round(255 * V * (1.0 - S));
			B = Math.round(255 * V * (1.0 - (S * F)));
			C = Math.round(255 * V * (1.0 - (S * (1.0 - F))));
			V = Math.round(255 * V);
			switch (Math.floor(H))
			{
				case 0: R = V; G = C; B = A; break;
				case 1: R = B; G = V; B = A; break;
				case 2: R = A; G = V; B = C; break;
				case 3: R = A; G = B; B = V; break;
				case 4: R = C; G = A; B = V; break;
				case 5: R = V; G = A; B = B; break;
			}
			return [R ? R : 0, G ? G : 0, B ? B : 0];
		}
		else
		{
			return [(V = Math.round(V * 255)), V, V];
		}
	}
	function rgb2hsv(r)
	{
		var R = r[0] / 255;
		var G = r[1] / 255;
		var B = r[2] / 255;
		var var_Min = Math.min(R, G, B);
		var var_Max = Math.max(R, G, B);
		var del_Max = var_Max - var_Min;
		var V = var_Max;
		var H, S;
		if (del_Max == 0)
		{
			H = 0;
			S = 0;
		}
		else
		{
			S = del_Max / var_Max;
			var del_R = (((var_Max - R) / 6 ) + (del_Max / 2)) / del_Max;
			var del_G = (((var_Max - G) / 6 ) + (del_Max / 2)) / del_Max;
			var del_B = (((var_Max - B) / 6 ) + (del_Max / 2)) / del_Max;
			if (R == var_Max)
			{
				H = del_B - del_G;
			}
			else if (G == var_Max)
			{
				H = (1 / 3) + del_R - del_B;
			}
			else if (B == var_Max)
			{
				H = (2 / 3) + del_G - del_R;
			}
			if (H < 0)
			{
				H += 1;
			}
			else if (H > 1)
			{
				H -= 1;
			}
		}
		return [H * 360, S * 100, V * 100];
	}
	document.onmouseup=onmouseup_clp;