/*
To use this you will need to ensure that your page has references to this file and Helper.js.
You can then instanciate the class using the required values.
*/

function ShowProgress(progressImage, buttonControl, hasEvents)
{
    var me = this;

    // Set up prpoerties
    this.ProgressImage = document.getElementById(progressImage);
    this.ButtonControl = document.getElementById(buttonControl);
    this.HasEvents = hasEvents;
    this.UseAbsolute = true;
    
    this.showProgress = function()
    {
	    // Display the progress image
	    me.showProgressImage();
    }
    
    this.Initialise = function()
    {
        // Set window event if required
        if (this.HasEvents)
            addEvent(window, "beforeunload", this.showProgress);
    }
    
    this.Initialised = this.Initialise();
}

ShowProgress.prototype.showProgressImage = function()
{
    if (this.UseAbsolute == true)
    {
        // Display progress image first
        this.ProgressImage.style.zIndex = '999';
	    this.ProgressImage.style.position = 'absolute';
        
        // Absolutely position the image
        var xPos = getAscendingLefts(this.ButtonControl, false);
        var yPos = getAscendingTops(this.ButtonControl, false);
        
        // Work out offset of the image
        var middlePos = parseInt(this.ButtonControl.offsetWidth / 2);
        var xOffset = middlePos - parseInt(this.ProgressImage.offsetWidth / 2);
        
        // Set progress image position
        this.ProgressImage.style.top = yPos + 'px';
        this.ProgressImage.style.left = (xPos + xOffset) + 'px';
    }
    
    // Hide the button
    this.ButtonControl.style.display = 'none';
    
    // Display progress image first in order to work out margin
    this.ProgressImage.style.display = 'block';

    // Cause animated gif to reload and start animation 
    var imgSrc = this.ProgressImage.src;
    setTimeout("document.getElementById('" + this.ProgressImage.id + "').src = '" + imgSrc + "'", 0);
}