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