var ScrollTrack = new Class({
	
	center:false,

	Implements: [Options,Events],
	options: { track: Array(), offset: -1 },

	initialize: function(options) {
		this.setOptions(options);
		if (this.options.track.length != null && this.options.track.length > 0) {
			if (this.options.offset == -1) { 
				this.options.offset = window.getSize().y/2;
				this.center = true;
			}
			window.addEvent('scroll',this.track.bind(this));
			window.addEvent('resize', function() {
				if (this.center) this.options.offset = window.getSize().y/2;
				this.track();
			}.bind(this));
		}
	},

	track: function() {
		var scroll = window.getScroll().y+this.options.offset;
		this.options.track.each(function(name) {
			var item = $(name);
			if (item) {
				try {
					var pos = item.getPosition().y;
					var size = item.getSize().y;
				} catch (e) {
					var pos = item.offsetParent.offsetParent.offsetTop;
					var size = item.offsetHeight;
				}
				if (scroll > pos && scroll < pos+size) {
					this.fireEvent('track',[item,true]);
				} else {
					this.fireEvent('track',[item,false]);
				}
			}
		},this);
	}

});
