/**
 * @author Han Lin Yap < http://zencodez.net/ >
 * @copyright 2011 zencodez.net
 * @license http://creativecommons.org/licenses/by-sa/3.0/
 * @package Css3-Finalize
 * @version 1.40 - 2011-05-10
 * @website https://github.com/codler/jQuery-Css3-Finalize
 *
 * == Description == 
 * Some css3 attributes needs to have a prefix in front 
 * in order to work in different browser. The plugin takes 
 * care of that so you only need to write without the prefix.
 *
 * == Example Usage ==
 * // This will look for all style-tags and parse them.
 * $('style').cssFinalize();
 */
(function(c){if(c.cssFinalize){return}if(!c.camelCase){var b=/-([a-z])/ig,a=function(d,e){return e.toUpperCase()};c.camelCase=function(d){return d.replace(b,a)}}c.cssFinalizeSetup={shim:true,node:"style,link",checkMedia:true};c.fn.cssFinalize=function(d){if(!d||typeof d!="object"){d={}}d.node=this;c.cssFinalize(d);return this};c.cssFinalize=function(j){var r=document.createElement("div");if(typeof j=="string"){newoptions=arguments[1]||{};newoptions.node=j;j=newoptions}j=c.extend({},c.cssFinalizeSetup,j);j.checkMedia=j.checkMedia&&window.matchMedia;var v=false;if(c.browser.webkit||c.browser.safari){v="webkit"}else{if(c.browser.mozilla){v="moz"}else{if(c.browser.msie){if(c.browser.version<=7&&!j.shim){return true}v="ms"}else{if(c.browser.opera){v="o"}}}}function g(A,B){return function(C){return(v==A)?B:false}}var k="animation animation-delay animation-direction animation-duration animation-fill-mode animation-iteration-count animation-name animation-play-state animation-timing-function";k+=" appearance backface-visibility";k+=" background-clip background-composite background-origin background-position-x background-position-y background-size";k+=" border-corner-image border-image border-top-image border-right-image border-bottom-image border-left-image border-top-left-image border-top-right-image border-bottom-left-image border-bottom-right-image border-radius";k+=" box-align box-direction box-flex box-flex-group box-lines box-ordinal-group box-orient box-pack box-reflect box-shadow box-sizing";k+=" column-count column-gap column-rule column-rule-color column-rule-style column-rule-width column-width columns";k+=" dashboard-region hyphenate-character hyphens line-break";k+=" grid-columns grid-rows";k+=" marquee marquee-direction marquee-increment marquee-repetition marquee-speed marquee-style";k+=" mask mask-attachment mask-box-image mask-clip mask-composite mask-image mask-origin mask-position mask-position-x mask-position-y mask-repeat mask-size";k+=" nbsp-mode";k+=" perspective perspective-origin";k+=" tab-size tap-highlight-color text-fill-color text-overflow text-security text-size-adjust";k+=" text-stroke text-stroke-color text-stroke-width";k+=" touch-callout";k+=" transform transform-origin transform-origin-x transform-origin-y transform-origin-z transform-style";k+=" transition transition-delay transition-duration transition-property transition-timing-function";k+=" user-drag user-modify user-select";k=k.split(" ");var o={};if(parseInt(c.browser.version.substr(0,1))<2){o={"border-top-left-radius":[g("moz","-moz-border-radius-topleft")],"border-top-right-radius":[g("moz","-moz-border-radius-topright")],"border-bottom-right-radius":[g("moz","-moz-border-radius-bottomright")],"border-bottom-left-radius":[g("moz","-moz-border-radius-bottomleft")]}}function m(A){var B=c.camelCase(A);return(v=="ms")?B[0].toLowerCase()+B.substr(1):B}function w(A){A=A.replace(/\/\*((?:[^\*]|\*[^\/])*)\*\//g,"");A=A.replace(/\n/g,"");A=A.replace(/\r/g,"");A=A.replace(/\@import[^;]*;/g,"");return A}function y(D,C){var A=D.match(RegExp(C,"g"));var B=D.replace(new RegExp(C,"g"),"[|]").split("[|]");var E=[];for(i in B){E.push(B[i]);if(A&&A[i]){E.push(A[i])}}return E}function z(A,C){if(v=="ms"&&c.browser.version<=7){var B=c('<style class="css-finalized" '+((A.attr("media")&&A.attr("media").length>0)?'media="'+A.attr("media")+'"':"")+"/>");c("head:first").append(B);B[0].styleSheet.cssText=h(C)}else{A.after('<style class="css-finalized" '+((A.attr("media")&&A.attr("media").length>0)?'media="'+A.attr("media")+'"':"")+">"+h(C)+"</style>")}}function e(B,C){C=w(C);if(c.trim(C)===""){return}var D=f(C);var A=[];A=E(D);function E(G){var F=[];c.each(G,function(H,J){if(J.attributes){var I=s(J.attributes);if(!c.isEmptyObject(I)){F.push({selector:n(J.selector),attributes:I})}else{if(n(J.selector)!=J.selector){F.push({selector:n(J.selector),attributes:J.attributes})}else{if(!j.checkMedia||(j.checkMedia&&J.selector.indexOf("@media")===0&&matchMedia(J.selector.substr(7)).matches)){F.push({selector:J.selector,attributes:E(J.attributes)})}}}}});return F}B.addClass("css-finalize-read");if(A.length>0){z(B,A)}}function f(H){var C;if(v=="ms"&&c.browser.version<=8){C=y(H,"({[^{}]*})")}else{C=H.split(/({[^{}]*})/)}if(C[C.length-1].indexOf("}")==-1){C.pop()}var D=[];var A=false;var I;var F=0;var G;var E=0;while(E<C.length){if(E%2===0){var B=c.trim(C[E]);if(A){if(B.indexOf("}")!=-1){B=B.substr(1);C[E]=B;G=C.splice(F,E-F);G.shift();G.unshift(I[1]);D[D.length-1].attributes=f(G.join(""));A=false;E=F;continue}}else{if(B.indexOf("{")!=-1){I=B.split("{");B=c.trim(I[0]);A=true;F=E}if(B!==""){D.push({selector:B})}}}else{if(!A){D[D.length-1].attributes=x(C[E].substr(1,C[E].length-2))}}E++}return D}function x(C){var B;C=C.replace(/url\(([^)]+)\)/g,function(D){return D.replace(/;/g,"[cssFinalize]")});if(v=="ms"&&c.browser.version<=8){B=y(C,"(:[^;]*;?)")}else{B=C.split(/(:[^;]*;?)/)}B.pop();var A={};c.map(B,function(E,D){if(D%2==1){A[c.trim(B[D-1])]=c.trim(E.substr(1).replace(";","").replace(/url\(([^)]+)\)/g,function(F){return F.replace(/\[cssFinalize\]/g,";")}))}});return A}function h(A){var B="";c.each(A,function(C,D){B+=D.selector+"{";if(c.isArray(D.attributes)){B+=h(D.attributes)}else{c.each(D.attributes,function(F,E){B+=F+":"+E+";"})}B+="}"});return B}function s(A){if(c.isArray(A)){return{}}var B={};c.each(A,function(F,E){var C=t(F);if(C){B[C]=E}var G=p(F,E,C);if(G){B[(C)?C:F]=G}var D=u(F,E);if(D){c.each(D,function(H,I){if(H=="filter"&&B[H]){B[H]+=" "+I}else{B[H]=I}})}});return B}function t(B){if(B in o){for(prefix in o[B]){if(c.isFunction(o[B][prefix])){var A=o[B][prefix](B);if(A){return A}}else{if(v==o[B][prefix]||!v){return"-"+o[B][prefix]+"-"+B}}}}if(c.inArray(B,k)>-1){if(!(m(B) in r.style)||B=="mask"){if(m("-"+v+"-"+B) in r.style){return"-"+v+"-"+B}}}return false}function p(E,D,G){G=G||E;if(E=="background-clip"||E=="background-origin"){r.style.cssText=G+":"+D;if(r.style[m(G)]!==undefined&&""+r.style[m(G)].indexOf(D)==-1){return D.split("-")[0]}}if(E=="transition"||E=="transition-property"){var I=D.split(/\s?,\s?/);var A=[];for(var B in I){var F,J;if(E=="transition"){F=I[B].split(" ")[0]}else{F=I[B]}if((J=t(F))!==false){A.push(J+I[B].substr(F.length))}else{A.push(I[B])}}return A.join(",")}if(v=="moz"){if(D.indexOf("calc")===0){return"-moz-"+D}}var L;if(E=="background"||E=="background-image"){if(D.indexOf("linear-gradient")===0){if(v=="webkit"){L=D.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(L.length==2){return"-webkit-gradient(linear, 0% 0%, 0% 100%, from("+L[0]+"), to("+L[1]+"))"}var K="";if(L.length>=3){var C="0% 0%, 0% 100%";if(L[0]==="left"){C="0% 0%, 100% 0%"}if(L.length>3){var H=L.slice(2,L.length-1);c.each(H,function(N,O){var M=O.split(/ /);if(M.length===2){K+="color-stop("+M[1]+", "+M[0]+"),"}})}return"-webkit-gradient(linear, "+C+", from("+L[1]+"), "+K+" to("+L[L.length-1]+"))"}}return"-"+v+"-"+D}else{if(D.indexOf("radial-gradient")===0){return"-"+v+"-"+D}}}return false}function u(C,B){if(j.shim){if(v=="ms"){if(C.toUpperCase()=="OPACITY"&&!c.support.opacity&&!c.isNaN(B)){return{filter:"alpha(opacity="+B*100+")",zoom:1}}if(c.browser.version<=8){if(C.toUpperCase()==="BACKGROUND-COLOR"&&B.indexOf("rgba")===0){B=d(B);return{filter:"progid:DXImageTransform.Microsoft.gradient(startColorStr='"+B+"',EndColorStr='"+B+"')"}}}if(c.browser.version<=9){if((C.toUpperCase()=="BACKGROUND"||C.toUpperCase()==="BACKGROUND-IMAGE")&&B.indexOf("linear-gradient")===0){var A=B.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(A.length==2){return{filter:"progid:DXImageTransform.Microsoft.gradient(startColorStr='"+A[0]+"',EndColorStr='"+A[1]+"')"}}}}}}return false}function n(A){if(v=="moz"){A=A.replace("::selection","::-moz-selection");A=A.replace("::placeholder",":-moz-placeholder")}else{if(v=="webkit"){A=A.replace("@keyframes","@-webkit-keyframes");A=A.replace("::placeholder","::-webkit-input-placeholder")}}return A}function d(E){var B=E.replace(/^rgba\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);var A=[];var D;for(var C=0;C<B.length;C++){if(C==3){B[C]*=255}D="0"+parseInt(B[C],10).toString(16);A.push(D.substr(D.length-2,2).toUpperCase())}A.splice(0,0,A.pop());return"#"+A.join("")}if(!(j.node instanceof jQuery)){j.node=c(j.node)}j.node.each(function(A,B){var C=c(this);if(C.hasClass("css-finalize-read")||C.hasClass("css-finalized")){return true}if(this.tagName=="LINK"&&C.attr("rel")=="stylesheet"){if(!j.checkMedia||(C.attr("media")&&C.attr("media").length>0&&matchMedia(C.attr("media")).matches)||(C.attr("media")&&C.attr("media").length===0)){l(this.href,C)}}else{e(C,C.html())}});function l(A,B){var G=document.location,F=G.protocol||"http:";var E=/^(\w+:)\/\/([^\/?#:]+)(?::(\d+))?/.exec(A.toLowerCase());var C=!!(E&&(E[1]!=F||E[2]!=G.hostname||(E[3]||(E[1]==="http:"?80:443))!=(G.port||(F==="http:"?80:443))));if(C){return}try{c("<div />").load(A,function(H){e(B,H)})}catch(D){}}if(c.cssHooks){for(property in o){if((newProperty=t(property))!==false){q(property,newProperty)}}for(property in k){if((newProperty=t(k[property]))!==false){q(k[property],newProperty)}}}function q(B,A){A=c.camelCase(A);if(v=="ms"&&c.browser.version<=8){A=A.charAt(0).toLowerCase()+A.substr(1)}c.cssHooks[c.camelCase(B)]={get:function(E,D,C){return E.style[A]},set:function(C,D){C.style[A]=D}}}};c(function(){if(window.cssFinalize!==false){c.cssFinalize()}})})(jQuery);window.matchMedia=window.matchMedia||(function(e,f){var c,a=e.documentElement,b=a.firstElementChild||a.firstChild,d=e.createElement("body"),g=e.createElement("div");g.id="mq-test-1";g.style.cssText="position:absolute;top:-100em";d.appendChild(g);return function(h){g.innerHTML='&shy;<style media="'+h+'"> #mq-test-1 { width: 42px; }</style>';a.insertBefore(d,b);c=g.offsetWidth==42;a.removeChild(d);return{matches:c,media:h}}})(document);
