/*
 * SVG_roundies dynamically creates SVG graphics to make boxes look like as if they have rounded corners.
 * Adapted from DD_roundies: http://dillerdesign.com/experiment/DD_roundies/
 *
 * Author: Boris Schaeling
 * Email: boris@highscore.de
 * URL: http://www.highscore.de/SVG_roundies/
 * Version: 0.0.2a
 *
 * Licensed under the MIT License: http://www.highscore.de/SVG_roundies/#license
 * Copyright (c) 2008-2009 Drew Diller, Boris Schaeling
 *
 * Usage:
 * SVG_roundies.addRule('p', '10px 5px'); // tag name and multiple radii
 */
var SVG_roundies={ns:"SVG_roundies",imgSize:{},querySelectorAll:function(a){return document.getElementsByTagName(a)},addRule:function(b,a){if(typeof a=="undefined"||a===null){a=0}if(a.constructor.toString().search("Array")==-1){a=a.toString().replace(/[^0-9 ]/g,"").split(" ")}for(var f=0;f<4;f++){a[f]=(!a[f]&&a[f]!==0)?a[Math.max((f-2),0)]:a[f]}var e=b.split(",");for(var f=0;f<e.length;f++){var d=this.querySelectorAll(b);for(var c=0;c<d.length;c++){this.roundify(d[c],a)}}},runtimeStyle:function(b){var a=document.defaultView.getComputedStyle(b,null);if(b.SVG_roundies.v===undefined){b.SVG_roundies.v={}}if(b.SVG_roundies.v.bgColor===undefined||b.SVG_roundies.v.bgColor!=a.getPropertyValue("background-color")){b.SVG_roundies.v.bgColor=a.getPropertyValue("background-color")}if(b.SVG_roundies.v.bgImage===undefined||b.SVG_roundies.v.bgImage!=a.getPropertyValue("background-image")){b.SVG_roundies.v.bgImage=a.getPropertyValue("background-image")}if(b.SVG_roundies.v.borderColor===undefined||b.SVG_roundies.v.borderColor!=a.getPropertyValue("border-left-color")){b.SVG_roundies.v.borderColor=a.getPropertyValue("border-left-color")}},readPropertyChanges:function(a){if(a.currentTarget==a.target&&a.attrName=="style"){var b=a.target;this.runtimeStyle(b);b.SVG_roundies.svg.style.setProperty("z-index",b.style.getPropertyValue("z-index"),null);this.applySVG(b)}},applySVG:function(a){this.removeEventListeners(a);this.svgFill(a);this.svgStrokeColor(a);this.svgStrokeWeight(a);this.svgOffsets(a);this.svgPath(a);this.svgOpacity(a);this.addEventListeners(a)},svgOpacity:function(b){var a=document.defaultView.getComputedStyle(b,null);b.SVG_roundies.svg.setAttribute("opacity",a.getPropertyValue("opacity"))},svgFill:function(d){d.style.setProperty("background-color","transparent",null);if(d.SVG_roundies.v.bgImage!="none"||d.SVG_roundies.isImg){var e=function(l,i,h){var g=document.createElementNS("http://www.w3.org/2000/svg","defs");var j=document.createElementNS("http://www.w3.org/2000/svg","pattern");j.setAttribute("patternUnits","userSpaceOnUse");j.setAttribute("width",h.offsetWidth+"px");j.setAttribute("height",h.offsetHeight+"px");var m=l.ns+"_"+h.getAttribute("src").replace(/\W/g,"");j.setAttribute("id",m);i.SVG_roundies.paths.color.setAttribute("fill","url(#"+m+")");var k=document.createElementNS("http://www.w3.org/2000/svg","image");k.setAttributeNS("http://www.w3.org/1999/xlink","href",h.getAttribute("src"));k.setAttribute("width",h.offsetWidth+"px");k.setAttribute("height",h.offsetHeight+"px");j.appendChild(k);g.appendChild(j);i.SVG_roundies.svg.appendChild(g)};var f=this;if(d.SVG_roundies.isImg){e(f,d,d)}else{var c;d.style.setProperty("background-image","none",null);var b=d.SVG_roundies.v.bgImage;c=b.substring(4,b.length-1);if(c[0]=='"'||c[0]=="'"){c=c.substring(1,c.length-1)}if(this.imgSize[c]===undefined){var a=document.createElement("img");a.addEventListener("load",function(){e(f,d,a)},false);a.style.setProperty("position","absolute",null);a.style.setProperty("top","-10000px",null);a.style.setProperty("left","-10000px",null);a.setAttribute("src",c);document.body.insertBefore(a,document.body.firstChild);this.imgSize[c]=a}else{e(f,d,this.imgSize[c])}}}else{d.SVG_roundies.paths.color.setAttribute("fill",(d.SVG_roundies.v.bgColor=="transparent")?"none":d.SVG_roundies.v.bgColor)}},svgStrokeColor:function(a){a.style.setProperty("border-color","transparent",null);a.SVG_roundies.paths.stroke.setAttribute("fill",a.SVG_roundies.v.borderColor)},svgStrokeWeight:function(d){var c=document.defaultView.getComputedStyle(d,null);var e=["top","right","bottom","left"];d.SVG_roundies.bW=[];for(var a=0;a<4;a++){d.SVG_roundies.bW[e[a]]=parseInt(c.getPropertyValue("border-"+e[a]+"-width"),10)||0}},svgOffsets:function(b){var e=["Left","Top","Width","Height"];b.SVG_roundies.dim=[];for(var c=0;c<4;c++){b.SVG_roundies.dim[e[c]]=b["offset"+e[c]]}var a=function(d){d.style.setProperty("left",b.SVG_roundies.dim.Left+"px",null);d.style.setProperty("top",b.SVG_roundies.dim.Top+"px",null);d.style.setProperty("width",b.SVG_roundies.dim.Width+"px",null);d.style.setProperty("height",b.SVG_roundies.dim.Height+"px",null)};a(b.SVG_roundies.svg)},svgPath:function(e){var f=function(q,s,n,j,t,o){var l=j.slice();for(var m=0;m<4;m++){l[m]=Math.min(s/2,n/2,l[m])}if(q){var k=["M","A","L","A","L","A","L","A","L"];var p=[k[0]+Math.floor(0+t)+","+Math.floor(l[0]+o),k[1]+l[0]+","+l[0]+" 0 0 1 "+Math.floor(l[0]+t)+","+Math.floor(0+o),k[2]+Math.ceil(s-l[1]+t)+","+Math.floor(0+o),k[3]+l[1]+","+l[1]+" 0 0 1 "+Math.ceil(s+t)+","+Math.floor(l[1]+o),k[4]+Math.ceil(s+t)+","+Math.ceil(n-l[2]+o),k[5]+l[2]+","+l[2]+" 0 0 1 "+Math.ceil(s-l[2]+t)+","+Math.ceil(n+o),k[6]+Math.floor(l[3]+t)+","+Math.ceil(n+o),k[7]+l[3]+","+l[3]+" 0 0 1 "+Math.floor(0+t)+","+Math.ceil(n-l[3]+o),k[8]+Math.floor(0+t)+","+Math.floor(l[0]+o)]}else{var k=["A","L","A","L","A","L","A","L","M"];var p=[k[0]+l[0]+","+l[0]+" 0 0 0 "+Math.floor(0+t)+","+Math.floor(l[0]+o),k[1]+Math.floor(l[0]+t)+","+Math.floor(0+o),k[2]+l[1]+","+l[1]+" 0 0 0 "+Math.ceil(s-l[1]+t)+","+Math.floor(0+o),k[3]+Math.ceil(s+t)+","+Math.floor(l[1]+o),k[4]+l[2]+","+l[2]+" 0 0 0 "+Math.ceil(s+t)+","+Math.ceil(n-l[2]+o),k[5]+Math.ceil(s-l[2]+t)+","+Math.ceil(n+o),k[6]+l[3]+","+l[3]+" 0 0 0 "+Math.floor(l[3]+t)+","+Math.ceil(n+o),k[7]+Math.floor(0+t)+","+Math.ceil(n-l[3]+o),k[8]+Math.floor(0+t)+","+Math.floor(l[0]+o)];p.reverse()}var u=p.join("");return u};var g=e.SVG_roundies.bW;var a=e.SVG_roundies.radii.slice();var d=f(true,e.SVG_roundies.dim.Width,e.SVG_roundies.dim.Height,a,0,0);a[0]-=Math.max(g.left,g.top);a[1]-=Math.max(g.top,g.right);a[2]-=Math.max(g.right,g.bottom);a[3]-=Math.max(g.bottom,g.left);for(var c=0;c<4;c++){a[c]=Math.max(a[c],0)}var b=f(false,e.SVG_roundies.dim.Width-g.left-g.right,e.SVG_roundies.dim.Height-g.top-g.bottom,a,g.left,g.top);e.SVG_roundies.paths.color.setAttribute("d",b);e.SVG_roundies.paths.stroke.setAttribute("d",d+b)},reposition:function(a){this.svgOffsets(a);this.svgPath(a)},addEventListeners:function(d){if(d.handlers===undefined){d.handlers=[];var e=SVG_roundies;var a={resize:"reposition"};for(var c in a){var b=function(){e[a[c]](d)};if(c=="resize"){window.addEventListener(c,b,false)}else{d.addEventListener(c,b,false)}d.handlers.push({type:c,listener:b})}var b=function(f){e.readPropertyChanges(f)};d.addEventListener("DOMAttrModified",b,false);d.handlers.push({type:"DOMAttrModified",listener:b})}},removeEventListeners:function(c){if(c.handlers!==undefined){for(var a=0;a<c.handlers.length;a++){var b=c.handlers[a];if(b.type=="resize"){window.removeEventListener(b.type,b.listener,false)}else{c.removeEventListener(b.type,b.listener,false)}}delete c.handlers}},roundify:function(c,a){var e=SVG_roundies;c.SVG_roundies={};c.SVG_roundies.radii=a;var d={TABLE:false,TR:false,TD:false,OPTION:false};if(d[c.nodeName]===false){return}this.runtimeStyle(c);var b=document.defaultView.getComputedStyle(c,null);c.SVG_roundies.svg=document.createElementNS("http://www.w3.org/2000/svg","svg");c.SVG_roundies.svg.style.setProperty("position","absolute",null);c.SVG_roundies.svg.style.setProperty("z-index",b.getPropertyValue("z-index"),null);c.SVG_roundies.paths={};c.SVG_roundies.paths.color=document.createElementNS("http://www.w3.org/2000/svg","path");c.SVG_roundies.svg.appendChild(c.SVG_roundies.paths.color);c.SVG_roundies.paths.stroke=document.createElementNS("http://www.w3.org/2000/svg","path");c.SVG_roundies.svg.appendChild(c.SVG_roundies.paths.stroke);c.parentNode.insertBefore(c.SVG_roundies.svg,c);if(b.getPropertyValue("position")=="static"){c.style.setProperty("position","relative",null)}c.SVG_roundies.isImg=false;if(c.nodeName=="IMG"){c.SVG_roundies.isImg=true;c.style.setProperty("visibility","hidden",null)}setTimeout(function(){e.applySVG(c)},1)}};