function YearsInit() { Years.init(); }

var Years = {

	timer : null,
	elm : null,
	area : null,
	elmWidth : null,
	areaWidth : null,
	maxLeft : 0,
	
	init : function()
	{
		var menu = $('MenuYears');

		var topLine = menu.parentElement || menu.parentNode;
		
		var maxWidth = U.getWidth(topLine);
		maxWidth -= U.getWidth(topLine.children[1]);	
		maxWidth -= U.getWidth(topLine.children[3]);
					
		menu.style.width = maxWidth + 'px';
		
		if(isIE7) 
			$('YearsList').style.width = (maxWidth - 40) + 'px';
					
		this.elm = $('YearsInner');
		this.area = this.elm.parentElement || this.elm.parentNode;
		
		this.areaWidth = U.getWidth(this.area);
		
		var width = 0;
		var initLeft = 0;
		for(var i = 0; i < this.elm.children.length; i++)
		{
			if(this.elm.children[i].children[0].className.match(/active/))
				initLeft = -width;
			
			width += this.elm.children[i].offsetWidth;
		}
		
		this.elmWidth = width;						
		this.maxLeft = this.elmWidth - this.areaWidth;
		
		initLeft = Math.abs(initLeft) > this.maxLeft ? -this.maxLeft : initLeft;
		this.elm.style.left = initLeft + 'px';
	},
	
	move : function(direction)
	{
		if(this.elmWidth > this.areaWidth)
		{
			var setTimer = true;
			
			var posLeft = U.getInt(this.elm.style.left);
			var newLeft = posLeft + (direction == 'left' ? 2 : -2);
			
			if(Math.abs(newLeft) > this.maxLeft)
			{
				newLeft = -this.maxLeft;
				setTimer = false;
			}
			
			if(newLeft > 0)
			{
				newLeft = 0;
				setTimer = false;
			}
			
			this.elm.style.left = newLeft + 'px';
			
			if(setTimer)
				this.timer = setTimeout('Years.move("' + direction + '")', 25);			
		}		
	},
	
	stop : function()
	{
		clearTimeout(this.timer);	
	}
}

U.setEvent(window, 'onload', YearsInit);

