/*global jQuery */
/* ****************************************************************************

	CJ Object Scaler jQuery Plug-In v2.1.1

	Copyright (c) 2010, Doug Jones. All rights reserved.


**************************************************************************** */

/*
 jQuery('img.photo',this).imagesLoaded(myFunction)
 execute a callback when all images have loaded.
 needed because .load() doesn't work on cached images

 mit license. paul irish. 2010.
 webkit fix from Oren Solomianik. thx!

 callback function is passed the last image to load
 as an argument, and the collection as `this`
*/
(function($){jQuery.fn.imagesLoaded=function(b){var c=this.filter('img'),len=c.length;c.bind('load',function(){if(--len<=0){b.call(c,this)}}).each(function(){if(this.complete||this.complete===undefined){var a=this.src;this.src='#';this.src=a}})}})(jQuery);

/*
 CJ Object Scaler
*/
(function($){jQuery.fn.cjObjectScaler=function(c){var d={method:"fill",destElem:null,fade:0};var e={version:'2.1.1',elem:null};function scaleObj(a){var b=jQuery(d.destElem).width(),destH=jQuery(d.destElem).height(),ratioX,ratioY,scale,newWidth,newHeight,borderW=parseInt(jQuery(a).css("borderLeftWidth"),10)+parseInt(jQuery(a).css("borderRightWidth"),10),borderH=parseInt(jQuery(a).css("borderTopWidth"),10)+parseInt(jQuery(a).css("borderBottomWidth"),10),objW=jQuery(a).width(),objH=jQuery(a).height();borderW=isNaN(borderW)?0:borderW;borderH=isNaN(borderH)?0:borderH;ratioX=b/jQuery(a).width();ratioY=destH/jQuery(a).height();if(!jQuery(a).hasClass("cf_image_scaler_fill")&&(jQuery(a).hasClass("cf_image_scaler_fit")||d.method==="fit")){scale=ratioX<ratioY?ratioX:ratioY}else if(!jQuery(a).hasClass("cf_image_scaler_fit")&&(jQuery(a).hasClass("cf_image_scaler_fill")||d.method==="fill")){scale=ratioX>ratioY?ratioX:ratioY}newWidth=parseInt(jQuery(a).width()*scale,10)-borderW;newHeight=parseInt(jQuery(a).height()*scale,10)-borderH;jQuery(a).css({"width":newWidth+"px","height":newHeight+"px","position":"absolute","top":(parseInt((destH-newHeight)/2,10)-parseInt(borderH/2,10))+"px","left":(parseInt((b-newWidth)/2,10)-parseInt(borderW/2,10))+"px"}).attr({"width":newWidth,"height":newHeight});if(d.fade>0){jQuery(a).fadeIn(d.fade)}}if(c){jQuery.extend(d,c)}return this.each(function(){e.elem=this;if(d.destElem===null){d.destElem=jQuery(e.elem).parent()}if(jQuery(d.destElem).css("position")==="static"){jQuery(d.destElem).css({"position":"relative"})}if(typeof e.elem==="object"&&typeof d.destElem==="object"&&typeof d.method==="string"){if(d.fade>0){jQuery(e.elem).hide()}if(e.elem.nodeName==="IMG"){jQuery(e.elem).width("auto");jQuery(e.elem).height("auto");jQuery(e.elem).imagesLoaded(function(){scaleObj(this)})}else{scaleObj(jQuery(e.elem))}}else{console.debug("CJ Object Scaler could not initialize.");return}})}})(jQuery);
