(function(k,j){k.ui=k.ui||{};var m=/left|center|right/,l=/top|center|bottom/,i="center",h=k.fn.position,n=k.fn.offset;k.fn.position=function(e){if(!e||!e.of){return h.apply(this,arguments)}e=k.extend({},e);var a=k(e.of),b=a[0],g=(e.collision||"flip").split(" "),p=e.offset?e.offset.split(" "):[0,0],c,f,d;if(b.nodeType===9){c=a.width();f=a.height();d={top:0,left:0}}else{if(b.setTimeout){c=a.width();f=a.height();d={top:a.scrollTop(),left:a.scrollLeft()}}else{if(b.preventDefault){e.at="left top";c=f=0;d={top:e.of.pageY,left:e.of.pageX}}else{c=a.outerWidth();f=a.outerHeight();d=a.offset()}}}k.each(["my","at"],function(){var o=(e[this]||"").split(" ");if(o.length===1){o=m.test(o[0])?o.concat([i]):l.test(o[0])?[i].concat(o):[i,i]}o[0]=m.test(o[0])?o[0]:i;o[1]=l.test(o[1])?o[1]:i;e[this]=o});if(g.length===1){g[1]=g[0]}p[0]=parseInt(p[0],10)||0;if(p.length===1){p[1]=p[0]}p[1]=parseInt(p[1],10)||0;if(e.at[0]==="right"){d.left+=c}else{if(e.at[0]===i){d.left+=c/2}}if(e.at[1]==="bottom"){d.top+=f}else{if(e.at[1]===i){d.top+=f/2}}d.left+=p[0];d.top+=p[1];return this.each(function(){var F=k(this),D=F.outerWidth(),o=F.outerHeight(),E=parseInt(k.curCSS(this,"marginLeft",true))||0,y=parseInt(k.curCSS(this,"marginTop",true))||0,B=D+E+(parseInt(k.curCSS(this,"marginRight",true))||0),A=o+y+(parseInt(k.curCSS(this,"marginBottom",true))||0),C=k.extend({},d),z;if(e.my[0]==="right"){C.left-=D}else{if(e.my[0]===i){C.left-=D/2}}if(e.my[1]==="bottom"){C.top-=o}else{if(e.my[1]===i){C.top-=o/2}}C.left=Math.round(C.left);C.top=Math.round(C.top);z={left:C.left-E,top:C.top-y};k.each(["left","top"],function(q,r){if(k.ui.position[g[q]]){k.ui.position[g[q]][r](C,{targetWidth:c,targetHeight:f,elemWidth:D,elemHeight:o,collisionPosition:z,collisionWidth:B,collisionHeight:A,offset:p,my:e.my,at:e.at})}});if(k.fn.bgiframe){F.bgiframe()}F.offset(k.extend(C,{using:e.using}))})};k.ui.position={fit:{left:function(d,c){var a=k(window),b=c.collisionPosition.left+c.collisionWidth-a.width()-a.scrollLeft();d.left=b>0?d.left-b:Math.max(d.left-c.collisionPosition.left,d.left)},top:function(d,c){var a=k(window),b=c.collisionPosition.top+c.collisionHeight-a.height()-a.scrollTop();d.top=b>0?d.top-b:Math.max(d.top-c.collisionPosition.top,d.top)}},flip:{left:function(e,c){if(c.at[0]===i){return}var a=k(window),b=c.collisionPosition.left+c.collisionWidth-a.width()-a.scrollLeft(),f=c.my[0]==="left"?-c.elemWidth:c.my[0]==="right"?c.elemWidth:0,d=c.at[0]==="left"?c.targetWidth:-c.targetWidth,g=-2*c.offset[0];e.left+=c.collisionPosition.left<0?f+d+g:b>0?f+d+g:0},top:function(e,c){if(c.at[1]===i){return}var a=k(window),b=c.collisionPosition.top+c.collisionHeight-a.height()-a.scrollTop(),f=c.my[1]==="top"?-c.elemHeight:c.my[1]==="bottom"?c.elemHeight:0,d=c.at[1]==="top"?c.targetHeight:-c.targetHeight,g=-2*c.offset[1];e.top+=c.collisionPosition.top<0?f+d+g:b>0?f+d+g:0}}};if(!k.offset.setOffset){k.offset.setOffset=function(b,e){if(/static/.test(k.curCSS(b,"position"))){b.style.position="relative"}var c=k(b),g=c.offset(),f=parseInt(k.curCSS(b,"top",true),10)||0,a=parseInt(k.curCSS(b,"left",true),10)||0,d={top:(e.top-g.top)+f,left:(e.left-g.left)+a};if("using" in e){e.using.call(b,d)}else{c.css(d)}};k.fn.offset=function(b){var a=this[0];if(!a||!a.ownerDocument){return null}if(b){return this.each(function(){k.offset.setOffset(this,b)})}return n.call(this)}}}(jQuery));