timely.define(["jquery_timely","external_libs/bootstrap/popover"],function(e){var t=function(e,t){this.init("constrained_popover",e,t)};t.DEFAULTS=e.extend({},e.fn.popover.Constructor.DEFAULTS,{container:"",content:this.options}),t.prototype=e.extend({},e.fn.popover.Constructor.prototype),t.prototype.constructor=t,t.prototype.getDefaults=function(){return t.DEFAULTS},t.prototype.applyPlacement=function(t,n){e.fn.popover.Constructor.prototype.applyPlacement.call(this,t,n);var r=this.tip(),i=r[0].offsetWidth,s=r[0].offsetHeight,o=this.getPosition(),u={};switch(n){case"left":newPos=this.defineBounds(o),typeof newPos.top=="undefined"?u.top=o.top+o.height/2-s/2:u.top=newPos.top-s/2,typeof newPos.left=="undefined"?u.left=o.left-i:u.left=newPos.left-i,r.offset(u);break;case"right":newPos=this.defineBounds(o),typeof newPos.top=="undefined"?u.top=o.top+o.height/2-s/2:u.top=newPos.top-s/2,typeof newPos.left=="undefined"?u.left=o.left+o.width:u.left=newPos.left+o.width,r.offset(u)}},t.prototype.defineBounds=function(t){var n,r,i,s,o,u={},a=e("body"===this.options.container?document:this.options.container);return a.length?(n=a.offset()||{top:0,left:0},r=n.top,i=n.left,s=r+a.height(),o=i+a.width(),t.top+t.height/2<r&&(u.top=r),t.top+t.height/2>s&&(u.top=s),t.left-t.width/2<i&&(u.left=i),t.left-t.width/2>o&&(u.left=o),u):!1};var n=e.fn.popover;e.fn.constrained_popover=function(n){return this.each(function(){var r=e(this),i=r.data("ai1ec.constrained_popover"),s=typeof n=="object"&&n;i||r.data("ai1ec.constrained_popover",i=new t(this,s)),typeof n=="string"&&i[n]()})},e.fn.constrained_popover.Constructor=t,e.fn.constrained_popover.noConflict=function(){return e.fn.constrained_popover=n,this}});