Type.registerNamespace("ROS");

ROS.UpdateIndicator = function(referenceElement)
{
    ROS.UpdateIndicator.initializeBase(this, [referenceElement]);
    
    var indicatorImg;
    var indicatorBg;
    
    this.get_referenceElement = function()
    {
        return referenceElement;
    }
    this.set_referenceElement = function(value)
    {
        referenceElement = value;
    }

    this.dispose = function()
    {
        if (referenceElement)
        {
            indicatorImg = null;
            indicatorBg = null;
            referenceElement = null;
        }

        ROS.UpdateIndicator.callBaseMethod(this, "dispose");
    }

    this.getDescriptor = function()
    {
        var td = ROS.UpdateIndicator.callBaseMethod(this, "getDescriptor");
        return td;
    }

    this.initialize = function()
    {
        ROS.UpdateIndicator.callBaseMethod(this, "initialize");
        
        indicatorImg = document.getElementById(referenceElement.id + "_IndicatorImg");
        indicatorBg = document.getElementById(referenceElement.id + "_IndicatorBg");
        
        SetSizeAndPositions();
        
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_beginRequest(BeginRequestHandler);
        prm.add_endRequest(EndRequestHandler);
        
        if (window.addEventListener)//Firefox
        {
            window.addEventListener("resize", SetSizeAndPositions, false);
        }
        else if (window.attachEvent)//IE
        {
            window.attachEvent("onresize", SetSizeAndPositions);
        }
    }
    
    function BeginRequestHandler(sender, args)
    {
        indicatorBg.setAttribute("showing", "true");
        setTimeout(ShowIndicator,1);
    }
    function EndRequestHandler(sender, args)
    {
        HideIndicator();
    }
    function ShowIndicator()
    {
        if (indicatorBg.getAttribute("showing") == "true")
        {
            indicatorImg.style.display = "";
            indicatorBg.style.display = "";
        }
    }
    function HideIndicator()
    {
        indicatorImg.style.display = "none";
        indicatorBg.style.display = "none";
        indicatorBg.setAttribute("showing", "false");
    }
    
    function SetSizeAndPositions()
    {
        var bodyWidth = document.documentElement.clientWidth;
        var bodyHeight = document.documentElement.clientHeight;

        indicatorImg.style.top = ((bodyHeight/2)-8) + "px";
        indicatorImg.style.left = ((bodyWidth/2)-107) + "px";
        indicatorBg.style.width = bodyWidth + "px";
        indicatorBg.style.height = bodyHeight + "px";
    }
}
ROS.UpdateIndicator.registerClass("ROS.UpdateIndicator", Sys.UI.Behavior);
if (Sys && Sys.Application) { Sys.Application.notifyScriptLoaded(); }
