//* SOME AJAX HELPER FUNCTION. WELL, NOT REALLY AJAX, BUT THE SAME PRINCIPLE
var http;		// THIS IS THE REQUEST OBJECT

//* UTILITY: CREATE THE OBJECT. SHOULD WORK ON IE AND MOZILLA
function AJAXcreateRequestObject() {
  var ro;

 	// Moz supports XMLHttpRequest. IE uses ActiveX.  
 	// browser detection is bad. object detection works for any browser  
 	
 	if (window.XMLHttpRequest) {
        ro = new XMLHttpRequest();
    } else {
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }
  return ro;
}

//* MAIN CODE
http = AJAXcreateRequestObject ();       

//* EVENT: SOME RESPONSE HAS BEEN RECEIVED FROM THE SERVER
function AJAXhandleResponse () {
  if (http.readyState != 4) return;

	try {
		Status = http.status;
	} catch (e) {
		Status = null;
	}	
	if (Status != 200) return;
		
if (http.responseText) {
	var Answer = eval('(' + http.responseText + ')');	
	var Status = Answer.Status;	
	if (Status == null) return;
	if (Status != 'OK') return;
} else {
	return;
}
	
}

//* SEND A REQUEST TO OUR DATABASE, CALL THE GIVEN CALLBACK ON SUCCESS
function AJAXsndReq (imagenumber1, imagenumber2, currentimagealpha, flashcounter) {

		http = null;		    
		http = AJAXcreateRequestObject ();       
		http.open ('get', 'continuity.php?imagenumber1=' + imagenumber1 + '&imagenumber2=' + imagenumber2 + '&currentimagealpha=' + currentimagealpha + '&flashcounter=' + flashcounter, true);
		http.onreadystatechange = AJAXhandleResponse;
		http.send (null);
}

// ***********************************************************************

// this function is called from the flash movie, every time the current image is halfway through fading, it receives the next image number
function storeImagestate(imagenumber1, imagenumber2, currentimagealpha, flashcounter) {
	// set the session for php
	AJAXsndReq (imagenumber1, imagenumber2, currentimagealpha, flashcounter);
}


