var onload_overlay_type = '';
var onload_jsfunction = function(){}
var line_number = 1;
var sudo_user = "voltron";

function adjustOverlay() {
	//var content_height = parseInt(YAHOO.util.Dom.getStyle($('content_container'), 'height'), 10);
	//var content_height = $('content_container').offsetHeight;
	var window_height = getWindowHeight();
	var content_height = $('content_container').offsetHeight;

	if (window_height > content_height) $$('overlay').height = (window_height + "px");
	else $$('overlay').height = (content_height + "px");
		
}

function fullScreen() {
	var window_height = getWindowHeight();
	var content_height = $('content_container').offsetHeight;
	if (content_height < window_height) {
		$$('content_container').height = (window_height + "px");
		$$('footer_container').position = "absolute";
		adjustShadows();
		adjustOverlay();
	}
}

function flexibleScreen() {
	$$('content_container').height = "auto";
	$$('footer_container').position = "relative";
	adjustShadows();
	adjustOverlay();
	
	fullScreen();
}

function turnOnOverlay() {
	$$('overlay').visibility = "visible";
	$$('overlay_content_outer').visibility = "visible";
}

function turnOnSignupOverlay() {
	centerSpecialSignupOverlay();
	$$('overlay').visibility = "visible";
	$$('overlay_signup_content_outer').visibility = "visible";
}

function turnOffOverlay() {
	$$('overlay').visibility = "hidden";
	$$('overlay_content_outer').visibility = "hidden";
	$$('overlay_signup_content_outer').visibility = "hidden";
}

function turnOffStandardOverlay() {
	$$('overlay_content_outer').visibility = "hidden";
}


function turnOffOverlayTimed() {
	var default_delay_time = 3000;
	var timer = setTimeout(function(){turnOffOverlay();},default_delay_time);
}



function focusInput(element,row_height) {
	var black_position = "0px";
	var gray_position = ("-" + row_height + "px");
	var white_position = ("-" + (row_height * 2) + "px");
	if (element.value != "") element.style.backgroundPosition = ("0px " + white_position);
	else element.style.backgroundPosition = ("0px " + gray_position);
}

function blurInput(element,row_height) {
	var black_position = "0px";
	var gray_position = ("-" + row_height + "px");
	var white_position = ("-" + (row_height * 2) + "px");
	if (element.value != "") element.style.backgroundPosition = ("0px " + white_position);
	else element.style.backgroundPosition = ("0px " + black_position);
}

function blankInput(event,element,row_height) {
	var black_position = "0px";
	var gray_position = ("-" + row_height + "px");
	var white_position = ("-" + (row_height * 2) + "px");
	var keynum;
	if(window.event) { // IE
		keynum = event.keyCode;
	} else if(event.which) { // Netscape/Firefox/Opera
		keynum = event.which;
	}
	
	if (element.value.length <= 1) {
		if (keynum == 8) element.style.backgroundPosition = ("0px " + gray_position);
		else element.style.backgroundPosition = ("0px " + white_position);
	} else if (element.value != "") element.style.backgroundPosition = ("0px " + white_position);
	else element.style.backgroundPosition = ("0px " + gray_position);
}




function centerOverlay() {
	verticallyCenterElement('overlay_content_outer',343);
}


function centerBGLogo() {
	centerElement('bg_logo',900,369);
}


function checkTerminalEnter(event){ 
	var keynum;
	if(window.event) { // IE
		keynum = event.keyCode;
	} else if(event.which) { // Netscape/Firefox/Opera
		keynum = event.which;
	}

	if(keynum == 13){ //if generated character code is equal to ascii 13 (if enter key)
		return doResponse(); //submit the form
	} else {
		return true;
	}
}

function doResponse() {
	line_number++;
	var command = getCommand();
	var command_args = getCommandArgs();
	switch(command) {
		case('sudo'):
			sudo_user = command_args;
			$('command_line').value += ("\r" + line_number + ":~ " + sudo_user + "$ ");
			break;
		case('help'):
			$('command_line').value += ("\rType sudo to change user\r" + line_number + ":~ " + sudo_user + "$ ");
			break;
		default:
			$('command_line').value += ("\rReally? You're a dumb jerk. Maybe try being smart next time. Type help to be coddled.\r" + line_number + ":~ " + sudo_user + "$ ");
			break;
	}
	return false;
}

function getCommandLine() {
	var last_line_start = $('command_line').value.lastIndexOf("\n");
	var last_line = $('command_line').value.substring(last_line_start, $('command_line').value.length);
	var command_line_start = last_line.indexOf('$ ') + 2;
	var command_line = last_line.substring(command_line_start, last_line.length);
	return command_line;
}

function getCommand() {
	var command_line = getCommandLine();
	var command_end = command_line.indexOf(' ');
	if (command_end < 0) command_end = command_line.length;
	var command = command_line.substring(0,command_end);
	return command;
}

function getCommandArgs() {
	var command_line = getCommandLine();
	var command_args_start = command_line.indexOf(' ') + 1;
	var command_args = command_line.substring(command_args_start, command_line.length);
	return command_args;
}