(function(a){jQuery.fn.farbtastic=function(b){a.farbtastic(this,b);return this};jQuery.farbtastic=function(b,c){var b=a(b).get(0);return b.farbtastic||(b.farbtastic=new jQuery._farbtastic(b,c))};jQuery._farbtastic=function(b,f){var c=this;a(b).html('<div class="farbtastic"><div class="color"></div><div class="wheel"></div><div class="overlay"></div><div class="h-marker marker"></div><div class="sl-marker marker"></div></div>');var d=a(".farbtastic",b);c.wheel=a(".wheel",b).get(0);c.radius=84;c.square=100;c.width=194;if(navigator.appVersion.match(/MSIE [0-6]\./)){a("*",d).each(function(){if(this.currentStyle.backgroundImage!="none"){var e=this.currentStyle.backgroundImage;e=this.currentStyle.backgroundImage.substring(5,e.length-2);a(this).css({backgroundImage:"none",filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+e+"')"})}})}c.linkTo=function(e){if(typeof c.callback=="object"){a(c.callback).unbind("keyup",c.updateValue)}c.color=null;if(typeof e=="function"){c.callback=e}else{if(typeof e=="object"||typeof e=="string"){c.callback=a(e);c.callback.bind("keyup",c.updateValue);if(c.callback.get(0).value){c.setColor(c.callback.get(0).value)}}}return this};c.updateValue=function(e){if(this.value&&this.value!=c.color){c.setColor(this.value)}};c.setColor=function(e){var g=c.unpack(e);if(c.color!=e&&g){c.color=e;c.rgb=g;c.hsl=c.RGBToHSL(c.rgb);c.updateDisplay()}return this};c.setHSL=function(e){c.hsl=e;c.rgb=c.HSLToRGB(e);c.color=c.pack(c.rgb);c.updateDisplay();return this};c.widgetCoords=function(j){var h,n;var i=j.target||j.srcElement;var g=c.wheel;if(typeof j.offsetX!="undefined"){var m={x:j.offsetX,y:j.offsetY};var k=i;while(k){k.mouseX=m.x;k.mouseY=m.y;m.x+=k.offsetLeft;m.y+=k.offsetTop;k=k.offsetParent}var k=g;var l={x:0,y:0};while(k){if(typeof k.mouseX!="undefined"){h=k.mouseX-l.x;n=k.mouseY-l.y;break}l.x+=k.offsetLeft;l.y+=k.offsetTop;k=k.offsetParent}k=i;while(k){k.mouseX=undefined;k.mouseY=undefined;k=k.offsetParent}}else{var m=c.absolutePosition(g);h=(j.pageX||0*(j.clientX+a("html").get(0).scrollLeft))-m.x;n=(j.pageY||0*(j.clientY+a("html").get(0).scrollTop))-m.y}return{x:h-c.width/2,y:n-c.width/2}};c.mousedown=function(e){if(!document.dragging){a(document).bind("mousemove",c.mousemove).bind("mouseup",c.mouseup);document.dragging=true}var g=c.widgetCoords(e);c.circleDrag=Math.max(Math.abs(g.x),Math.abs(g.y))*2>c.square;c.mousemove(e);return false};c.mousemove=function(i){var j=c.widgetCoords(i);if(c.circleDrag){var h=Math.atan2(j.x,-j.y)/6.28;if(h<0){h+=1}c.setHSL([h,c.hsl[1],c.hsl[2]])}else{var g=Math.max(0,Math.min(1,-(j.x/c.square)+0.5));var e=Math.max(0,Math.min(1,-(j.y/c.square)+0.5));c.setHSL([c.hsl[0],g,e])}return false};c.mouseup=function(){a(document).unbind("mousemove",c.mousemove);a(document).unbind("mouseup",c.mouseup);document.dragging=false};c.updateDisplay=function(){var e=c.hsl[0]*6.28;a(".h-marker",d).css({left:Math.round(Math.sin(e)*c.radius+c.width/2)+"px",top:Math.round(-Math.cos(e)*c.radius+c.width/2)+"px"});a(".sl-marker",d).css({left:Math.round(c.square*(0.5-c.hsl[1])+c.width/2)+"px",top:Math.round(c.square*(0.5-c.hsl[2])+c.width/2)+"px"});a(".color",d).css("backgroundColor",c.pack(c.HSLToRGB([c.hsl[0],1,0.5])));if(typeof c.callback=="object"){a(c.callback).css({backgroundColor:c.color,color:c.hsl[2]>0.5?"#000":"#fff"});a(c.callback).each(function(){if(this.value&&this.value!=c.color){this.value=c.color}})}else{if(typeof c.callback=="function"){c.callback.call(c,c.color)}}};c.absolutePosition=function(g){var h={x:g.offsetLeft,y:g.offsetTop};if(g.offsetParent){var e=c.absolutePosition(g.offsetParent);h.x+=e.x;h.y+=e.y}return h};c.pack=function(h){var j=Math.round(h[0]*255);var i=Math.round(h[1]*255);var e=Math.round(h[2]*255);return"#"+(j<16?"0":"")+j.toString(16)+(i<16?"0":"")+i.toString(16)+(e<16?"0":"")+e.toString(16)};c.unpack=function(e){if(e.length==7){return[parseInt("0x"+e.substring(1,3))/255,parseInt("0x"+e.substring(3,5))/255,parseInt("0x"+e.substring(5,7))/255]}else{if(e.length==4){return[parseInt("0x"+e.substring(1,2))/15,parseInt("0x"+e.substring(2,3))/15,parseInt("0x"+e.substring(3,4))/15]}}};c.HSLToRGB=function(n){var p,o,e,k,m;var j=n[0],q=n[1],i=n[2];o=(i<=0.5)?i*(q+1):i+q-i*q;p=i*2-o;return[this.hueToRGB(p,o,j+0.33333),this.hueToRGB(p,o,j),this.hueToRGB(p,o,j-0.33333)]};c.hueToRGB=function(g,e,i){i=(i<0)?i+1:((i>1)?i-1:i);if(i*6<1){return g+(e-g)*i*6}if(i*2<1){return e}if(i*3<2){return g+(e-g)*(0.66666-i)*6}return g};c.RGBToHSL=function(n){var j,p,q,k,t,i;var e=n[0],m=n[1],o=n[2];j=Math.min(e,Math.min(m,o));p=Math.max(e,Math.max(m,o));q=p-j;i=(j+p)/2;t=0;if(i>0&&i<1){t=q/(i<0.5?(2*i):(2-2*i))}k=0;if(q>0){if(p==e&&p!=m){k+=(m-o)/q}if(p==m&&p!=o){k+=(2+(o-e)/q)}if(p==o&&p!=e){k+=(4+(e-m)/q)}k/=6}return[k,t,i]};a("*",d).mousedown(c.mousedown);c.setColor("#000000");if(f){c.linkTo(f)}}})(jQuery);