function Ajax(onload, url,method,params,contentType)
{        
    this.req = null;
    this.onload = onload;
    
	this.InitRequestObject();
    this.InitXMLHttpRequest(url, method, params, contentType);
}

Ajax.prototype = 
{
    READY_STATE_UNINITIALIZED : 0,
    READY_STATE_LOADING       : 1,
    READY_STATE_LOADED        : 2,
    READY_STATE_INTERACTIVE   : 3,
    READY_STATE_COMPLETE      : 4,
        
	InitRequestObject : function()
	{
		if (window.XMLHttpRequest) 
        {
            this.req = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            try
            {
                this.req = new ActiveXObject("Msxml2.XMLHTTP");
            }
            
            catch (err)
            {
                this.req = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }	
	},
	
    InitXMLHttpRequest : function(url, method, params, contentType)
    {
        if (! method) 
        {
            method = "GET";
        }
        
        if (! contentType && method == "POST") 
        {
            contentType = "application/x-www-form-urlencoded";
        }               
        
        if (this.req)
        {            
            try 
            {                    
                var loader = this;
                this.req.onreadystatechange = function()
                {
                    loader.onReadyStateChange.call(loader);    
                }
                
                this.req.open(method, url, true);
                
                if (contentType) 
                {
                    this.req.setRequestHeader("Content-Type", contentType);
                }
                                    
                this.req.send(params);
            }
            
            catch (err)
            {
                alert(err);
            }
        }
    },
    
    onReadyStateChange : function()
    {        
        var req = this.req;            
        
        if (req.readyState == this.READY_STATE_COMPLETE) {            
            if (req.status == 200 || req.status == 0)                
            {                
                this.onload.call(this); 
            }
            else
            {
                alert("Error, status = " . req.status);
            }                
        }            
    },

    getXMLDocument : function ()
    {
        var xDoc = null;
        
        if (document.implementation && document.implementation.createDocument)
        {
            xDoc = document.implementation.createDocument("", "", null);
        }
        else if (typeof ActiveXObject != "undefined")
        {
            var msXmlAx = null;
            
            try
            {
                msXmlAx = new ActiveXObject("Msxml2.DOMDocument");
            }
            catch (err)
            {
                msXmlAx = new ActiveXObject("Msxml.DOMDocument");
            }
            
            xDoc = msXmlAx;
        }
    
        if (xDoc == null || typeof xDoc.load == "undefined")
        {
            xDoc = null;
        }
        
        return xDoc;
    }                      
};

var img = null;
var SlideShowID = 0;

function callback()
{
    var result = this.req.responseText.split("|");
	img.src = result[0];		
	SlideShowID = result[1];
}

function SetRandomImage(imageID){
	img = document.getElementById(imageID);
	
	setInterval ( "GetRandomImage();", 2000 );		
}

function GetRandomImage()
{	
	var ajax = new Ajax(callback, "GetRandomPic.php?id=" + SlideShowID, "GET");
}
