var sCurrentScale="h";var iOldSwatch=0;var sMode="rgb";var bPicking=false;var sColor="";var newSliderPos;var currentColor="";var slider;var colorfield;var timerVariations;function setTrackbarPosition(A){alert("set slider: "+A);slider.setValue(A,true,true,true)}function positionMarker(){alert("positionmarker:"+sCurrentScale);if(sCurrentScale=="r"){colorfield.setRegionValue(parseInt(document.getElementById("val_b").value),255-parseInt(document.getElementById("val_g").value),true,true,true)}if(sCurrentScale=="g"){colorfield.setRegionValue(parseInt(document.getElementById("val_b").value),255-parseInt(document.getElementById("val_r").value),true,true,true)}if(sCurrentScale=="b"){colorfield.setRegionValue(parseInt(document.getElementById("val_r").value),255-parseInt(document.getElementById("val_g").value),true,true,true)}if(sCurrentScale=="s"){colorfield.setRegionValue(Math.round(parseInt(document.getElementById("val_h").value)*256/360),255-Math.round(parseInt(document.getElementById("val_v").value)*256/100),true,true,true)}if(sCurrentScale=="v"){colorfield.setRegionValue(Math.round(parseInt(document.getElementById("val_h").value)*256/360),255-Math.round(parseInt(document.getElementById("val_s").value)*256/100),true,true,true)}}function setActiveHsvColor(D){var C=hsv2rgb(D);document.getElementById("val_r").value=C.r;document.getElementById("val_g").value=C.g;document.getElementById("val_b").value=C.b;document.getElementById("val_hex").value=rgb2html(C).substr(1,6).toUpperCase();var B=255-parseInt(document.getElementById("val_"+sCurrentScale).value);if((sCurrentScale=="s")||(sCurrentScale=="v")){B=255-Math.round(parseInt(document.getElementById("val_"+sCurrentScale).value)*256/100)}setTrackbarPosition(B);var A=getTrackerValue();changeFading(A);positionMarker();updatePickerSwatches()}function setActiveColorFromSwatch(A){iOldSwatch=A;setActiveColor(aPalette[A]);document.getElementById("button_updateswatch").disabled=false;document.getElementById("old_color").style.backgroundColor="#"+aPalette[A]}function updateFromRgbValues(){var D=convertToInt(document.getElementById("val_r").value,0,255);var C=convertToInt(document.getElementById("val_g").value,0,255);var A=convertToInt(document.getElementById("val_b").value,0,255);document.getElementById("val_r").value=D;document.getElementById("val_g").value=C;document.getElementById("val_b").value=A;var B=new Object();B.r=D;B.g=C;B.b=A;setActiveColor(rgb2html(B))}function updateFromHsvValues(){var E=convertToInt(document.getElementById("val_h").value,0,359);var D=convertToInt(document.getElementById("val_s").value,0,100);var A=convertToInt(document.getElementById("val_v").value,0,100);document.getElementById("val_h").value=E;document.getElementById("val_s").value=D;document.getElementById("val_v").value=A;var C=new Object();C.h=E;C.s=D;C.v=A;var B=hsv2rgb(C);document.getElementById("val_r").value=B.r;document.getElementById("val_g").value=B.g;document.getElementById("val_b").value=B.b;setActiveColor(rgb2html(B))}function updateFromHexValue(){var A=convertToHex(document.getElementById("val_hex").value);document.getElementById("val_hex").value=A;setActiveColor(A)}function convertToHex(C){C=C.toUpperCase();var B="";for(var A=0;A<C.length;A++){if("0123456789ABCDEF".indexOf(C.charAt(A))>=0){B+=C.charAt(A)}}B=B.substr(0,6);if(B.length==3){B=B.charAt(0)+B.charAt(0)+B.charAt(1)+B.charAt(1)+B.charAt(2)+B.charAt(2)}while(B.length<6){B+="0"}return(B)}function initColorPicker(){getPalette();renderCurrentPalette();slider=YAHOO.widget.Slider.getVertSlider("trackbar","tracker",0,255);slider.subscribe("change",sliderMoved);colorfield=YAHOO.widget.Slider.getSliderRegion("colorfield","marker",0,255,0,255);colorfield.subscribe("change",markerMoved);changeScale(sCurrentScale);var A="808080";if(aPalette.length>0){A=aPalette[0]}if(sColor!=""){A=sColor}var B=getQuerystring("s","-");A=getQuerystring("c",A);if(B!="-"){setActiveColorFromSwatch(parseInt(B))}else{setActiveColor(A)}}function markerMoved(){var D,C;if(sCurrentScale=="r"){D=colorfield.getXValue()+2;C=255-colorfield.getYValue()-2;document.getElementById("val_b").value=D;document.getElementById("val_g").value=C}if(sCurrentScale=="g"){D=colorfield.getXValue()+2;C=255-colorfield.getYValue()-2;document.getElementById("val_b").value=D;document.getElementById("val_r").value=C}if(sCurrentScale=="b"){D=colorfield.getXValue()+2;C=255-colorfield.getYValue()-2;document.getElementById("val_r").value=D;document.getElementById("val_g").value=C}if(sCurrentScale=="h"){D=Math.round(100*(colorfield.getXValue()+2)/255);C=Math.round(100*(255-colorfield.getYValue()-2)/255);document.getElementById("val_s").value=D;document.getElementById("val_v").value=C}if(sCurrentScale=="s"){D=Math.round(359*(colorfield.getXValue()+2)/255);C=Math.round(100*(255-colorfield.getYValue()-2)/255);document.getElementById("val_h").value=D;document.getElementById("val_v").value=C}if(sCurrentScale=="v"){D=Math.round(359*(colorfield.getXValue()+2)/255);C=Math.round(100*(255-colorfield.getYValue()-2)/255);document.getElementById("val_h").value=D;document.getElementById("val_s").value=C}if("rgb".indexOf(sCurrentScale)>=0){var B=new Object();B.r=parseInt(document.getElementById("val_r").value);B.g=parseInt(document.getElementById("val_g").value);B.b=parseInt(document.getElementById("val_b").value);document.getElementById("val_hex").value=rgb2html(B);var A=rgb2hsv(B);document.getElementById("val_h").value=A.h;document.getElementById("val_s").value=A.s;document.getElementById("val_v").value=A.v}else{var A=new Object();A.h=parseInt(document.getElementById("val_h").value);A.s=parseInt(document.getElementById("val_s").value);A.v=parseInt(document.getElementById("val_v").value);var B=hsv2rgb(A);document.getElementById("val_r").value=B.r;document.getElementById("val_g").value=B.g;document.getElementById("val_b").value=B.b;document.getElementById("val_hex").value=rgb2html(B)}repositionSliderAndMarker();updatePickerSwatches()}function sliderMoved(){changeFading(getTrackerValue());var C;if("rgb".indexOf(sCurrentScale)>=0){C=255-getTrackerValue();document.getElementById("val_"+sCurrentScale).value=C}if("sv".indexOf(sCurrentScale)>=0){C=Math.round(100-100*getTrackerValue()/255);document.getElementById("val_"+sCurrentScale).value=C}if(sCurrentScale=="h"){C=Math.round(359-359*getTrackerValue()/255);document.getElementById("val_"+sCurrentScale).value=C}if("rgb".indexOf(sCurrentScale)>=0){var B=new Object();B.r=parseInt(document.getElementById("val_r").value);B.g=parseInt(document.getElementById("val_g").value);B.b=parseInt(document.getElementById("val_b").value);document.getElementById("val_hex").value=rgb2html(B);var A=rgb2hsv(B);document.getElementById("val_h").value=A.h;document.getElementById("val_s").value=A.s;document.getElementById("val_v").value=A.v}else{var A=new Object();A.h=parseInt(document.getElementById("val_h").value);A.s=parseInt(document.getElementById("val_s").value);A.v=parseInt(document.getElementById("val_v").value);var B=hsv2rgb(A);document.getElementById("val_r").value=B.r;document.getElementById("val_g").value=B.g;document.getElementById("val_b").value=B.b;document.getElementById("val_hex").value=rgb2html(B)}updatePickerSwatches();repositionSliderAndMarker()}function changeScale(A){sCurrentScale=A;if(sCurrentScale=="h"){document.getElementById("rgb_a").style.display=document.getElementById("rgb_b").style.display="none";document.getElementById("hue").style.display="block"}else{document.getElementById("rgb_a").style.backgroundImage="url(gfx/picker/"+sCurrentScale+"_a.jpg)";document.getElementById("rgb_b").style.backgroundImage="url(gfx/picker/"+sCurrentScale+"_b.jpg)";document.getElementById("rgb_a").style.display=document.getElementById("rgb_b").style.display="block";document.getElementById("hue").style.display="none"}document.getElementById("trackbar").style.backgroundImage="url(gfx/picker/"+sCurrentScale+"_c.jpg)";repositionSliderAndMarker();changeFading(getTrackerValue())}function changeFading(A){if(sCurrentScale=="h"){var E=359-Math.round(359*A/255);var D=new Object();D.h=E;D.v=D.s=100;document.getElementById("hue").style.backgroundColor="#"+rgb2html(hsv2rgb(D))}else{var C,B;A=255-A;if((sCurrentScale=="s")||(sCurrentScale=="v")){C=Math.round(100*A/255)}else{C=A}if((sCurrentScale=="s")||(sCurrentScale=="v")){B=100-Math.round((A/256)*100)}else{B=Math.round((A/256)*100)}B=Math.round((A/256)*100);document.getElementById("rgb_b").style.filter="alpha(opacity="+B+")";document.getElementById("rgb_b").style.opacity=B/100}}function repositionSliderAndMarker(){if("rgb".indexOf(sCurrentScale)>=0){var B=new Object();B.r=parseInt(document.getElementById("val_r").value);B.g=parseInt(document.getElementById("val_g").value);B.b=parseInt(document.getElementById("val_b").value);if(sCurrentScale=="r"){newSliderPos=255-B.r;slider.setValue(newSliderPos,true,true,true);colorfield.setRegionValue(B.b,255-B.g,true,true,true)}if(sCurrentScale=="g"){newSliderPos=255-B.g;slider.setValue(newSliderPos,true,true,true);colorfield.setRegionValue(B.b,255-B.r,true,true,true)}if(sCurrentScale=="b"){newSliderPos=255-B.b;slider.setValue(newSliderPos,true,true,true);colorfield.setRegionValue(B.r,255-B.g,true,true,true)}}if("hsv".indexOf(sCurrentScale)>=0){var A=new Object();A.h=parseInt(document.getElementById("val_h").value);A.s=parseInt(document.getElementById("val_s").value);A.v=parseInt(document.getElementById("val_v").value);if(sCurrentScale=="h"){newSliderPos=255-Math.round(255*A.h/359);slider.setValue(newSliderPos,true,true,true);colorfield.setRegionValue(Math.round(255*A.s/100),255-(Math.round(255*A.v/100)),true,true,true)}if(sCurrentScale=="s"){newSliderPos=255-Math.round(255*A.s/100);slider.setValue(newSliderPos,true,true,true);colorfield.setRegionValue(Math.round(255*A.h/359),255-(Math.round(255*A.v/100)),true,true,true)}if(sCurrentScale=="v"){newSliderPos=255-Math.round(255*A.v/100);slider.setValue(newSliderPos,true,true,true);colorfield.setRegionValue(Math.round(255*A.h/359),255-(Math.round(255*A.s/100)),true,true,true)}}}function updatePickerSwatches(){var B=new Object();B.r=parseInt(document.getElementById("val_r").value);B.g=parseInt(document.getElementById("val_g").value);B.b=parseInt(document.getElementById("val_b").value);document.getElementById("active_color").style.backgroundColor="#"+rgb2html(B);document.getElementById("websafe_color").style.backgroundColor="#"+makeWebSafe(rgb2html(B));var A=rgb2hsv(B);if(A.v<50){document.getElementById("marker").style.borderColor="#ffffff"}else{document.getElementById("marker").style.borderColor="#000000"}if(timerVariations){window.clearTimeout(timerVariations)}currentColor=rgb2html(B);timerVariations=window.setTimeout("renderVariations()",200)}function setActiveColor(C){C=fixRgbColor(C);var B=html2rgb(C);document.getElementById("val_r").value=B.r;document.getElementById("val_g").value=B.g;document.getElementById("val_b").value=B.b;var A=rgb2hsv(B);document.getElementById("val_h").value=A.h;document.getElementById("val_s").value=A.s;document.getElementById("val_v").value=A.v;document.getElementById("val_hex").value=C.toUpperCase();repositionSliderAndMarker();changeFading(newSliderPos);updatePickerSwatches()}function renderVariations(){var C=document.getElementById("content_variations");var B=document.getElementById("active_color").style.backgroundColor.substr(1,6);B=currentColor;var A="";A="<div style='width:220px;height:100px;position:relative;'>";A+="   <div title='More green' class='variationswatch' style='left:17px;top:0px;background-color:#"+correctColor(B,"g",20)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='More yellow' class='variationswatch' style='left:51px;top:0px;background-color:#"+correctColor(B,"b",-20)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='More cyan' class='variationswatch' style='left:0px;top:34px;background-color:#"+correctColor(B,"r",-20)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='Current color' class='variationswatch' style='left:34px;top:34px;background-color:#"+B+"' onclick=''><img src='gfx/pixel.gif' alt='setActiveColor(this.style.backgroundColor)' /></div>";A+="   <div title='More red' class='variationswatch' style='left:68px;top:34px;background-color:#"+correctColor(B,"r",20)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='More blue' class='variationswatch' style='left:17px;top:68px;background-color:#"+correctColor(B,"b",20)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='More magenta' class='variationswatch' style='left:51px;top:68px;background-color:#"+correctColor(B,"g",-20)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='Less saturation, more lightness' class='variationswatch' style='left:130px;top:0px;background-color:#"+correctColor(correctColor(B,"s",-10),"v",10)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='More lightness' class='variationswatch' style='left:164px;top:0px;background-color:#"+correctColor(B,"v",10)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='More saturation, more lightness' class='variationswatch' style='left:198px;top:0px;background-color:#"+correctColor(correctColor(B,"s",10),"v",10)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='Less saturation' class='variationswatch' style='left:130px;top:34px;background-color:#"+correctColor(B,"s",-10)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='Current color' class='variationswatch' style='left:164px;top:34px;background-color:#"+B+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='More saturation' class='variationswatch' style='left:198px;top:34px;background-color:#"+correctColor(B,"s",10)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='Less saturation, less lightness' class='variationswatch' style='left:130px;top:68px;background-color:#"+correctColor(correctColor(B,"s",-10),"v",-10)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='Less lightness' class='variationswatch' style='left:164px;top:68px;background-color:#"+correctColor(B,"v",-10)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="   <div title='More saturation, less lightness' class='variationswatch' style='left:198px;top:68px;background-color:#"+correctColor(correctColor(B,"v",-10),"s",10)+"' onclick='setActiveColor(this.style.backgroundColor)'><img src='gfx/pixel.gif' alt='' /></div>";A+="</div>";C.innerHTML=A;document.getElementById("content_colordesc").innerHTML=nameColor(B)}function getTrackerValue(){return(slider.getValue()+2)};