/*
Script: artpq.Floater.js
			È­¸é Æ¯Á¤ ³ôÀÌ¿¡ Ç×»ó ¶° ÀÖ´Â ÇÃ·ÎÆÃ ¹Ù.

Author: yangkun7@gmail.com
*/
if (!$type(artpq)) var artpq = {};
if (!$type(artpq.Floater)) {
	artpq.Floater = new Class({
		Extends: Fx.Tween,

		options: {
			fps: 80,
			link: 'cancel',
			bottom: null
		},
		initialize: function(floater, options){
			this.setOptions(options);
			this.options = $merge(this.options, {property: 'top'});
			this.parent($(floater), this.options);
			this.initTop = this.element.getPosition().y;
			this.isPlay = true;
			this.set(this.initTop);
			this.prevTop = this.initTop;

			this.bottomBound = null;
			if (this.options.bottom) this.bottomBound = $(this.options.bottom).getPosition().y - this.element.getSize().y;
			window.addEvent('scroll', this.adjustTop.bindWithEvent(this));
		},

		adjustTop: function(){
			if (this.isPlay) {
				var newTop = this.computeTop();
				//newTop  ÀÛÀº ¶§ ±âº»°ª
				if (newTop <= this.initTop) newTop = this.initTop;
				if ($defined(this.bottomBound) && newTop > this.bottomBound) newTop = this.bottomBound;//newTop = this.prevTop; //newTop = this.bottomBound;
				if (this.prevTop != newTop) {
					this.start(newTop);
					this.prevTop = newTop;
				}
			}
		},

		computeTop: function(){
			return $(window).getScroll().y + this.initTop;
		},

		fix: function(){
			this.set(this.initTop);
			this.prevTop = this.initTop;
			this.isPlay = false;
		},

		play: function(){
			this.isPlay = true;
			this.adjustTop();
		}
	});

	artpq.Floater.KeepTop = new Class({
		Extends: artpq.Floater,
		computeTop: function(){
			return $(window).getScroll().y;
		}
	});
}
