var rotation;
var last_rotation;

var left_over = new Image();
var px_over = new Image();
var right_over = new Image();

function setLoginFocus() {
	var email = eval(doc + 'email' + doc2);
	var passwd = eval(doc + 'passwd' + doc2);

	if (email.value == '') {
		email.focus();
	} else {
		passwd.focus();
	}
}

function startRotation(bg_color) {
	last_rotation = 0;

	left_over.src = "http://localhost" + sccc_path + "includes/images/buttons/big_buttons/left_" + bg_color + "_over.jpg";
	px_over.src = "http://localhost" + sccc_path + "includes/images/buttons/big_buttons/1px_" + bg_color + "_over.jpg";
	right_over.src = "http://localhost" + sccc_path + "includes/images/buttons/big_buttons/right_" + bg_color + "_over.jpg";
	
	rotation = setTimeout("cycleButtons(0, '" + bg_color + "', true)", 5000);
}

function cycleButtons(active_num, bg_color, cycle) {
	detail = eval(doc + "upgrade_details_div" + doc2);

	if (cycle) {
		cur_num = (active_num % 4);
		next_num = ((active_num + 1) % 4);
	
		cur_num = (next_num == 1 && last_rotation == 3) ? 3 : cur_num;
		
		if (next_num != 0) {
			next_button_tbl = eval(doc + 'button_' + next_num + '_tbl' + doc2);
		} else {
			next_num = 1;
			next_button_tbl = eval(doc + 'button_' + next_num + '_tbl' + doc2);
		}
		
		if (cur_num != 0) {	
			cur_button_tbl = eval(doc + 'button_' + cur_num + '_tbl' + doc2);	
		} else {
			cur_num = 3;
			next_num = 1;
				
			cur_button_tbl = eval(doc + 'button_' + cur_num + '_tbl' + doc2);
			next_button_tbl = eval(doc + 'button_' + next_num + '_tbl' + doc2);
		}
		
		rotation = setTimeout("cycleButtons(" + next_num + ", '" + bg_color + "', true)", 3000);
	} else {
		clearTimeout(rotation);
		
		cur_num = (last_rotation == 0) ? 3 : last_rotation;
		next_num = active_num;
		
		cur_button_tbl = eval(doc + 'button_' + cur_num + '_tbl' + doc2);
		next_button_tbl = eval(doc + 'button_' + next_num + '_tbl' + doc2);
	}
	
	cur_button = cur_button_tbl.getElementsByTagName('td');
	next_button = next_button_tbl.getElementsByTagName('td');
	
	cur_button[0].style.backgroundImage = "url('http://localhost" + sccc_path + "includes/images/buttons/big_buttons/left_" + bg_color + ".jpg')";
	cur_button[1].style.backgroundImage = "url('http://localhost/smartsite/includes/images/buttons/big_buttons/1px_" + bg_color + ".jpg')";
	cur_button[2].style.backgroundImage = "url('http://localhost/smartsite/includes/images/buttons/big_buttons/right_" + bg_color + ".jpg')";
		
	next_button[0].style.backgroundImage = "url('http://localhost" + sccc_path + "includes/images/buttons/big_buttons/left_" + bg_color + "_over.jpg')";
	next_button[1].style.backgroundImage = "url('http://localhost" + sccc_path + "includes/images/buttons/big_buttons/1px_" + bg_color + "_over.jpg')";
	next_button[2].style.backgroundImage = "url('http://localhost" + sccc_path + "includes/images/buttons/big_buttons/right_" + bg_color + "_over.jpg')";

	txt = eval(doc + "upgrade_txt" + next_num + "_div" + doc2);

	detail.innerHTML = txt.innerHTML;
	
	last_rotation = next_num;
}

