(function(){var E,D,B=/.*\.css$/i,C=/[ \w.0-9~#:*-|\[\]$^\n\f\r\t]+\{[;\w:_()=.%\t\n\f\r\ \\"'#,-]*\}/gi,A=window.ss=window.dynSS=function(G,H,F){return new A.fn.init(G,H,F)};A.ds=document.styleSheets;A.fn=A.prototype={length:null,findSelector:"",prevObject:null,sheets:[],version:"0.1.1",debug:true,ignore:[],init:function(G,H,F){D=this;this.length=0;this.removeAllRules();if(typeof F!=="undefined"){this.findSelector=F}if(typeof H!=="undefined"){if(typeof H==="string"){H=this.getSheet(H)}if(H.cssRules||H.rules){this.sheets=[H]}else{if(H[0]){if(H[0].cssRules||H[0].rules){this.sheets=H}}}this.log("Context sheet: ",H)}if(typeof G==="undefined"){this.log("Init:\tno selector");return this.initAllRules()}else{if(G.compile&&G.exec){this.log("Init:\tregexp: ",G);this.initAllRules();return this.find(G)}else{if(G.cssRules||G.rules){this.log("Init:\tstylesheet: ",G);this.sheets=[G];return this.initRules(this.getRulesFromSheet(G),G)}else{if(typeof G==="string"){if(C.test(G)){if(!this.sheets.length){this.initAllSheets()}return this.addMultiple(G,H)}else{if(B.test(G)){return this.newSS(G)}else{this.log("Init:\tselector string: ",G);this.initAllRules();return this.find(G)}}}else{if(G.nodeType){this.log("Init:\tHTML elem");if(!this.sheets.length){this.initAllSheets()}this.initAllRules();return this.getAffectingRules(G)}else{if(typeof G==="object"){if(G.length){if(G[0].cssText||G[0].selectorText){this.log("Init:\trules",G);return this.initRules(G)}}if(G.selectorText){this.log("Init:\tstyle rule");this.initAllSheets();this.length=1;this[0]=G;return this}else{this.log("Init:\twth is this?",G)}}}}}}}return this},end:function(){if(this.prevObject){return this.prevObject}this.log("End:\tno previous object");return this},find:function(I){var G=this.length,K=[],H=0,F=I,J;if(typeof I==="string"){I=this.trim(I);if(/--.*/.test(I)){I=this.regExpEscape(I);I=".*"+I.substring(4).split(" ").join("\\b.*\\b[^.|#]{1}")+"\\b.*";I=new RegExp(I,"i")}else{if(/\|\|.*/.test(I)){J=I.substring(2).split("|");for(H=0;H<J.length;H++){J[H]=this.regExpEscape(this.trim(J[H]))}I="\\b"+J.join("\\b|");I=new RegExp(I,"i")}}}if(typeof I==="string"){I=this.regExpEscape(I);I=new RegExp(I,"i")}for(H=0;H<G;H++){if(I.test(this[H].selectorText)){K.push(this[H])}}this.log("Find:\t",I);this.log("New rules: ",K.length);return this.pushStack(K,F)},pushStack:function(H,F){var G=A(H,this.sheets.slice(),F);G.prevObject=this;return G},eq:function(F){if(F<0){return this.eq(this.length+F)}else{if(F>=0&&F<this.length){this[0]=this[F];for(var G=1;G<this.length;G++){delete this[G]}this.length=1;return this}}this.log("Eq: i is an invalid index: ",F);return this},filter:function(F){if(typeof F!=="function"){F=function(){}}return this.each(function(){})},push:function(G){if(typeof G==="string"){G=A(G)}for(var F=0;F<G.length;F++){this[this.length++]=G[F]}return this},unique:function(F){return F},merge:function(F){return this.push(F).unique()},initRules:function(K,F){var I,J,H,G;if(F){if(F.imports){if(F.imports.length){for(G=0;G<F.imports.length;G++){if(!this.sheetSelected(F.imports[G].href)){H=F.imports[G];this.sheets.push(H);this.initRules(this.getRulesFromSheet(H),H)}}}}}for(I=0;I<K.length;I++){J=K[I];if(J.href){if(!this.sheetSelected(J.href)){H=J.styleSheet;this.sheets.push(H);this.initRules(this.getRulesFromSheet(H),H)}}else{if(!/^#Firebug/.test(J.selectorText)){this[this.length++]=J}}}return this},initAllRules:function(){var F;this.length=0;if(this.sheets.length===0){this.initAllSheets()}for(F=0;F<this.sheets.length;F++){this.initRules(this.getRulesFromSheet(this.sheets[F]),this.sheets[F])}return this},initAllSheets:function(){this.sheets=[];for(var F=0;F<document.styleSheets.length;F++){try{A.ds[F].cssRules}catch(G){D.log("Error",G);D.log(A.ds[F]);continue}if(!this.ignoreSheet(A.ds[F])){this.sheets.push(document.styleSheets[F])}}return this},ignoreSheet:function(G){for(var F=0;F<A.fn.ignore.length;F++){this.log(A.fn.ignore[F],G);if(A.fn.ignore[F]===G){return true}}return false},getRulesFromSheet:function(G){if(G.cssRules){return G.cssRules}else{if(G.rules){return G.rules}}try{if(G[0].cssText||G[0].selectorText){return G}else{return this.defaultRules()}}catch(F){}return this.log("getRulesFromSheet: Bad sheet: ",G)},addMultiple:function(I,H){if(typeof H==="undefined"){H=true}var G,F=I.match(C);this.log("addMultiple: add new rule(s): ",F);for(G=0;G<F.length;G++){this.add(F[G],H)}return this},add:function(N,I){I=(typeof I==="undefined"||I)?true:false;var O,M,H,L,J,F=this.sheets[0],K=this.getRulesFromSheet(F).length,G;if(F.insertRule){this.log("add:\tinsertRule");if(N.indexOf("{")+N.indexOf("}")==-2){N+=" { }"}F.insertRule(N,K);G=this.getRuleByIndex(F,K)}else{this.log("add:\taddRule");N=this.trim(N);O=N.indexOf("{");M=N.length;H=(N.indexOf("{")==-1)?N:N.substr(0,O);L=(O+1==M)?"":N.substring(O+1,M-1);if(L.length===0){this.log("Empty properties");F.addRule(H,null,K)}else{L=this.trim(L).split(";");for(J=0;J<L.length;J++){if(L[J]!=""){F.addRule(H,L[J],K)}}}G=this.getRuleByIndex(F,K)}this.log("add:\t",G);if(G.selectorText&&I){this.log("Adding new rule to selection",this);this.addRule(G)}return this},addRule:function(F){this[this.length++]=F;return this},getRuleByIndex:function(G,F){return this.getRulesFromSheet(G)[F]},remove:function(){this.each(function(G,F){D.removeRule(F)});this.removeAllRules();this.length=0;return this},removeRule:function(I){var H=this.getRuleIndex(I),F=H[0],G=H[1];if(F){if(F.deleteRule){F.deleteRule(G)}else{if(F.removeRule){F.removeRule(G)}}}},getRuleIndex:function(J){var H,F,I,G;for(I=0;I<this.sheets.length;I++){H=this.sheets[I];F=this.getRulesFromSheet(H);for(G=0;G<F.length;G++){if(F[G]==J){return[H,G]}}}return false},copy:function(G){this.eq(0);if(this.length){var F=this.text();F=G+" "+F.substr(F.indexOf("{"));this.add(F)}return this},rename:function(F){if(this.length){this.copy(F);A(this[0]).remove()}return this},disable:function(G,F){return this},property:function(L,K,F){if(this.length<1){this.log("Property: No rules selected to set styles in");return this}var J,M,G,I,H;if(typeof K==="undefined"){if(typeof L==="object"){J=L;this.log("Set many styles: ",J)}else{this.log("Get the property ",L);if(this.length){return this[0].style[this.camelCase(L)]}return false}}else{this.log("Set property "+L+" with "+K);J={};J[L]=K}this.each(function(N){M=this;G=this.style[N];if(J){for(H in J){if(M.style.setProperty){if(F){J[H]=D.incrementValue(M.style.getPropertyValue(H),K)}M.style.setProperty(H,J[H],null)}else{I=D.camelCase(H);if(I=="float"){I="styleFloat"}else{if(I=="opacity"){I="filter";J[H]="alpha(opacity="+(J[H]*100)+");"}}if(F){J[H]=D.incrementValue(M.style.getPropertyValue(H),K)}M.style[I]=J[H]}}}});return this},camelCase:function(F){return F.replace(/\-(\w)/g,function(G,H){return H.toUpperCase()})},incrementValue:function(G,I){var H=parseFloat(G),F=G.substring((""+H).length);if(I.toString().indexOf("%")>0){return H+(H*(parseFloat(I)/100))+F}return(H+I)+F},disableProperty:function(G,F){},getRulesAsArray:function(){var H={},J,K,G,I,F;this.each(function(){if(this.style.cssText){J=this.style.cssText}else{J=this.cssText}G=J.split(";");for(I=0,F=G.length;I<F;I++){K=G[I].split(":");if(K[0]&&K[1]&&D.checkProp(K[0])){H[D.trim(K[0])]=D.trim(K[1])}}});return H},checkProp:function(F){if(/moz-/.test(F)){return false}return true},copyStyles:function(){var F=this.getRulesAsArray();this.log("copyStyles",F);if(arguments.length==1){this.log("Copy all styles to ",arguments[0]);if(!this.ruleExists()){A(this.sheets[0]).add(arguments[0])}A().find(arguments[0]).property(F)}return this},ruleExists:function(F){return false},getCascadedStyles:function(F,G){},text:function(F){var I="",K,M,H,J,G,L;if(typeof F==="string"){G=[];this.each(function(){G.push(this);K=A(this).text();M=K.substr(0,K.indexOf("{")+1);H=K.substr(K.lastIndexOf("}"));D.add(M+F+H)});for(L in G){this.remove(L)}return this}else{if(F===true){this.eachSheet(function(){if(this.cssText){I+=this.cssText}else{if(this.ownerNode){for(J=0;J<this.ownerNode.childNodes.length;J++){I+=this.ownerNode.childNodes[J].textContent}}else{this.log("text() error: May be imported style sheet, text output not supported yet")}}})}else{this.each(function(){if(this.cssText){I+=this.cssText+"\n"}else{I+=this.selectorText+"{"+this.style.cssText+"}\n"}})}}return I},selectorText:function(){if(this.length>0){return this[0].selectorText}return this},getComputedStyle:function(F,G){if(document.defaultView&&document.defaultView.getComputedStyle){return document.defaultView.getComputedStyle(F,null)}else{if(F.currentStyle){return F.currentStyle}else{return F.style}}},getAffectingRules:function(G){var F="";if(G.id){F+="\\#"+G.id+"\\b|"}if(this.trim(G.className)!==""){F+="\\."+G.className.split(" ").join("\\b|.")+"|"}if(G.nodeName){F+=G.nodeName+"(?![a-zA-Z0-9-_])"}F=RegExp(F,"i");return this.find(F)},newSS:function(J,L){this.log("New stylesheet, ",J);var K=(typeof L==="boolean"&&L)?false:true,G,I=document.getElementsByTagName("head")[0],F=B.test(J),H;J=typeof J==="string"?J:"";L=typeof L==="string"?L:"Sheet_"+document.styleSheets.length;if(F){for(H=0;H<document.styleSheets.length;H++){if(RegExp(".*"+J+"$","i").test(document.styleSheets[H].href)){return this.init(document.styleSheets[H])}}}if(document.createStyleSheet){if(F){document.createStyleSheet(J)}else{document.createStyleSheet().cssText=J}G=document.styleSheets[document.styleSheets.length-1];G.title=L;if(K){return this.init(G)}}else{if(F){G=document.createElement("link");G.type="text/css";G.rel="stylesheet";G.href=J;G.media="screen";I.appendChild(G);G=G.sheet;return this}else{G=document.createElement("style");G.type="text/css";G.media="screen";G.rel="stylesheet";G.title=L;I.appendChild(G);G.appendChild(document.createTextNode(J));G=G.sheet;return this}}this.sheets[this.sheets.length]=G;return this.initRules(this.getRulesFromSheet(G))},newSSTimeout:function(){return this},sheetSelected:function(F){var G=false;this.eachSheet(function(){if(typeof this.href==="string"){if(RegExp(F+"$").test(this.href)){this.log("sheetSelected: sheet is selected already: ",this);G=true;return false}}});return G},switchSS:function(G){var F,H;if(parseInt(G)>=0&&parseInt(G)<this.sheets.length){for(F=0;F<this.sheets.length;F++){this.disableSS(G)}this.enableSS(G)}else{if(typeof G==="string"){for(F=0;F<this.sheets.length;F++){if(this.sheets[F].getAttribute("title")==G){for(H=0;H<this.sheets.length;H++){this.disableSS(G)}this.enableSS(F);break}}}}return this},enableSS:function(F){this.sheets[F].disabled=false;return this},disableSS:function(F){this.sheets[F].disabled=true;return this},toggleSS:function(F){this.sheets[F].disabled=!this.sheets[F].disabled;return this},removeSS:function(G){var H,F;if(typeof G==="undefined"){H=this.sheets[0]}else{if(typeof G==="number"){H=document.styleSheets[G]}else{if(typeof G==="string"){for(F=0;F<document.styleSheets.length;F++){if(document.styleSheets[F].title+""==G+""){H=document.styleSheets[F]}}}}}if(H.cssRules||H.rules){if(H.ownerNode){H.ownerNode.parentNode.removeChild(H.ownerNode)}if(H.owningElement){H.owningElement.parentNode.removeChild(H.owningElement)}}return this},getSheet:function(G){for(var F=0;F<document.styleSheets.length;F++){if(document.styleSheets[F].title+""==G){return document.styleSheets[F]}}return false},appendMedium:function(F){if(this.sheets[0].media.appendMedium){this.sheets[0].media.appendMedium(F)}else{if(typeof this.sheets[0].media==="string"){this.sheets[0].media=this.sheets[0].media+", "+F}}return this},deleteMedium:function(F){if(this.sheets[0].media.deleteMedium){this.sheets[0].media.deleteMedium(F)}else{if(typeof this.sheets[0].media==="string"){this.sheets[0].media=this.sheets[0].media.replace(this.regExpEscape(F,"ig"),"")}}return this},medium:function(H){if(typeof arguments[0]==="string"){return this.appendMedium(arguments[0])}if(typeof arguments[0]==="object"){this.each(arguments[0],function(){D.appendMedium(this)});return this}var I,G,F=[];if(typeof this.sheets[0].media==="string"){I=this.trim(this.sheets[0].media);return I.split(",")}for(G=0;G<this.sheets[0].media.length;G++){F.push(this.sheets[0].media.item(G))}return F},s:function(F){F=typeof F==="undefined"?0:F;return this.sheets[F]},each:function(G,K){if(typeof G==="function"){K=G;G=this}var F,H=0,I=G.length,J;if(I==E){for(F in G){if(K.call(G[F],F,G[F])===false){break}}}else{for(J=G[0];H<I&&K.call(J,H,J)!==false;J=G[++H]){}}return G},eachSheet:function(F){return this.each(this.sheets,F)},removeAllRules:function(){if(this.length>0){this.eq(0);delete this[0]}return this},color:function(F){return this.property("color",F)},border:function(F){return this.property("border",F)},background:function(F){return this.property("background",F)},font:function(F){return this.property("font",F)},margin:function(F){return this.property("margin",F)},padding:function(F){return this.property("padding",F)},outline:function(F){return this.property("outline",F)},width:function(F){return this.property("width",F)},height:function(F){return this.property("height",F)},valign:function(F){return this.property("vertical-align",F)},cursor:function(F){return this.property("cursor",F)},display:function(F){return this.property("display",F)},cssFloat:function(F){return this.property("float",F)},position:function(F){return this.property("position",F)},visibility:function(F){return this.property("visibility",F)},opacity:function(F){if(typeof F==="undefined"){return this.property("opacity")}return this.property("opacity",F)},zindex:function(F){return this.property("z-index",F)},left:function(F){return this.property("left",F)},right:function(F){return this.property("right",F)},top:function(F){return this.property("top",F)},bottom:function(F){return this.property("bottom",F)},overflow:function(F){return this.property("overflow",F)},clear:function(F){return this.property("clear",F)},lineheight:function(F){return this.property("line-height",F)},listStyle:function(F){return this.property("list-style",F)},hover:function(F){return this.copy(":hover",F)},animate:function(H,G,K,L){this.eq(0);var J=30,F=1000/J,I=setInterval(function(){D.property(H,G,true)},F);setTimeout(function(){clearTimeout(I);if(typeof L==="function"){L()}},K+100);return this},trim:function(I){var H=/^\s+|\s+$/,F=I.split(/\n/g),G=F.length;while(G-->0){F[G]=F[G].replace(H,"")}return F.join("\n")},log:function(G,F){if(this.debug){try{if(arguments.length>1){console.log("~\t",G,F)}else{if(arguments.length>0){console.log("~\t",G)}else{console.log("~\t",this)}}}catch(H){}}return this},selectorList:function(){var F="";this.each(function(){F+=this.selectorText+"\n"});return F},regExpEscape:function(G){if(!arguments.callee.sRE){var F=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+F.join("|\\")+")","g")}return G.replace(arguments.callee.sRE,"\\$1")}};A.prototype.init.prototype=A.prototype})();
