jQuery.fn.farbtastic=function(A){$.farbtastic(this,A);return this};jQuery.farbtastic=function(B,A){var B=$(B).get(0);return B.farbtastic||(B.farbtastic=new jQuery._farbtastic(B,A))};jQuery._farbtastic=function(D,A){var C=this;$(D).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 B=$(".farbtastic",D);C.wheel=$(".wheel",D).get(0);C.radius=84;C.square=100;C.width=194;if(navigator.appVersion.match(/MSIE [0-6]\./)){$("*",B).each(function(){if(this.currentStyle.backgroundImage!="none"){var E=this.currentStyle.backgroundImage;E=this.currentStyle.backgroundImage.substring(5,E.length-2);$(this).css({"backgroundImage":"none","filter":"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+E+"')"})}})}C.linkTo=function(E){if(typeof C.callback=="object"){$(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=$(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(F){var E=C.unpack(F);if(C.color!=F&&E){C.color=F;C.rgb=E;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(H){var K,L;var I=H.target||H.srcElement;var G=C.wheel;if(typeof H.offsetX!="undefined"){var J={x:H.offsetX,y:H.offsetY};var E=I;while(E){E.mouseX=J.x;E.mouseY=J.y;J.x+=E.offsetLeft;J.y+=E.offsetTop;E=E.offsetParent}var E=G;var F={x:0,y:0};while(E){if(typeof E.mouseX!="undefined"){K=E.mouseX-F.x;L=E.mouseY-F.y;break}F.x+=E.offsetLeft;F.y+=E.offsetTop;E=E.offsetParent}E=I;while(E){E.mouseX=undefined;E.mouseY=undefined;E=E.offsetParent}}else{var J=C.absolutePosition(G);K=(H.pageX||0*(H.clientX+$("html").get(0).scrollLeft))-J.x;L=(H.pageY||0*(H.clientY+$("html").get(0).scrollTop))-J.y}return{x:K-C.width/2,y:L-C.width/2}};C.mousedown=function(F){if(!document.dragging){$(document).bind("mousemove",C.mousemove).bind("mouseup",C.mouseup);document.dragging=true}var E=C.widgetCoords(F);C.circleDrag=Math.max(Math.abs(E.x),Math.abs(E.y))*2>C.square;C.mousemove(F);return false};C.mousemove=function(H){var G=C.widgetCoords(H);if(C.circleDrag){var F=Math.atan2(G.x,-G.y)/6.28;if(F<0){F+=1}C.setHSL([F,C.hsl[1],C.hsl[2]])}else{var I=Math.max(0,Math.min(1,-(G.x/C.square)+0.5));var E=Math.max(0,Math.min(1,-(G.y/C.square)+0.5));C.setHSL([C.hsl[0],I,E])}return false};C.mouseup=function(){$(document).unbind("mousemove",C.mousemove);$(document).unbind("mouseup",C.mouseup);document.dragging=false};C.updateDisplay=function(){var E=C.hsl[0]*6.28;$(".h-marker",B).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"});$(".sl-marker",B).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"});$(".color",B).css("backgroundColor",C.pack(C.HSLToRGB([C.hsl[0],1,0.5])));if(typeof C.callback=="object"){$(C.callback).css({backgroundColor:C.color,color:C.hsl[2]>0.5?"#000":"#fff"});$(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(E){var F={x:E.offsetLeft,y:E.offsetTop};if(E.offsetParent){var G=C.absolutePosition(E.offsetParent);F.x+=G.x;F.y+=G.y}return F};C.pack=function(G){var F=Math.round(G[0]*255);var E=Math.round(G[1]*255);var H=Math.round(G[2]*255);return"#"+(F<16?"0":"")+F.toString(16)+(E<16?"0":"")+E.toString(16)+(H<16?"0":"")+H.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(L){var G,H,E,M,K;var I=L[0],F=L[1],J=L[2];H=(J<=0.5)?J*(F+1):J+F-J*F;G=J*2-H;return[this.hueToRGB(G,H,I+0.33333),this.hueToRGB(G,H,I),this.hueToRGB(G,H,I-0.33333)]};C.hueToRGB=function(F,G,E){E=(E<0)?E+1:((E>1)?E-1:E);if(E*6<1){return F+(G-F)*E*6}if(E*2<1){return G}if(E*3<2){return F+(G-F)*(0.66666-E)*6}return F};C.RGBToHSL=function(G){var H,I,M,J,F,K;var E=G[0],N=G[1],L=G[2];H=Math.min(E,Math.min(N,L));I=Math.max(E,Math.max(N,L));M=I-H;K=(H+I)/2;F=0;if(K>0&&K<1){F=M/(K<0.5?(2*K):(2-2*K))}J=0;if(M>0){if(I==E&&I!=N){J+=(N-L)/M}if(I==N&&I!=L){J+=(2+(L-E)/M)}if(I==L&&I!=E){J+=(4+(E-N)/M)}J/=6}return[J,F,K]};$("*",B).mousedown(C.mousedown);C.setColor("#000000");if(A){C.linkTo(A)}};