/**
 * jscolor, JavaScript Color Picker
 *
 * @version 1.3.0
 * @license GNU Lesser General Public License, http://www.gnu.org/copyleft/lesser.html
 * @author  Honza Odvarko http://odvarko.cz
 * @created 2008-06-15
 * @updated 2009-10-16
 * @link    http://jscolor.com
 */
var jscolor={dir:"/static/js/jscolor/",bindClass:"color",binding:true,preloading:true,install:function(){jscolor.addEvent(window,"load",jscolor.init)},init:function(){jscolor.binding&&jscolor.bind();jscolor.preloading&&jscolor.preload()},getDir:function(){if(!jscolor.dir){var d=jscolor.detectDir();jscolor.dir=d!==false?d:"jscolor/"}return jscolor.dir},detectDir:function(){for(var d=location.href,g=document.getElementsByTagName("base"),c=0;c<g.length;c+=1)if(g[c].href)d=g[c].href;g=document.getElementsByTagName("script"); for(c=0;c<g.length;c+=1)if(g[c].src&&/(^|\/)jscolor\.js([?#].*)?$/i.test(g[c].src)){d=(new jscolor.URI(g[c].src)).toAbsolute(d);d.path=d.path.replace(/[^\/]+$/,"");d.query=null;d.fragment=null;return d.toString()}return false},bind:function(){for(var d=new RegExp("(^|\\s)("+jscolor.bindClass+")\\s*(\\{[^}]*\\})?","i"),g=document.getElementsByTagName("input"),c=0;c<g.length;c+=1){var h;if(!g[c].color&&g[c].className&&(h=g[c].className.match(d))){if(h[3])try{eval("prop="+h[3])}catch(m){}g[c].color= new jscolor.color(g[c],{})}}},preload:function(){for(var d in jscolor.imgRequire)jscolor.imgRequire.hasOwnProperty(d)&&jscolor.loadImage(d)},images:{pad:[181,101],sld:[16,101],cross:[15,15],arrow:[7,11]},imgRequire:{},imgLoaded:{},requireImage:function(d){jscolor.imgRequire[d]=true},loadImage:function(d){if(!jscolor.imgLoaded[d]){jscolor.imgLoaded[d]=new Image;jscolor.imgLoaded[d].src=jscolor.getDir()+d}},fetchElement:function(d){return typeof d==="string"?document.getElementById(d):d},addEvent:function(d, g,c){if(d.addEventListener)d.addEventListener(g,c,false);else d.attachEvent&&d.attachEvent("on"+g,c)},fireEvent:function(d,g){if(d)if(document.createEventObject){var c=document.createEventObject();d.fireEvent("on"+g,c)}else if(document.createEvent){c=document.createEvent("HTMLEvents");c.initEvent(g,true,true);d.dispatchEvent(c)}else d["on"+g]&&d["on"+g]()},getElementPos:function(d){var g=d;d=d;var c=0,h=0;if(g.offsetParent){do{c+=g.offsetLeft;h+=g.offsetTop}while(g=g.offsetParent)}for(;(d=d.parentNode)&& d.nodeName!=="BODY";){c-=d.scrollLeft;h-=d.scrollTop}return[c,h]},getElementSize:function(d){return[d.offsetWidth,d.offsetHeight]},getMousePos:function(d){if(!d)d=window.event;if(typeof d.pageX==="number")return[d.pageX,d.pageY];else if(typeof d.clientX==="number")return[d.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,d.clientY+document.body.scrollTop+document.documentElement.scrollTop]},getViewPos:function(){return typeof window.pageYOffset==="number"?[window.pageXOffset,window.pageYOffset]: document.body&&(document.body.scrollLeft||document.body.scrollTop)?[document.body.scrollLeft,document.body.scrollTop]:document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)?[document.documentElement.scrollLeft,document.documentElement.scrollTop]:[0,0]},getViewSize:function(){return typeof window.innerWidth==="number"?[window.innerWidth,window.innerHeight]:document.body&&(document.body.clientWidth||document.body.clientHeight)?[document.body.clientWidth, document.body.clientHeight]:document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)?[document.documentElement.clientWidth,document.documentElement.clientHeight]:[0,0]},URI:function(d){function g(c){for(var h="";c;)if(c.substr(0,3)==="../"||c.substr(0,2)==="./")c=c.replace(/^\.+/,"").substr(1);else if(c.substr(0,3)==="/./"||c==="/.")c="/"+c.substr(3);else if(c.substr(0,4)==="/../"||c==="/.."){c="/"+c.substr(4);h=h.replace(/\/?[^\/]*$/,"")}else if(c=== "."||c==="..")c="";else{var m=c.match(/^\/?[^\/]*/)[0];c=c.substr(m.length);h+=m}return h}this.authority=this.scheme=null;this.path="";this.fragment=this.query=null;this.parse=function(c){c=c.match(/^(([A-Za-z][0-9A-Za-z+.-]*)(:))?((\/\/)([^\/?#]*))?([^?#]*)((\?)([^#]*))?((#)(.*))?/);this.scheme=c[3]?c[2]:null;this.authority=c[5]?c[6]:null;this.path=c[7];this.query=c[9]?c[10]:null;this.fragment=c[12]?c[13]:null;return this};this.toString=function(){var c="";if(this.scheme!==null)c=c+this.scheme+":"; if(this.authority!==null)c=c+"//"+this.authority;if(this.path!==null)c+=this.path;if(this.query!==null)c=c+"?"+this.query;if(this.fragment!==null)c=c+"#"+this.fragment;return c};this.toAbsolute=function(c){c=new jscolor.URI(c);var h=this,m=new jscolor.URI;if(c.scheme===null)return false;if(h.scheme!==null&&h.scheme.toLowerCase()===c.scheme.toLowerCase())h.scheme=null;if(h.scheme!==null){m.scheme=h.scheme;m.authority=h.authority;m.path=g(h.path);m.query=h.query}else{if(h.authority!==null){m.authority= h.authority;m.path=g(h.path);m.query=h.query}else{if(h.path===""){m.path=c.path;m.query=h.query!==null?h.query:c.query}else{if(h.path.substr(0,1)==="/")m.path=g(h.path);else{m.path=c.authority!==null&&c.path===""?"/"+h.path:c.path.replace(/[^\/]+$/,"")+h.path;m.path=g(m.path)}m.query=h.query}m.authority=c.authority}m.scheme=c.scheme}m.fragment=h.fragment;return m};d&&this.parse(d)},color:function(d,g){function c(a,e,b){var k=Math.min(Math.min(a,e),b),l=Math.max(Math.max(a,e),b),j=l-k;if(j===0)return[null, 0,l];a=a===k?3+(b-e)/j:e===k?5+(a-b)/j:1+(e-a)/j;return[a===6?0:a,j/l,l]}function h(a,e,b){if(a===null)return[b,b,b];var k=Math.floor(a),l=b*(1-e);a=b*(1-e*(k%2?a-k:1-(a-k)));switch(k){case 6:case 0:return[b,a,l];case 1:return[a,b,l];case 2:return[l,b,a];case 3:return[l,a,b];case 4:return[a,l,b];case 5:return[b,l,a]}}function m(){delete jscolor.picker.owner;document.getElementsByTagName("body")[0].removeChild(jscolor.picker.boxB)}function G(a,e){if(!jscolor.picker){jscolor.picker={box:document.createElement("div"), boxB:document.createElement("div"),pad:document.createElement("div"),padB:document.createElement("div"),padM:document.createElement("div"),sld:document.createElement("div"),sldB:document.createElement("div"),sldM:document.createElement("div")};for(var b=0;b<jscolor.images.sld[1];b+=4){var k=document.createElement("div");k.style.height="4px";k.style.fontSize="1px";k.style.lineHeight="0";jscolor.picker.sld.appendChild(k)}jscolor.picker.sldB.appendChild(jscolor.picker.sld);jscolor.picker.box.appendChild(jscolor.picker.sldB); jscolor.picker.box.appendChild(jscolor.picker.sldM);jscolor.picker.padB.appendChild(jscolor.picker.pad);jscolor.picker.box.appendChild(jscolor.picker.padB);jscolor.picker.box.appendChild(jscolor.picker.padM);jscolor.picker.boxB.appendChild(jscolor.picker.box)}b=jscolor.picker;u=[a+f.pickerBorder+f.pickerFace+f.pickerInset,e+f.pickerBorder+f.pickerFace+f.pickerInset];H=[null,e+f.pickerBorder+f.pickerFace+f.pickerInset];b.box.onmouseup=b.box.onmouseout=function(){d.focus()};b.box.onmousedown=function(){s= true};b.box.onmousemove=function(i){v&&C(i);w&&D(i)};b.padM.onmouseup=b.padM.onmouseout=function(){if(v){v=false;jscolor.fireEvent(n,"change")}};b.padM.onmousedown=function(i){v=true;C(i)};b.sldM.onmouseup=b.sldM.onmouseout=function(){if(w){w=false;jscolor.fireEvent(n,"change")}};b.sldM.onmousedown=function(i){w=true;D(i)};b.box.style.width=4*f.pickerInset+2*f.pickerFace+jscolor.images.pad[0]+2*jscolor.images.arrow[0]+jscolor.images.sld[0]+"px";b.box.style.height=2*f.pickerInset+2*f.pickerFace+jscolor.images.pad[1]+ "px";b.boxB.style.position="absolute";b.boxB.style.clear="both";b.boxB.style.left=a+"px";b.boxB.style.top=e+"px";b.boxB.style.zIndex=f.pickerZIndex;b.boxB.style.border=f.pickerBorder+"px solid";b.boxB.style.borderColor=f.pickerBorderColor;b.boxB.style.background=f.pickerFaceColor;b.pad.style.width=jscolor.images.pad[0]+"px";b.pad.style.height=jscolor.images.pad[1]+"px";b.padB.style.position="absolute";b.padB.style.left=f.pickerFace+"px";b.padB.style.top=f.pickerFace+"px";b.padB.style.border=f.pickerInset+ "px solid";b.padB.style.borderColor=f.pickerInsetColor;b.padM.style.position="absolute";b.padM.style.left="0";b.padM.style.top="0";b.padM.style.width=f.pickerFace+2*f.pickerInset+jscolor.images.pad[0]+jscolor.images.arrow[0]+"px";b.padM.style.height=b.box.style.height;b.padM.style.cursor="crosshair";b.sld.style.overflow="hidden";b.sld.style.width=jscolor.images.sld[0]+"px";b.sld.style.height=jscolor.images.sld[1]+"px";b.sldB.style.position="absolute";b.sldB.style.right=f.pickerFace+"px";b.sldB.style.top= f.pickerFace+"px";b.sldB.style.border=f.pickerInset+"px solid";b.sldB.style.borderColor=f.pickerInsetColor;b.sldM.style.position="absolute";b.sldM.style.right="0";b.sldM.style.top="0";b.sldM.style.width=jscolor.images.sld[0]+jscolor.images.arrow[0]+f.pickerFace+2*f.pickerInset+"px";b.sldM.style.height=b.box.style.height;try{b.sldM.style.cursor="pointer"}catch(l){b.sldM.style.cursor="hand"}switch(r){case 0:var j="hs.png";break;case 1:j="hv.png";break}b.padM.style.background="url('"+jscolor.getDir()+ "cross.gif') no-repeat";b.sldM.style.background="url('"+jscolor.getDir()+"arrow.gif') no-repeat";b.pad.style.background="url('"+jscolor.getDir()+j+"') 0 0 no-repeat";E();F();jscolor.picker.owner=f;document.getElementsByTagName("body")[0].appendChild(b.boxB)}function E(){switch(r){case 0:var a=1;break;case 1:a=2;break}var e=Math.round(f.hsv[0]/6*(jscolor.images.pad[0]-1));a=Math.round((1-f.hsv[a])*(jscolor.images.pad[1]-1));jscolor.picker.padM.style.backgroundPosition=f.pickerFace+f.pickerInset+e- Math.floor(jscolor.images.cross[0]/2)+"px "+(f.pickerFace+f.pickerInset+a-Math.floor(jscolor.images.cross[1]/2))+"px";e=jscolor.picker.sld.childNodes;switch(r){case 0:var b=h(f.hsv[0],f.hsv[1],1);for(a=0;a<e.length;a+=1)e[a].style.backgroundColor="rgb("+b[0]*(1-a/e.length)*100+"%,"+b[1]*(1-a/e.length)*100+"%,"+b[2]*(1-a/e.length)*100+"%)";break;case 1:var k,l=[f.hsv[2],0,0];a=Math.floor(f.hsv[0]);var j=a%2?f.hsv[0]-a:1-(f.hsv[0]-a);switch(a){case 6:case 0:b=[0,1,2];break;case 1:b=[1,0,2];break;case 2:b= [2,0,1];break;case 3:b=[2,1,0];break;case 4:b=[1,2,0];break;case 5:b=[0,2,1];break}for(a=0;a<e.length;a+=1){k=1-1/(e.length-1)*a;l[1]=l[0]*(1-k*j);l[2]=l[0]*(1-k);e[a].style.backgroundColor="rgb("+l[b[0]]*100+"%,"+l[b[1]]*100+"%,"+l[b[2]]*100+"%)"}break}}function F(){switch(r){case 0:var a=2;break;case 1:a=1;break}a=Math.round((1-f.hsv[a])*(jscolor.images.sld[1]-1));jscolor.picker.sldM.style.backgroundPosition="0 "+(f.pickerFace+f.pickerInset+a-Math.floor(jscolor.images.arrow[1]/2))+"px"}function x(){return jscolor.picker&& jscolor.picker.owner===f}function I(){n===d&&f.importColor();f.pickerOnfocus&&f.hidePicker()}function J(){n!==d&&f.importColor()}function C(a){var e=jscolor.getMousePos(a);a=e[0]-u[0];e=e[1]-u[1];switch(r){case 0:f.fromHSV(a*(6/(jscolor.images.pad[0]-1)),1-e/(jscolor.images.pad[1]-1),null,y);break;case 1:f.fromHSV(a*(6/(jscolor.images.pad[0]-1)),null,1-e/(jscolor.images.pad[1]-1),y);break}}function D(a){a=jscolor.getMousePos(a)[1]-u[1];switch(r){case 0:f.fromHSV(null,null,1-a/(jscolor.images.sld[1]- 1),z);break;case 1:f.fromHSV(null,1-a/(jscolor.images.sld[1]-1),null,z);break}}this.adjust=this.required=true;this.hash=false;this.caps=true;this.styleElement=this.valueElement=d;this.hsv=[0,0,1];this.rgb=[1,1,1];this.pickerOnfocus=true;this.pickerMode="HSV";this.pickerPosition="bottom";this.pickerFace=10;this.pickerFaceColor="ThreeDFace";this.pickerBorder=1;this.pickerBorderColor="ThreeDHighlight ThreeDShadow ThreeDShadow ThreeDHighlight";this.pickerInset=1;this.pickerInsetColor="ThreeDShadow ThreeDHighlight ThreeDHighlight ThreeDShadow"; this.pickerZIndex=1E4;for(var A in g)if(g.hasOwnProperty(A))this[A]=g[A];this.hidePicker=function(){x()&&m()};this.showPicker=function(){if(!x()){var a=jscolor.getElementPos(d),e=jscolor.getElementSize(d),b=jscolor.getViewPos(),k=jscolor.getViewSize(),l=[2*this.pickerBorder+4*this.pickerInset+2*this.pickerFace+jscolor.images.pad[0]+2*jscolor.images.arrow[0]+jscolor.images.sld[0],2*this.pickerBorder+2*this.pickerInset+2*this.pickerFace+jscolor.images.pad[1]],j,i,q;switch(this.pickerPosition.toLowerCase()){case "left":j= 1;i=0;q=-1;break;case "right":j=1;i=0;q=1;break;case "top":j=0;i=1;q=-1;break;default:j=0;q=i=1;break}var p=(e[i]+l[i])/2;a=[-b[j]+a[j]+l[j]>k[j]?-b[j]+a[j]+e[j]/2>k[j]/2&&a[j]+e[j]-l[j]>=0?a[j]+e[j]-l[j]:a[j]:a[j],-b[i]+a[i]+e[i]+l[i]-p+p*q>k[i]?-b[i]+a[i]+e[i]/2>k[i]/2&&a[i]+e[i]-p-p*q>=0?a[i]+e[i]-p-p*q:a[i]+e[i]-p+p*q:a[i]+e[i]-p+p*q>=0?a[i]+e[i]-p+p*q:a[i]+e[i]-p-p*q];G(a[j],a[i])}};this.importColor=function(){if(n)if(this.adjust)if(!this.required&&/^\s*$/.test(n.value)){n.value="";o.style.backgroundColor= o.jscStyle.backgroundColor;o.style.color=o.jscStyle.color;this.exportColor(t|B)}else this.fromString(n.value)||this.exportColor();else{if(!this.fromString(n.value,t)){o.style.backgroundColor=o.jscStyle.backgroundColor;o.style.color=o.jscStyle.color;this.exportColor(t|B)}}else this.exportColor()};this.exportColor=function(a){if(!(a&t)&&n){var e=this.toString();if(this.caps)e=e.toUpperCase();if(this.hash)e="#"+e;n.value=e}if(!(a&B)&&o){o.style.backgroundColor="#"+this.toString();o.style.color=0.213* this.rgb[0]+0.715*this.rgb[1]+0.072*this.rgb[2]<0.5?"#FFF":"#000"}!(a&z)&&x()&&E();!(a&y)&&x()&&F()};this.fromHSV=function(a,e,b,k){a<0&&(a=0)||a>6&&(a=6);e<0&&(e=0)||e>1&&(e=1);b<0&&(b=0)||b>1&&(b=1);this.rgb=h(a===null?this.hsv[0]:(this.hsv[0]=a),e===null?this.hsv[1]:(this.hsv[1]=e),b===null?this.hsv[2]:(this.hsv[2]=b));this.exportColor(k)};this.fromRGB=function(a,e,b,k){a<0&&(a=0)||a>1&&(a=1);e<0&&(e=0)||e>1&&(e=1);b<0&&(b=0)||b>1&&(b=1);a=c(a===null?this.rgb[0]:(this.rgb[0]=a),e===null?this.rgb[1]: (this.rgb[1]=e),b===null?this.rgb[2]:(this.rgb[2]=b));if(a[0]!==null)this.hsv[0]=a[0];if(a[2]!==0)this.hsv[1]=a[1];this.hsv[2]=a[2];this.exportColor(k)};this.fromString=function(a,e){if(a=a.match(/^\W*([0-9A-F]{3}([0-9A-F]{3})?)\W*$/i)){a[1].length===6?this.fromRGB(parseInt(a[1].substr(0,2),16)/255,parseInt(a[1].substr(2,2),16)/255,parseInt(a[1].substr(4,2),16)/255,e):this.fromRGB(parseInt(a[1].charAt(0)+a[1].charAt(0),16)/255,parseInt(a[1].charAt(1)+a[1].charAt(1),16)/255,parseInt(a[1].charAt(2)+ a[1].charAt(2),16)/255,e);return true}else return false};this.toString=function(){return(256|Math.round(255*this.rgb[0])).toString(16).substr(1)+(256|Math.round(255*this.rgb[1])).toString(16).substr(1)+(256|Math.round(255*this.rgb[2])).toString(16).substr(1)};var f=this,r=this.pickerMode.toLowerCase()==="hvs"?1:0,s=false,n=jscolor.fetchElement(this.valueElement),o=jscolor.fetchElement(this.styleElement),v=false,w=false,u,H,t=1,B=2,z=4,y=8;jscolor.addEvent(d,"focus",function(){f.pickerOnfocus&&f.showPicker()}); jscolor.addEvent(d,"blur",function(){if(s)s=false;else window.setTimeout(function(){s||I();s=false},0)});if(n){g=function(){f.fromString(n.value,t)};jscolor.addEvent(n,"keyup",g);jscolor.addEvent(n,"input",g);jscolor.addEvent(n,"blur",J);n.setAttribute("autocomplete","off")}if(o)o.jscStyle={backgroundColor:o.style.backgroundColor,color:o.style.color};switch(r){case 0:jscolor.requireImage("hs.png");break;case 1:jscolor.requireImage("hv.png");break}jscolor.requireImage("cross.gif");jscolor.requireImage("arrow.gif"); this.importColor()}};jscolor.install();