
	var hue;
	var picker;
	var dd1, dd2;
	var r, g, b;
	var firstFlag = 0;

function calculateHSV()
  {
    var max = Math.max(Math.max(red, green), blue);
    var min = Math.min(Math.min(red, green), blue);
    
    value = max;
    
    saturation = 0;
    if(max != 0)
      saturation = 1 - min/max;
      
    hue = 0;
    if(min == max)
      return;
    
    var delta = (max - min);
    if (red == max)
      hue = (green - blue) / delta;
    else if (green == max)
      hue = 2 + ((blue - red) / delta);
    else
      hue = 4 + ((red - green) / delta);
    hue = hue * 60;
    if(hue <0)
      hue += 360;
  }





function init() {
		pickerInit();
		ddcolorposter.fillcolorbox("pickerhexval", "colorbox1"); //PREFILL "colorbox1" with hex value from "colorfield1"
		ddcolorposter.echocolor('pickerhexval', 'colorbox1');
    }

    function pickerInit() {
		hue = YAHOO.widget.Slider.getVertSlider("hueBg", "hueThumb", 0, 131);
		hue.onChange = function(newVal) { hueUpdate(newVal); };

		picker = YAHOO.widget.Slider.getSliderRegion("pickerDiv", "selector",
				0, 131, 0, 131);
		picker.onChange = function(newX, newY) { pickerUpdate(newX, newY); };

		hueUpdate();

	}

	executeonload(init);

	function pickerUpdate(newX, newY) {
		pickerSwatchUpdate();
	}


	function hueUpdate(newVal) {

		var h = (180 - (hue.getValue() * 180 / 131)) / 180;
		if (h == 1) { h = 0; }

		var a = YAHOO.util.Color.hsv2rgb( h, 1, 1);

		document.getElementById("pickerDiv").style.backgroundColor =
			"rgb(" + a[0] + ", " + a[1] + ", " + a[2] + ")";

		pickerSwatchUpdate();
	}

	function pickerSwatchUpdate() {
		var h = (180 - (hue.getValue() * 180 / 131));
		if (h == 180) { h = 0; }


		h = h / 180;

		var s = picker.getXValue() / 131;

		var v = (131 - picker.getYValue()) / 131;

		var a = YAHOO.util.Color.hsv2rgb( h, s, v );



		if(firstFlag == 1) {
			var hexvalue = document.getElementById("pickerhexval").value = YAHOO.util.Color.rgb2hex(a[0], a[1], a[2]);
			ddcolorposter.initialize(a[0], a[1], a[2], hexvalue);
		}
		else {
			firstFlag = 1;
		}
	}

	function updateColorFromText(inputobj, divID) {
		ddcolorposter.echocolor(inputobj, divID);
	}


