// JavaScript Document
var buttons = window.document.getElementById("buttons");
var panels = window.document.getElementById("panels");
selected = 0;
y = 0;
x = 0;
target = 0;
animate_loop = '';
automate_loop = '';
panel_loop = '';
action = '';

for(x=0; x<3; x++) {
	var btn = buttons.getElementsByTagName('a')[x];
	btn.onclick = function(){
		panel_clicker(this.id);
	}
	buttons.getElementsByTagName('a')[x].removeAttribute('href');
}
buttons.getElementsByTagName('li')[0].className = "selected";

if(automate_loop!='') clearInterval(automate_loop);
automate_loop = setInterval("automate()",3500);

function automate() {
	var top = parseInt(panels.style.top);
	if(top>=0) {
		value = 'btn-lowcost';
		target = -314;
	}
	if((top<=-314)&&(top>-628)) {
		value = 'btn-billing';
		target = -628;
	}
	if(top<=-628) {
		value = 'btn-free';
		target = 0;
	}
	panel_loop = setTimeout("scroll_panel('"+value+"')",3500);
}

function panel_clicker(value) {
	clearInterval(automate_loop);
	clearTimeout(panel_loop);
	scroll_panel(value);
	automate_loop = setTimeout("automate()",5000);
}

function scroll_panel(value) {
	clearTimeout(panel_loop);
	for(x=0;x<3;x++) buttons.getElementsByTagName('li')[x].className = "";
	if(value=='btn-free') {
		target = 0;
		buttons.getElementsByTagName('li')[0].className = "selected";
	}
	if(value=='btn-lowcost') {
		target = -314;
		buttons.getElementsByTagName('li')[1].className = "selected";
	}
	if(value=='btn-billing') {
		target = -628;
		buttons.getElementsByTagName('li')[2].className = "selected";
	}
	panel_loop = setTimeout("animate("+target+")",1);
	action = '';
}

function animate(target) {
	clearTimeout(animate_loop);
	current = parseInt(panels.style.top);
		if(action!='movedown') {
			if(current<target) {
				if(!action) action = 'moveup';
				y = y+7;
				panels.style.top = y+'px';
			} else {
				panels.style.top = target+'px';
			}
		}
	
		if(action!='moveup') {
			if(current>target) {
				if(!action) action = 'movedown';
				y = y-7;
				panels.style.top = y+'px';
			} else {
				panels.style.top = target+'px';
			}
		}

	if((target>0)||(target<-628)) {
		panels.style.top = 0;
		target = -314;
	}
	animate_loop = setTimeout("animate("+target+")",1);
}
