var VDrifter = Class.create();
VDrifter.prototype = {
  initialize: function(element, upBT, downBT) {
    this.element = $(element);
	this.visibleArea = $(this.element.parentNode.id);
	this.upEl = $(upBT);
	this.downEl = $(downBT);
	this.speed = 20; //one px per X milliseconds.
	this.element.setStyle({position: 'relative'});
	
	//this.element.setStyle({top: '0px'});
	
	this.allLinks = getElementsByClassName(this.element, 'a', "current");
	if(this.allLinks.length == 1){
		this.current = $(this.allLinks[0]);
		var outerpos = this.element.cumulativeOffset();
		var pos = this.current.cumulativeOffset();
		pos[0] -= outerpos[0];
		pos[1] -= outerpos[1];
		pos[0] -= this.visibleArea.getWidth()/2;
		//pos[0] *= -1;
		pos[1] *= -1;
		//new Effect.Move(this.element.id, {x:0, y:pos[1], mode: 'relative'});
	}
	
    this.eventGoup = this.startScrollup.bindAsEventListener(this);
	this.eventGodown = this.startScrolldown.bindAsEventListener(this);
    
    Event.observe(this.upEl, 'mouseover', this.eventGoup);
	Event.observe(this.downEl, 'mouseover', this.eventGodown);
	Event.observe(this.upEl, 'mouseout', this.doneScroll);
	Event.observe(this.downEl, 'mouseout', this.doneScroll);
  },
  destroy: function() {
    Event.stopObserving(this.upEl, 'mouseover', this.eventGoup);
	Event.stopObserving(this.downEl, 'mouseover', this.eventGodown);
  },
  startScrollup: function(event) {
	  drift(this.element.id, 'top', 3, this.speed);
  },
  startScrolldown: function(event) {
	  drift(this.element.id, 'top', -3, this.speed)
  },

  doneScroll: function(){
	stopDrift();
  }
}

function drift(el_id, attrib, direction, speed){
	element = $(el_id);
	pos = element.positionedOffset();
	switch(attrib){
		case 'top':
		xy_to = (pos[1] + direction) +'px';
		element.style['top'] = xy_to;
		break;
		case 'left':
		xy_to = (pos[0] + direction) +'px';
		element.style['left'] = xy_to;
		break;
	}

	t=setTimeout('drift("'+ el_id +'","'+ attrib +'",'+ direction +','+ speed +')',speed);
}

function stopDrift(){
	clearTimeout(t);
}
