(function(a){a.slammer=function(c,b){var d=this;d.$element=a(c);d.element=c;d.$element.data("slammer",d);d.init=function(){d.spec=a.extend({},b);d.spec.layers=a.extend({},b.layers);var e="<div id='layout-canvas-wrapper' style='position:relative'></div>";d.$element.wrapInner(e);d.$wrapper=a("#layout-canvas-wrapper");e="<canvas id='layout-canvas' style='z-index:-1;position:absolute;left:0;top:0' width=";e+=d.$element.width();e+=" height="+d.$element.height();e+="></canvas>";d.$wrapper.prepend(e);d.canvas=a("#layout-canvas")[0]};d.drawLayer=function(f,e){f.save();f.fillStyle=e.backgroundColor;f.globalAlpha=e.opacity;f.globalCompositeOperation=e.compositeOperation;f.fillRect(e.rect.left,e.rect.top,e.rect.width,e.rect.height);f.beginPath();f.rect(e.rect.left,e.rect.top,e.rect.width,e.rect.height);f.clip();var g=a.extend([],e.overlays);jQuery.each(g,function(j,h){d.drawOverlay(f,e,h)});f.restore()};d.drawOverlay=function(g,f,e){var i=e.orientation*Math.PI/180;var h=f.rect;g.save();g.translate(h.left+h.width-1,h.top+h.height-1);g.rotate(Math.PI);g.translate(-h.left,-h.top);g.globalCompositeOperation=e.compositeOperation;g.globalAlpha=f.opacity*e.opacity;h=d.boundingRectForAngle(i,f.rect);g.translate(h.left+h.width/2,h.top+h.height/2);g.rotate(i);g.translate(-(h.left+h.width/2),-(h.top+h.height/2));if(e.type=="golden-section"){d.drawGoldenSection(g,h,e)}else{if(e.type=="uniform"){d.drawUniform(g,h,e)}else{if(e.type=="harmonious-section"){d.drawHarmoniousSection(g,h,e)}}}g.restore()};d.drawGoldenSection=function(f,h,e){var j=h.width/1.618;var g=h.width-j;if(!e.bidirectional){f.fillStyle=e.sectionColor;f.fillRect(h.left,h.top,j,h.height);f.fillStyle=e.alternateColor;f.fillRect(h.left+j,h.top,g,h.height)}else{var i=j-g;f.fillStyle=e.sectionColor;f.fillRect(h.left,h.top,g,h.height);f.fillStyle=e.alternateColor;f.fillRect(h.left+g,h.top,i,h.height);f.fillStyle=e.sectionColor;f.fillRect(h.left+j,h.top,g,h.height)}};d.drawHarmoniousSection=function(h,j,e){var g=j.width/e.numberOfSections;for(var f=1;f<=e.numberOfSections;f++){h.fillStyle=f%2==1?e.alternateColor:e.sectionColor;h.fillRect(j.left+g*(f-1),j.top,g,j.height)}};d.drawUniform=function(f,g,e){for(var h=0;h<=g.width;h+=e.sectionSize+e.gutterSize){f.fillStyle=e.alternateColor;f.fillRect(h+g.left,g.top,e.gutterSize,g.height);f.fillStyle=e.sectionColor;f.fillRect(h+g.left+e.gutterSize,g.top,e.sectionSize,g.height)}};d.boundingRectForAngle=function(i,g){var e=jQuery.extend(true,{},g);var f=Math.sin(i);var h=Math.cos(i);e.width=Math.abs(g.width*h)+Math.abs(g.height*f);e.height=Math.abs(g.width*f)+Math.abs(g.height*h);e.left-=((e.width-g.width)/2);e.top-=((e.height-g.height)/2);return e};d.showAll=function(){var e=d.canvas.getContext("2d");jQuery.each(d.spec.layers,function(g,f){d.drawLayer(e,f)})};d.hideAll=function(){var e=d.canvas.getContext("2d");e.clearRect(0,0,d.$element.width(),d.$element.height())};d.showLayer=function(e){var h=a.grep(d.spec.layers,function(j,i){j.name==e});if(!h.length){return}var g=h[0];var f=d.canvas.getContext("2d");d.drawLayer(f,g)};d.init();return this};a.fn.slammer=function(b){if(typeof(b)=="object"){(new a.slammer(this[0],b))}else{if(typeof(b)=="string"){var c=a(this).data("slammer");if(!c){return}if(b=="showAll"){c.showAll()}else{if(b=="hideAll"){c.hideAll()}else{c.showLayer(b)}}}}}})(jQuery);
