// XHTML live Communication
// author: alexander kohlhofer
// version: 1.0
// http://www.plasticshore.com
// http://www.plasticshore.com/projects/communication/
// please let the author know if you put any of this to use
// XHTML live Communication (including this script) is published under a creative commons license
// license: http://creativecommons.org/licenses/by-nc-sa/2.0/


var GetCommunicationurl = "live-functions.php";
window.onload = initJavaScript;
count = '1';

function initJavaScript() {
	receiveCommunicationText(); //initiates the first data query
}

//initiates the first data query
function receiveCommunicationText() {
	if (httpReceiveCommunication.readyState == 4 || httpReceiveCommunication.readyState == 0) {
  	//httpReceiveCommunication.open("GET",GetCommunicationurl + '?rand='+Math.floor(Math.random() * 1000000), true);
  	httpReceiveCommunication.open("GET",GetCommunicationurl, true);
    httpReceiveCommunication.onreadystatechange = handlehHttpReceiveCommunication; 
  	httpReceiveCommunication.send(null);
	}
}

//deals with the servers' reply to requesting new content
function handlehHttpReceiveCommunication() {
  if (httpReceiveCommunication.readyState == 4) {
    results = httpReceiveCommunication.responseText.split('---'); //the fields are seperated by ---
	    	insertNewContent(results[0], results[1]); //inserts the new content into the page
    setTimeout('receiveCommunicationText();',10000); //executes the next data query in 10 seconds
  }
}

//inserts the new content into the page

function insertNewContent(liScreen, video) {
	document.getElementById('leftscreen').innerHTML = liScreen;
	
	currentstate = document.getElementById('state').innerHTML;
	if (currentstate == video) { } else {
	if (video == 299) {
				
		document.getElementById('video23').innerHTML = '<div id="video_container"><div id="lcm_video" style="font-color: #fff;">The video will start in:<div id="lcm_simlive_countdown"></div></div></div>';
		lcm_console_init();
	document.getElementById('state').innerHTML = video;		
		} else {
					
		document.getElementById('video23').innerHTML = '<div style="margin: -24px 0 0 0px;"><div id="myAlternativeContent"></div></div>';
		loadSWF();
		document.getElementById('state').innerHTML = video;
		}
	}
	}

//initiates the XMLHttpRequest object
//as found here: http://www.webpasties.com/xmlHttpRequest
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;
}


// initiates the two objects for sending and receiving data
var httpReceiveCommunication = getHTTPObject();