/*!
* Cornerz 0.6 - Bullet Proof Corners
* Jonah Fox (jonah@parkerfox.co.uk) 2008
* 
* Usage: $('.myclass').curve(options)
* options is a hash with the following parameters. Bracketed is the default
*   radius (10)
*   borderWidth (read from BorderTopWidth or 0)
*   background ("white"). Note that this is not calculated from the HTML as it is expensive
*   borderColor (read from BorderTopColor)
*   corners ("tl br tr bl"). Specify which borders
*   fixIE ("padding") - attmepts to fix IE by incrementing the property by 1 if the outer width/height is odd.

CHANGELIST from  v0.4

0.5 - Now attempts to fix the odd dimension problem in IE 
0.6 - Added semicolons for packing and fixed a problem with odd border width's in IE

*/
(function(a){a.browser.msie&&document.namespaces.v==null&&document.namespaces.add("v","urn:schemas-microsoft-com:vml","#default#VML");a.fn.cornerz=function(i){function f(o,n,c,e,p,q){var g,f,r,h,i,k,l,j=1.57,d="position:absolute;";if(o){g=-j;i=c;l=0;d+="top:-"+e+"px;"}else{g=j;i=0;l=c;d+="bottom:-"+e+"px;"}if(n){f=j*2;h=c;k=0;d+="left:-"+e+"px;"}else{f=0;h=0;k=c;d+="right:-"+e+"px;"}var m=a("<canvas width="+c+"px height="+c+"px style='"+d+"' ></canvas>"),b=m[0].getContext("2d");b.beginPath();b.lineWidth=e*2;b.arc(h,i,c,g,f,!(o^n));b.strokeStyle=p;b.stroke();b.lineWidth=0;b.lineTo(k,l);b.fillStyle=q;b.fill();return m}function e(c,h,g,d,e){var b=a("<div style='display: inherit' />");a.each(c.split(" "),function(){b.append(f(this[0]=="t",this[1]=="l",h,g,d,e))});return b}function d(b,f,g,a,d,e,c){var h=a-d-c,i=a-e;return"<v:arc filled='False' strokeweight='"+f+"px' strokecolor='"+g+"' startangle='0' endangle='361' style=' top:"+i+"px;left: "+h+"px;width:"+b+"px; height:"+b+"px' />"}function g(f,e,b,g,h){var c="<div style='text-align:left; '>";a.each(a.trim(f).split(" "),function(){var a,i=1,j=1,f=0;if(this.charAt(0)=="t")a="top:-"+b+"px;";else{a="bottom:-"+b+"px;";j=e+1}if(this.charAt(1)=="l")a+="left:-"+b+"px;";else{a+="right:-"+b+"px; ";i=e;f=1}c+="<div style='"+a+"; position: absolute; overflow:hidden; width:"+e+"px; height: "+e+"px;'>";c+="<v:group  style='width:1000px;height:1000px;position:absolute;' coordsize='1000,1000' >";c+=d(e*3,e+b,h,-e/2,i,j,f);if(b>0)c+=d(e*2-b,b,g,Math.floor(b/2+.5),i,j,f);c+="</v:group>";c+="</div>"});c+="</div>";return c}var b={corners:"tl tr bl br",radius:10,background:"white",borderWidth:0,fixIE:true};a.extend(b,i||{});var c=function(a,b,c){var d=parseInt(a.css(b),10)||0;a.css(b,c+d)};return this.each(function(){var d=a(this),l=b.radius*1,j=(b.borderWidth||parseInt(d.css("borderTopWidth"),10)||0)*1,i=b.background,f=b.borderColor;f=f||(j>0?d.css("borderTopColor"):i);var k=b.corners;if(a.browser.msie){h=g(k,l,j,f,i,a(this).width());this.insertAdjacentHTML("beforeEnd",h)}else d.append(e(k,l,j,f,i));if(this.style.position!="absolute")this.style.position="relative";this.style.zoom=1;if(a.browser.msie&&b.fixIE){var n=d.outerWidth(),m=d.outerHeight();if(n%2==1){c(d,"padding-right",1);c(d,"margin-right",1)}if(m%2==1){c(d,"padding-bottom",1);c(d,"margin-bottom",1)}}})}})(jQuery)
