/**
 * This is straight from jQuery 1.5.2 backporting deferred in case it does't exists.
 */
if (!jQuery.Deferred) {
  (function(b){var a="then done fail isResolved isRejected promise".split(" "),c=[].slice;b.extend({_Deferred:function(){var g=[],h,e,f,d={done:function(){if(!f){var k=arguments,l,o,n,m,j;if(h){j=h;h=0}for(l=0,o=k.length;l<o;l++){n=k[l];m=b.type(n);if(m==="array"){d.done.apply(d,n)}else{if(m==="function"){g.push(n)}}}if(j){d.resolveWith(j[0],j[1])}}return this},resolveWith:function(j,i){if(!f&&!h&&!e){i=i||[];e=1;try{while(g[0]){g.shift().apply(j,i)}}finally{h=[j,i];e=0}}return this},resolve:function(){d.resolveWith(this,arguments);return this},isResolved:function(){return !!(e||h)},cancel:function(){f=1;g=[];return this}};return d},Deferred:function(e){var d=b._Deferred(),g=b._Deferred(),f;b.extend(d,{then:function(i,h){d.done(i).fail(h);return this},fail:g.done,rejectWith:g.resolveWith,reject:g.resolve,isRejected:g.isResolved,promise:function(j){if(j==null){if(f){return f}f=j={}}var h=a.length;while(h--){j[a[h]]=d[a[h]]}return j}});d.done(g.cancel).fail(d.cancel);delete d.cancel;if(e){e.call(d,d)}return d},when:function(k){var e=arguments,f=0,j=e.length,h=j,d=j<=1&&k&&b.isFunction(k.promise)?k:b.Deferred();function g(l){return function(i){e[l]=arguments.length>1?c.call(arguments,0):i;if(!(--h)){d.resolveWith(d,c.call(e,0))}}}if(j>1){for(;f<j;f++){if(e[f]&&b.isFunction(e[f].promise)){e[f].promise().then(g(f),d.reject)}else{--h}}if(!h){d.resolveWith(d,e)}}else{if(d!==k){d.resolveWith(d,j?[k]:[])}}return d.promise()}})})(jQuery);
}
