loginStatus = "closed";
loginHeight = 0;

function showLogin() {
	if (loginStatus == "closed") {
		loginStatus = "in transit";
		loginHeight = 1;
		openLoginLoop=setInterval("openLogin()",100);
	}
	if (loginStatus == "opened") {
		loginStatus = "in transit";
		loginHeight = 27;
		closeLoginLoop=setInterval("closeLogin()",100);
	}
}

function openLogin() {

	if (loginHeight == 0) {loginHeight = 1}
	else if (loginHeight == 1) {loginHeight = 2}
	else if (loginHeight == 2) {loginHeight = 3}
	else if (loginHeight == 3) {loginHeight = 5}
	else if (loginHeight == 5) {loginHeight = 8}
	else if (loginHeight == 8) {loginHeight = 12}
	else if (loginHeight == 12) {loginHeight = 17}
	else if (loginHeight == 17) {loginHeight = 21}
	else if (loginHeight == 21) {loginHeight = 24}
	else if (loginHeight == 24) {loginHeight = 26}
	else if (loginHeight == 26) {loginHeight = 27}

	if (loginHeight >= 27) {
		document.getElementById("login").style.height = loginHeight;
		clearInterval(openLoginLoop);
		loginStatus = "opened";
	} else {
		document.getElementById("login").style.height = loginHeight;
	}
}

function closeLogin() {
	
	if (loginHeight == 27) {loginHeight = 26}
	else if (loginHeight == 26) {loginHeight = 24}
	else if (loginHeight == 24) {loginHeight = 21}
	else if (loginHeight == 21) {loginHeight = 17}
	else if (loginHeight == 17) {loginHeight = 12}
	else if (loginHeight == 12) {loginHeight = 8}
	else if (loginHeight == 8) {loginHeight = 5}
	else if (loginHeight == 5) {loginHeight = 3}
	else if (loginHeight == 3) {loginHeight = 2}
	else if (loginHeight == 2) {loginHeight = 1}
	else if (loginHeight == 1) {loginHeight = 0}
	
	if (loginHeight <= 0) {
		document.getElementById("login").style.height = 1;
		clearInterval(closeLoginLoop);
		loginStatus = "closed";
	} else {
		document.getElementById("login").style.height = loginHeight;
	}
}





//////////////////////////////////////////////////////
// AJAX
var http = getHTTPObject(); // We create the HTTP Object
var isWorking = false;

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}


// CHAT NOTIFICATION
var lastId = 0;
function handleHttpResponse() {
	if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
			results = http.responseText.split("***SPLIT***");
			if (results[0] != lastId) {
				document.getElementById('updateChatDiv').style.display = "inline";
				document.getElementById('updateChatMessage').innerHTML = "<div style='float:left;padding:3px 8px 5px 0px;'><img width='24' height='24' border='0' src='/avatars/"+results[3]+"'></div><div style='padding-bottom:3px;'>"+results[2]+"</div><div style='float:right;font-size:9;font-style:italic;padding-bottom:3px;'>- "+results[1]+"</div><br style='clear:both;'><center><a href='chat.html' style='color:#7d7e7f;'>click to chat</a></center>";;
			}
			if (results[1]) {
			} else {
				document.getElementById('updateChatDiv').style.display = "none";
			}
//			alert ("results = " + results[0] + " - lastId = " + lastId);
			lastId = results[0];
			isWorking = false;
			setTimeout('updateChat();',5000); //executes the next data query in 5 seconds
		}
	}
}

function updateChat() {
	if (!isWorking && http) {
//		document.getElementById('updateChatDiv').style.display = "none";
		var random = Math.round(1000000*Math.random());
		http.open("GET", "updateChat_ajax.html?random="+random, true);
		http.onreadystatechange = handleHttpResponse;
		isWorking = true;
		http.send(null);
	}
}