 /****************************************************************  *                                                              *  *  JQuery Curvy Corners by Mike Jolley                         *  *	 http://blue-anvil.com                                       *  *  ------------                                                *  *  Version 1.81                                                 *  *                                                              *  *  Origionaly by: Cameron Cooke and Tim Hutchison.             *  *  Website: http://www.curvycorners.net                        *  *                                                              *  *  This library is free software; you can redistribute         *  *  it and/or modify it under the terms of the GNU              *  *  Lesser General Public License as published by the           *  *  Free Software Foundation; either version 2.1 of the         *  *  License, or (at your option) any later version.             *  *                                                              *  *  This library is distributed in the hope that it will        *  *  be useful, but WITHOUT ANY WARRANTY; without even the       *  *  implied warranty of MERCHANTABILITY or FITNESS FOR A        *  *  PARTICULAR PURPOSE. See the GNU Lesser General Public       *  *  License for more details.                                   *  *                                                              *  *  You should have received a copy of the GNU Lesser           *  *  General Public License along with this library;             *  *  Inc., 59 Temple Place, Suite 330, Boston,                   *  *  MA 02111-1307 USA                                           *  *                                                              *  ****************************************************************/(function($){$.fn.corner=function(Z){function BlendColour(a,b,c){var d=parseInt(a.substr(1,2),16);var e=parseInt(a.substr(3,2),16);var f=parseInt(a.substr(5,2),16);var g=parseInt(b.substr(1,2),16);var h=parseInt(b.substr(3,2),16);var i=parseInt(b.substr(5,2),16);if(c>1||c<0)c=1;var j=Math.round((d*c)+(g*(1-c)));if(j>255)j=255;if(j<0)j=0;var k=Math.round((e*c)+(h*(1-c)));if(k>255)k=255;if(k<0)k=0;var l=Math.round((f*c)+(i*(1-c)));if(l>255)l=255;if(l<0)l=0;return"#"+IntToHex(j)+IntToHex(k)+IntToHex(l)}function IntToHex(a){base=a/16;rem=a%16;base=base-(rem/16);baseS=MakeHex(base);remS=MakeHex(rem);return baseS+''+remS}function MakeHex(x){if((x>=0)&&(x<=9)){return x}else{switch(x){case 10:return"A";case 11:return"B";case 12:return"C";case 13:return"D";case 14:return"E";case 15:return"F"};return"F"}}function pixelFraction(x,y,r){var a=0;var b=new Array(1);var c=new Array(1);var d=0;var e="";var f=Math.sqrt((Math.pow(r,2)-Math.pow(x,2)));if((f>=y)&&(f<(y+1))){e="Left";b[d]=0;c[d]=f-y;d=d+1};var f=Math.sqrt((Math.pow(r,2)-Math.pow(y+1,2)));if((f>=x)&&(f<(x+1))){e=e+"Top";b[d]=f-x;c[d]=1;d=d+1};var f=Math.sqrt((Math.pow(r,2)-Math.pow(x+1,2)));if((f>=y)&&(f<(y+1))){e=e+"Right";b[d]=1;c[d]=f-y;d=d+1};var f=Math.sqrt((Math.pow(r,2)-Math.pow(y,2)));if((f>=x)&&(f<(x+1))){e=e+"Bottom";b[d]=f-x;c[d]=0};switch(e){case"LeftRight":a=Math.min(c[0],c[1])+((Math.max(c[0],c[1])-Math.min(c[0],c[1]))/2);break;case"TopRight":a=1-(((1-b[0])*(1-c[1]))/2);break;case"TopBottom":a=Math.min(b[0],b[1])+((Math.max(b[0],b[1])-Math.min(b[0],b[1]))/2);break;case"LeftBottom":a=(c[0]*b[1])/2;break;default:a=1};return a}function rgb2Hex(a){try{var b=rgb2Array(a);var c=parseInt(b[0]);var d=parseInt(b[1]);var f=parseInt(b[2]);var g="#"+IntToHex(c)+IntToHex(d)+IntToHex(f)}catch(e){alert("There was an error converting the RGB value to Hexadecimal in function rgb2Hex")};return g}function rgb2Array(a){var b=a.substring(4,a.indexOf(")"));var c=b.split(", ");return c}function format_colour(a){var b="transparent";if(a!=""&&a!="transparent"){if(a.substr(0,3)=="rgb"){b=rgb2Hex(a)}else if(a.length==4){b="#"+a.substring(1,2)+a.substring(1,2)+a.substring(2,3)+a.substring(2,3)+a.substring(3,4)+a.substring(3,4)}else{b=a}};return b};function strip_px(a){return parseInt(((a!="auto"&&a.indexOf("%")==-1&&a!=""&&a.indexOf("px")!==-1)?a.slice(0,a.indexOf("px")):0))}function drawPixel(a,b,c,d,e,f,g,h,i,j,k,l,m,n){var o=$(a);var p=document.createElement("div");$(p).css({height:f,width:"1px",position:"absolute","font-size":"1px",overflow:"hidden"});var q=Math.max(n.tl?n.tl.radius:0,n.tr?n.tr.radius:0);if(h==-1&&i!=""){if(q>0)$(p).css("background-position","-"+((m-j-l)+b)+"px -"+((o.height()+q-l)-c)+"px");else $(p).css("background-position","-"+((m-j-l)+b)+"px -"+((o.height())-c)+"px");$(p).css({"background-image":i,"background-repeat":o.css("background-repeat"),"background-color":d})}else{if(!k)$(p).css("background-color",d).addClass('hasBackgroundColor');else $(p).css("background-color",d)};if(e!=100)setOpacity(p,e);$(p).css({top:c+"px",left:b+"px"});return p};function setOpacity(a,b){b=(b==100)?99.999:b;if($.browser.safari&&a.tagName!="IFRAME"){var c=rgb2Array(a.style.backgroundColor);var d=parseInt(c[0]);var e=parseInt(c[1]);var f=parseInt(c[2]);a.style.backgroundColor="rgba("+d+", "+e+", "+f+", "+b/100+")"}else if(typeof(a.style.opacity)!="undefined"){a.style.opacity=b/100}else if(typeof(a.style.MozOpacity)!="undefined"){a.style.MozOpacity=b/100}else if(typeof(a.style.filter)!="undefined"){a.style.filter="alpha(opacity:"+b+")"}else if(typeof(a.style.KHTMLOpacity)!="undefined"){a.style.KHTMLOpacity=b/100}}function applyCorners(a,b){var c=$(a);var d=c.css("backgroundImage");var e=null;var f=null;var g=new Array();var h=null;var l=strip_px(c.css("height"))?strip_px(c.css("height")):a.scrollHeight;var m=strip_px(c.css("width"))?strip_px(c.css("width")):a.scrollWidth;var n=strip_px(c.css("borderTopWidth"))?strip_px(c.css("borderTopWidth")):0;var o=strip_px(c.css("paddingTop"));var p=strip_px(c.css("paddingBottom"));var q=strip_px(c.css("paddingLeft"));var r=strip_px(c.css("paddingRight"));var s=format_colour(c.css("backgroundColor"));var u=(d!="none"&&d!="initial")?d:"";var v=format_colour(c.css("borderTopColor"));var w=n+"px"+" solid "+v;var x=Math.max(b.tl?b.tl.radius:0,b.tr?b.tr.radius:0);var y=Math.max(b.bl?b.bl.radius:0,b.br?b.br.radius:0);c.addClass('hasCorners').css({"padding":"0","borderColor":a.style.borderColour,'overflow':'visible'});if(a.style.position!="absolute")c.css("position","relative");if(($.browser.msie)){if($.browser.version==6&&a.style.width=="auto"&&a.style.height=="auto")c.css("width","100%");c.css("zoom","1");$(c+" *").css("zoom","normal")}for(var t=0;t<2;t++){switch(t){case 0:if(b.tl||b.tr){var A=document.createElement("div");e=a.appendChild(A);$(e).css({width:"100%","font-size":"1px",overflow:"hidden",position:"absolute","padding-left":n,"padding-right":n,height:x+"px",top:0-x+"px",left:0-n+"px"}).addClass('topContainer')};break;case 1:if(b.bl||b.br){var A=document.createElement("div");f=a.appendChild(A);$(f).css({width:"100%","font-size":"1px",overflow:"hidden",position:"absolute","padding-left":n,"padding-right":n,height:y,bottom:0-y+"px",left:0-n+"px"}).addClass('bottomContainer')};break}};if(b.autoPad==true){var B=document.createElement("div");var C=document.createElement("div");var D=document.createElement("div");$(C).css({margin:"0","padding-bottom":p,"padding-top":o,"padding-left":q,"padding-right":r,'overflow':'visible'}).addClass('hasBackgroundColor content_container');$(B).css({position:"relative",'float':"left",width:"100%","margin-top":"-"+(x-n)+"px","margin-bottom":"-"+(y-n)+"px"}).addClass="autoPadDiv";$(D).css("clear","both");C.appendChild(B);C.appendChild(D);c.wrapInner(C)};if(e)c.css("border-top",0);if(f)c.css("border-bottom",0);var E=["tr","tl","br","bl"];for(var i in E){if(i>-1<4){var F=E[i];if(!b[F]){if(((F=="tr"||F=="tl")&&e!=null)||((F=="br"||F=="bl")&&f!=null)){var G=document.createElement("div");$(G).css({position:"relative","font-size":"1px",overflow:"hidden"});if(u=="")$(G).css("background-color",s);else $(G).css("background-image",u).css("background-color",s);switch(F){case"tl":$(G).css({height:x-n,"margin-right":b.tr.radius-(n*2),"border-left":w,"border-top":w,left:-n+"px","background-repeat":c.css("background-repeat"),"background-position":n+"px 0px"});break;case"tr":$(G).css({height:x-n,"margin-left":b.tl.radius-(n*2),"border-right":w,"border-top":w,left:n+"px","background-repeat":c.css("background-repeat"),"background-position":"-"+(x+n)+"px 0px"});break;case"bl":if(x>0)$(G).css({height:y-n,"margin-right":b.br.radius-(n*2),"border-left":w,"border-bottom":w,left:-n+"px","background-repeat":c.css("background-repeat"),"background-position":"0px -"+(c.height()+x-n+1)+"px"});else $(G).css({height:y-n,"margin-right":b.br.radius-(n*2),"border-left":w,"border-bottom":w,left:-n+"px","background-repeat":c.css("background-repeat"),"background-position":"0px -"+(c.height())+"px"});break;case"br":if(x>0)$(G).css({height:y-n,"margin-left":b.bl.radius-(n*2),"border-right":w,"border-bottom":w,left:n+"px","background-repeat":c.css("background-repeat"),"background-position":"-"+b.bl.radius+n+"px -"+(c.height()+x-n+1)+"px"});else $(G).css({height:y-n,"margin-left":b.bl.radius-(n*2),"border-right":w,"border-bottom":w,left:n+"px","background-repeat":c.css("background-repeat"),"background-position":"-"+b.bl.radius+n+"px -"+(c.height())+"px"});break}}}else{if(g[b[F].radius]){var G=g[b[F].radius].cloneNode(true)}else{var G=document.createElement("DIV");$(G).css({height:b[F].radius,width:b[F].radius,position:"absolute","font-size":"1px",overflow:"hidden"});var H=parseInt(b[F].radius-n);for(var I=0,j=b[F].radius;I<j;I++){if((I+1)>=H)var J=-1;else var J=(Math.floor(Math.sqrt(Math.pow(H,2)-Math.pow((I+1),2)))-1);if(H!=j){if((I)>=H)var K=-1;else var K=Math.ceil(Math.sqrt(Math.pow(H,2)-Math.pow(I,2)));if((I+1)>=j)var L=-1;else var L=(Math.floor(Math.sqrt(Math.pow(j,2)-Math.pow((I+1),2)))-1)};if((I)>=j)var M=-1;else var M=Math.ceil(Math.sqrt(Math.pow(j,2)-Math.pow(I,2)));if(J>-1)G.appendChild(drawPixel(a,I,0,s,100,(J+1),G,-1,u,b[F].radius,0,n,m,b));if(H!=j){for(var N=(J+1);N<K;N++){if(b.antiAlias){if(u!=""){var O=(pixelFraction(I,N,H)*100);if(O<30){G.appendChild(drawPixel(a,I,N,v,100,1,G,0,u,b[F].radius,1,n,m,b))}else{G.appendChild(drawPixel(a,I,N,v,100,1,G,-1,u,b[F].radius,1,n,m,b))}}else{var P=BlendColour(s,v,pixelFraction(I,N,H));G.appendChild(drawPixel(a,I,N,P,100,1,G,0,u,b[F].radius,F,1,n,m,b))}}};if(b.antiAlias){if(L>=K){if(K==-1)K=0;G.appendChild(drawPixel(a,I,K,v,100,(L-K+1),G,0,u,0,1,n,m,b))}}else{if(L>=J){G.appendChild(drawPixel(a,I,(J+1),v,100,(L-J),G,0,u,0,1,n,m,b))}};var Q=v}else{var Q=s;var L=J};if(b.antiAlias){for(var N=(L+1);N<M;N++){G.appendChild(drawPixel(a,I,N,Q,(pixelFraction(I,N,j)*100),1,G,((n>0)?0:-1),u,b[F].radius,1,n,m,b))}}};g[b[F].radius]=G.cloneNode(true)};if(F!="br"){for(var t=0,k=G.childNodes.length;t<k;t++){var R=G.childNodes[t];var S=strip_px($(R).css("top"));var T=strip_px($(R).css("left"));var U=strip_px($(R).css("height"));if(F=="tl"||F=="bl"){$(R).css("left",b[F].radius-T-1+"px")};if(F=="tr"||F=="tl"){$(R).css("top",b[F].radius-U-S+"px")};switch(F){case"tr":$(R).css("background-position","-"+Math.abs((m-b[F].radius+n)+T)+"px -"+Math.abs(b[F].radius-U-S-n)+"px");break;case"tl":$(R).css("background-position","-"+Math.abs((b[F].radius-T-1)-n)+"px -"+Math.abs(b[F].radius-U-S-n)+"px");break;case"bl":if(x>0)$(R).css("background-position","-"+Math.abs((b[F].radius-T-1)-n)+"px -"+Math.abs((c.height()+x-n+1))+"px");else $(R).css("background-position","-"+Math.abs((b[F].radius-T-1)-n)+"px -"+Math.abs((c.height()))+"px");break}}}};if(G){switch(F){case"tl":if($(G).css("position")=="absolute")$(G).css("top","0");if($(G).css("position")=="absolute")$(G).css("left","0");if(e)e.appendChild(G);break;case"tr":if($(G).css("position")=="absolute")$(G).css("top","0");if($(G).css("position")=="absolute")$(G).css("right","0");if(e)e.appendChild(G);break;case"bl":if($(G).css("position")=="absolute")$(G).css("bottom","0");if(G.style.position=="absolute")$(G).css("left","0");if(f)f.appendChild(G);break;case"br":if($(G).css("position")=="absolute")$(G).css("bottom","0");if($(G).css("position")=="absolute")$(G).css("right","0");if(f)f.appendChild(G);break}}}};var V=new Array();V["t"]=Math.abs(b.tl.radius-b.tr.radius);V["b"]=Math.abs(b.bl.radius-b.br.radius);for(z in V){if(z=="t"||z=="b"){if(V[z]){var W=((b[z+"l"].radius<b[z+"r"].radius)?z+"l":z+"r");var X=document.createElement("div");$(X).css({height:V[z],width:b[W].radius+"px",position:"absolute","font-size":"1px",overflow:"hidden","background-color":s,"background-image":u});switch(W){case"tl":$(X).css({"bottom":"0","left":"0","border-left":w,"background-position":"0px -"+(b[W].radius-n)});e.appendChild(X);break;case"tr":$(X).css({"bottom":"0","right":"0","border-right":w,"background-position":"0px -"+(b[W].radius-n)+"px"});e.appendChild(X);break;case"bl":$(X).css({"top":"0","left":"0","border-left":w,"background-position":"0px -"+(c.height()+b[W].radius-n)});f.appendChild(X);break;case"br":$(X).css({"top":"0","right":"0","border-right":w,"background-position":"0px -"+(c.height()+b[W].radius-n)});f.appendChild(X);break}};var Y=document.createElement("div");$(Y).css({position:"relative","font-size":"1px",overflow:"hidden","background-color":s,"background-image":u,"background-repeat":c.css("background-repeat")});switch(z){case"t":if(e){if(b.tl.radius&&b.tr.radius){$(Y).css({height:x-n+"px","margin-left":b.tl.radius-n+"px","margin-right":b.tr.radius-n+"px","border-top":w}).addClass('hasBackgroundColor');if(u!="")$(Y).css("background-position","-"+(x+n)+"px 0px");e.appendChild(Y)};c.css("background-position","0px -"+(x-n+1)+"px")};break;case"b":if(f){if(b.bl.radius&&b.br.radius){$(Y).css({height:y-n+"px","margin-left":b.bl.radius-n+"px","margin-right":b.br.radius-n+"px","border-bottom":w});if(u!=""&&x>0)$(Y).css("background-position","-"+(b.bl.radius-n)+"px -"+(c.height()+x-n+1)+"px");else $(Y).css("background-position","-"+(b.bl.radius-n)+"px -"+(c.height())+"px").addClass('hasBackgroundColor');f.appendChild(Y)}};break}}};c.prepend(e);c.prepend(f)}var bb={tl:{radius:8},tr:{radius:8},bl:{radius:8},br:{radius:8},antiAlias:true,autoPad:true,validTags:["div"]};if(Z&&typeof(Z)!='string')$.extend(bb,Z);return this.each(function(){if(!$(this).is('.hasCorners')){applyCorners(this,bb)}})}})(jQuery);
