var services;
function Services()
{	
	this.menu = $('menuFixed');
	this.holder = $('servicesContentHolder');
	this.pe = new PeriodicalExecuter(this.checkPositon.bind(this, null), 0.1);
	
	this.animation = null;    //pohyb menu na cielovu poziciu
	this.previousPostion = 0; //predch. nascrolovana pozicia
	this.inactiveTime = 0;
	this.inactiveTimeTreshold = 0; //necinnost po scrolovani
} 

Services.prototype.checkPositon = function()
{
	var scrollOffsets = document.viewport.getScrollOffsets();
	if(scrollOffsets.top != this.previousPostion)
	{
		this.inactiveTime = 0;
		if(this.animation)
		{
			this.animation.cancel();
			this.animation = null;
		}
	}
	else
	{
		this.inactiveTime++;
	}
	this.previousPostion = scrollOffsets.top;
	
	if(this.inactiveTime > this.inactiveTimeTreshold)
	{
		this.moveMenu();
	}
	
	
}

Services.prototype.moveMenu = function()
{
	if(this.animation) return;
	
	var newPosition = this.previousPostion - 70;
	newPosition = newPosition > 0 ? newPosition : 0;
	newPosition = Math.min(newPosition, this.holder.getHeight() - this.menu.getHeight() - 20);
	if(!this.menu.style.top || parseInt(this.menu.style.top) != newPosition)
	{
		var oldPosition = this.menu.style.top ? parseInt(this.menu.style.top) : 0;
		var duration = Math.abs(oldPosition - newPosition) / 1000;
		duration = Math.max(duration, 0.2);
//		this.animation = new Effect.Move(this.menu.identify(), { y: newPosition, mode: 'absolute', duration: duration, fps: 30, transition: Effect.Transitions.sinoidal });
		this.menu.style.top = newPosition + "px";
	}
	
}

Services.prototype.goToItem = function(id)
{
	if(this.scrolling) return;
	Effect.ScrollTo(id, {duration: 0.5, offset: 0});
}




