
function CreateRequest()
{
    var Request = false;

    if (window.XMLHttpRequest)
    {
        //Gecko- , Safari, Konqueror
        Request = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        //Internet explorer
        try
        {
             Request = new ActiveXObject("Microsoft.XMLHTTP");
        }    
        catch (CatchException)
        {
             Request = new ActiveXObject("Msxml2.XMLHTTP");
        }
    }
 
    if (!Request)
    {
        alert("  XMLHttpRequest");
    }
    
    return Request;
} 

/*
      
r_method  -  : GET  POST
r_path    -   
r_args    -   a=1&b=2&c=3...
r_handler - -   
*/
function SendRequest(r_method, r_path, r_args, r_handler)
{
    // 
    var Request = CreateRequest();
    
    //    
    if (!Request)
    {
        return;
    }
    
    //  
    Request.onreadystatechange = function()
    {
        //   
        /*  readonly PRInt32 readyState
            The state of the request.
            Possible values:
                0 UNINITIALIZED open() has not been called yet.
                1 LOADING send() has not been called yet.
                2 LOADED send() has been called, headers and status are available.
                3 INTERACTIVE Downloading, responseText holds the partial data.
                4 COMPLETED Finished with all operations.
        */
        if (Request.readyState == 4)
        {
            /* readonly int status
               The status of the response to the request for HTTP requests.
               readonly AUTF8String statusText
               The string representing the status of the response for HTTP requests.
            */
            if (Request.status == 200)
            {
                //   
                r_handler(Request);
            }
            //else
            //{
            //    window.alert("Status = " + Request.status + " - " + Request.statusText);
            //}
        }
        //else
        //{
        //    window.alert("Ready state = " + Request.readyState);
        //}
    }
    
    //,    GET-
    if (r_method.toLowerCase() == "get" && r_args.length > 0)
    r_path += "?" + r_args;
    
    // 
    Request.open(r_method, r_path, true);
    
    if (r_method.toLowerCase() == "post")
    {
        //  POST-
        
        // 
        Request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
        // 
        Request.send(r_args);
    }
    else
    {
        //  GET-
        
        // -
        Request.send(null);
    }
} 

function ReadFile(filename, container)
{
    //   (Callback)
    var Handler = function(Request)
    {
    	//window.alert("called back");
        //WRONG: document.write("Responce = " + Request.responseText);
        document.getElementById('filmstrip').innerHTML = Request.responseText;
    }
    SendRequest("GET",filename,"",Handler);
} 

function Filmstrip(root, photo) {
	var container;
	ReadFile(root + "php/filmstrip.php?p=" + photo, container);
}

var Leftwards =	0x25;
var Rightwards = 0x27;
var Upwards = 0x26;

var prev_photo = "";
var next_photo = "";

function processKeyDown(event) {
	//window.alert(prev_photo + next_photo);
	if (window.event) event = window.event;
	if (event.ctrlKey) {
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null) {
		case Leftwards:
			Filmstrip(prev_photo);
			break;
		case Rightwards:
			Filmstrip(next_photo);
			break;
		case Upwards:
			document.location = '/photo';
			break; 
		}
	}
}

