/*
 * Created By Scott Steil of Imperium Inc.
 *
 * 
 */

var Follow = new Class({
	Implements: Options,
	options: {
		top: 0,
		bottom: null,
		offset: {top: 0, bottom: 0},
		duration: 100,
		transition: Fx.Transitions.Quad.easeOut
	},
	
	initialize: function(ele, options){
		if(!$chk(ele)) return false;
		this.obj = $(ele);
		this.setOptions(options);
		this.scroll = new Fx.Tween(this.obj, {
			'link': 'cancel',
			'duration': this.options.duration,
			'transition': this.options.transition
		});
		
		if(this.obj.getStyle('position') != 'relative') {
			this.obj.setStyle('position', 'relative');
		}
		
		window.addEvent('scroll', this.move.bind(this));
		
		// update now
		this.move();
	},
	
	move: function(){
		var min_top = 0;
		var max_top = this.options.bottom - this.options.top - this.obj.getSize().y - this.options.offset.top - this.options.offset.bottom;
		var new_top = window.getScroll().y - this.options.top + this.options.offset.top;
		
		if(new_top < min_top) {
			new_top = min_top;
		}
		if(new_top > max_top) {
			new_top = max_top;
		}
		
		this.scroll.start('top', new_top+'px');
	}
});


