(function(scope){if(null==scope.at)scope.at={};if(null==scope.at.leichtgewicht)scope.at.leichtgewicht={};if(null==scope.at.leichtgewicht.color)scope.at.leichtgewicht.color={};var classPath=scope.at.leichtgewicht.color;var statik;var publik;statik=classPath.ColorFade=function(style,cycle,s,b){this.statik.initMouseDownHandle();this.replacer=new classPath.ColorReplacer(style);this.cycle=cycle;this.s=s;this.b=b;var scope=this;setInterval(function(){scope.onInterval()},1000);this.onInterval()};statik.mouseDown=false;statik.initMouseDownHandle=function(){if(!this.inited){this.inited=true;if(document.all){$(document.body).mousedown(function(event){this.mouseDown=true});$("*").mouseup(function(){this.mouseDown=false});$(document.body).mousemove(function(event){if(!event){event=window.event}if(0==event.button){this.mouseDown=false}})}}};publik=statik.prototype;publik.statik=statik;publik.onInterval=function(){if(!this.statik.mouseDown){var time=(new Date()).getTime();this.replacer.setColor(classPath.RainbowColor.create((time%this.cycle)/this.cycle,this.s,this.b))}};statik=classPath.ColorReplacer=function(css){this.node=document.createElement("style");this.css=css;$("head").append(this.node)};publik=statik.prototype;publik.setColor=function(color){$(this.node).text(this.css.split("$color").join(at.leichtgewicht.color.RGB.toHex(color)))};statik=classPath.RainbowColor=function(){};statik.create=function(percentage,s,b){var degree=percentage*1080;degree+=180;var degreeOffset=Math.floor(degree/360);degree=degree%360;var offset=-Math.cos(degree/360*Math.PI);return at.leichtgewicht.color.HSB.toRGB((degreeOffset*360+180*offset)/1080*360,s,b)};statik=classPath.RGB=function(){};statik.toHex=function(color){return"#"+this.toHexComponent(color.r)+this.toHexComponent(color.g)+this.toHexComponent(color.b)};statik.toHexComponent=function(number){number*=255;var digits='0123456789ABCDEF';var lsd=number%16;var msd=(number-lsd)/16;var hexified=digits.charAt(msd)+digits.charAt(lsd);return hexified};statik=classPath.HSB=function(){};statik.toRGB=function(h,s,b){if(b<=0){return 0}b=(b>=1)?1:b;if(s==0){return{r:b,g:b,b:b}}else{if(h<0){h=360-(-h)%360}h=Math.floor(h%360);s=(s>=1)?1:s;var sectorPos=h/60;var sectorNumber=Math.floor(sectorPos);var fractionalSector=sectorPos-sectorNumber;var p=b*(1-s);var q=b*(1-(s*fractionalSector));var t=b*(1-(s*(1-fractionalSector)));return{r:[b,q,p,p,t,b][sectorNumber],g:[t,b,b,q,p,p][sectorNumber],b:[p,p,t,b,b,q][sectorNumber]}}}})(window);
