
var buttons = new Array();
var buttonSpeed = 40;
var buttonMax = 10;
var buttonAnimTimer = null;

function setOpacity(item, opacity){
	opacity = 1 - opacity;
	item.style.opacity = opacity;
	item.style.filter = 'alpha(opacity='+(opacity*100)+')';
}

function buttonMove() {
	run = false;
	for (id in buttons){
		var button = document.getElementById(id);
		var b = buttons[id];
		
		if (b.orientation != 0){
			b.position += b.orientation;
			if (b.position <= 0){
				b.position = 0;
				b.orientation = 0;
			} else if (b.position >= buttonMax){
				b.position = buttonMax;
				b.orientation = 0;
			} else {
				run = true;
			}
		}	
		setOpacity(button,b.position / 20);
		button.style.marginLeft = (b.position)+'px';
		button.style.marginRight = (-b.position)+'px';
	}
	if (!run) {
		clearInterval(buttonAnimTimer);
		buttonAnimTimer = null;
	}
}

function highlightButton(button, selected) {
	if (!buttons[button.id]) buttons[button.id] = {orientation: 0, position: 0};
	var b = buttons[button.id];
	if (selected){
		b.orientation = 1;
	} else {
		b.orientation = -1;
	}
	if (buttonAnimTimer == null)
		buttonAnimTimer = setInterval('buttonMove()', buttonSpeed);
}

