﻿/**
 * @author hooriza (ajaxUI) 20080930
 * @see http://wiki.nhncorp.com/display/lsuit/nhn.Fixed
 */
nhn.Fixed=$Class({_pos:null,_effect:null,_repaint:false,$init:function(a,b){var a=this._object=$(a);var c=this._$object=$Element(a);this.option({duration:500,effect:nhn.Effect.easeOut});this.option(b||{});this._effect=new nhn.Transition().fps(60);this.paint();
$Fn(this._onScroll,this).attach(window,'scroll');$Fn(this._onScroll,this).attach(window,'resize');var d=this;setTimeout(function(){d._onScroll()},0)},paint:function(){var a=this._object;var b=this._$object;var c=a.style.left;var d=a.style.right;var e=a.style.top;
var f=a.style.bottom;var g={x:c?'left':(d?'right':null),y:e?'top':(f?'bottom':null)};var h=b.offset();var i=$Document().clientSize();if(g.x=='left')g.xv=h.left;else if(g.x=='right'){g.xv=i.width-h.left-b.width();if(g.xv<
parseFloat(d))g.xv=parseFloat(d)}if(g.y=='top')g.yv=h.top;else if(g.y=='bottom'){g.yv=i.height-h.top-b.height();if(g.yv<parseFloat(f))g.yv=parseFloat(f)}if(this._repaint){var j=document.documentElement||document;var k=
document.body;var l={x:j.scrollLeft||k.scrollLeft,y:j.scrollTop||k.scrollTop};g.xv-=l.x;g.yv-=l.y}this._repaint=true;this._pos=g},_onScroll:function(){var a=document.documentElement||document;var b=document.body;var c=this._object;var d=
this._$object;var e=this._pos;var f={};var g=$Element(c).offset();var h,nPosY;var i={x:null,y:null};if(e.x){switch(e.x){case'left':f.x=a.scrollLeft||b.scrollLeft;h=g.left-f.x;break;case'right':f.x=(a.scrollLeft||
b.scrollLeft)+$Document().clientSize().width;h=f.x-(g.left+d.width());break}i.x=parseFloat(d.css(e.x))+(e.xv-h)}if(e.y){switch(e.y){case'top':f.y=a.scrollTop||b.scrollTop;nPosY=g.top-f.y;break;case'bottom':f.y=
(a.scrollTop||b.scrollTop)+$Document().clientSize().height;nPosY=f.y-(g.top+d.height());break}i.y=parseFloat(d.css(e.y))+(e.yv-nPosY)}this.fireEvent('beforemove',i);var j={};var k=this.option('effect');if(i.x!==null)j['@'+e.x]=
k(i.x+'px');if(i.y!==null)j['@'+e.y]=k(i.y+'px');var l=this;this._effect.start(this.option('duration'),c,j).precede(function(){l.fireEvent('move')})}}).extend(nhn.Component);
