(function(a){var b={scaleType:"fill",positionX:"",positionY:"",offsetX:0,offsetY:0,container:a(window),src:"",backgroundColor:"#000",cssPosition:"absolute",maxWidth:10,maxHeight:10,marginAdj:0};a.fn.wstBackground=function(){function c(a){var c=function(c){var d;b.scaleType=="fill"?d=i(c.width,c.height):b.scaleType=="fit"?d=j(c.width,c.height):d=h(c.width,c.height);var e=b.scaleType=="fit"&&d.bestDimension=="width"?"center":b.positionX,f=b.scaleType=="fit"&&d.bestDimension=="height"?"middle":b.positionY,g=(e=="right"?d.width.container-d.width.best:e=="center"?Math.ceil((d.width.container-d.width.best)/2):0)+b.offsetX,k=(f=="bottom"?d.height.container-d.height.best:f=="middle"?Math.ceil((d.height.container-d.height.best)/2):0)+b.offsetY;if(a){var l={left:g+"px",top:k+"px"};b.scaleType!="normal"&&(l[d.bestDimension]=d[d.bestDimension].best+"px",l[d.offDimension]=""),a.css(l)}};g(b.src,c)}function d(a){a.hasClass("bg-fill")?b.scaleType="fill":a.hasClass("bg-fit")?b.scaleType="fit":a.hasClass("bg-normal")&&(b.scaleType="normal")}function e(a){a.hasClass("x-left")?b.positionX="left":a.hasClass("x-center")?b.positionX="center":a.hasClass("x-right")&&(b.positionX="right")}function f(a){a.hasClass("y-top")?b.positionY="top":a.hasClass("y-middle")?b.positionY="middle":a.hasClass("y-bottom")&&(b.positionY="bottom")}function g(a,b){var c=function(a,b,d,e){b.height==0?e>=30?window.console&&console.log&&console.log("Giving up... unable to get image dimensions for "+a):setTimeout(function(){c(a,b,d,++e)},100):d({height:b.height,width:b.width,src:a})},d=new Image;d.src=a,c(a,d,b,0)}function h(a,c){var d={width:{image:a,container:b.container.width()==0?b.maxWidth:b.container.width(),best:a},height:{image:c,container:b.container.height()==0?b.maxHeight:b.container.height()+b.marginAdj,best:c}};return d}function i(a,c){var d={width:{image:a,container:b.container.width()==0?b.maxWidth:b.container.width()},height:{image:c,container:b.container.height()==0?b.maxHeight:b.container.height()+b.marginAdj}};d.width.ifOppositeFillsContainer=Math.ceil(d.width.image*d.height.container/d.height.image),d.height.ifOppositeFillsContainer=Math.ceil(d.height.image*d.width.container/d.width.image),d.width.ifOppositeFillsIsUsed=Math.ceil(d.width.image*d.height.ifOppositeFillsContainer/d.height.image),d.height.ifOppositeFillsIsUsed=Math.ceil(d.height.image*d.width.ifOppositeFillsContainer/d.width.image),d.width.minimumToFillContainer=d.width.container<=d.width.ifOppositeFillsContainer?d.width.ifOppositeFillsContainer:d.width.container,d.height.minimumToFillContainer=d.height.container<=d.height.ifOppositeFillsContainer?d.height.ifOppositeFillsContainer:d.height.container;var e=d.height.ifOppositeFillsIsUsed>d.height.container?"width":"height",f=e=="width"?"height":"width";return d.bestDimension=e,d.offDimension=f,d.text=e+": "+d[e].minimumToFillContainer+"px;",d[e].best=d[e].minimumToFillContainer,d[f].best=Math.ceil(d[f].image*d[e].minimumToFillContainer/d[e].image),d}function j(a,c){var d={width:{image:a,container:b.container.width()==0?b.maxWidth:b.container.width()},height:{image:c,container:b.container.height()==0?b.maxHeight:b.container.height()+b.marginAdj}},e=a<c?"height":"width",f=e=="width"?"height":"width";return d.bestDimension=e,d.offDimension=f,d.text=e+": "+d[e].container+"px;",d[e].best=d[e].container,d[f].best=Math.ceil(d[f].image*d[e].container/d[e].image),d}b.src=this.attr("src"),d(this),e(this),f(this),this.each(function(){var d=a(".sf_outer_wrapper").css("margin-top");if(d.indexOf("-")==-1&&d.indexOf("px")!=-1){a(this).css("margin-top","-"+d);var e=d.replace("px","");isNaN(e)||(b.marginAdj=parseInt(e))}a.browser.msie==1&&a.browser.version<=6&&a(this).css("position","absolute"),a(this).is("img")&&c(a(this))})},a(document).ready(function(){a("#ss-background").wstBackground()}),a(window).resize(function(){a("#ss-background").wstBackground()})})(jQuery)