(function($){$.fn.fkImageResize=function(options)
{var opts=$.extend({},$.fn.fkImageResize.defaults,options);return this.each(function(){this.opts=opts;var oldWidth=Number($(this).width()||$(this).css("width").replace("px",""));var oldHeight=Number($(this).height()||$(this).css("height").replace("px",""));var newWidth=oldWidth;var newHeight=oldHeight;if(newWidth>this.opts.max_width)
{newWidth=this.opts.max_width;newHeight=oldHeight/(oldWidth/newWidth);}
if(newHeight>this.opts.max_height)
{newHeight=this.opts.max_height;newWidth=oldWidth/(oldHeight/newHeight);}
$(this).width(Math.round(newWidth));$(this).height(Math.round(newHeight));});};$.fn.fkImageResize.defaults={max_width:50,max_height:50};$.fn.fkImageCenter=function(options)
{var defaults={max_width:Number($(this).parent().width()),max_height:Number($(this).parent().height()),extra_padding:0};var opts=$.extend(defaults,options);return this.each(function(){this.opts=opts;var imageWidth=$(this).width();var imageHeight=$(this).height();if(imageWidth>this.opts.max_width||imageHeight>this.opts.max_height)
{$(this).fkImageResize({max_width:this.opts.max_width,max_height:this.opts.max_height});var imageWidth=Number($(this).css("width").replace("px",""));var imageHeight=Number($(this).css("height").replace("px",""));}
var padding_x=opts.extra_padding+(this.opts.max_width-imageWidth)/2;var padding_y=opts.extra_padding+(this.opts.max_height-imageHeight)/2;$(this).css("paddingTop",Math.floor(padding_y));$(this).css("paddingRight",Math.ceil(padding_x));$(this).css("paddingBottom",Math.ceil(padding_y));$(this).css("paddingLeft",Math.floor(padding_x));});};$.fn.fkCenter=function(options)
{var defaults={centerX:true,centerY:true,bindToResize:true,parentWidth:null,parentHeight:null};var opts=$.extend(defaults,options);if(opts.parentWidth==null)opts.parentWidth=$(window).width();if(opts.parentHeight==null)opts.parentHeight=$(window).height();return this.each(function()
{this.opts=opts;if(this.opts.bindToResize)
{var instance=this;$(window).resize(function(){instance.opts.bindToResize=false;instance.opts.parentHeight=null;$(instance).fkCenterVertically(instance.opts);});}
if(this.opts.centerX&&($(this).outerWidth()<this.opts.parentWidth))
$(this).css('margin','auto');if(this.opts.centerY)
$(this).fkCenterVertically(this.opts);});};$.fn.fkCenterVertically=function(options)
{var defaults={parentHeight:null};var opts=$.extend(defaults,options);if(opts.parentHeight==null)opts.parentHeight=$(window).height();return this.each(function()
{this.opts=opts;if($(this).outerHeight()<this.opts.parentHeight)
var marginY=(this.opts.parentHeight-$(this).outerHeight())/2;else
var marginY=0;$(this).css({'margin-top':marginY,'margin-bottom':marginY});});};})(jQuery);
