Type.registerNamespace("Graph");

/*
State loaded clicked
loding false false
loaded true false
click true true
error true false
request false false
*/

Graph.ActionLink = function (element) {
    this.loaded = false;
    this.clicked = false;

    this.timeout;
    this.pageLoaded;
    this.endRequest;
    this.beginRequest;

    this.timeout = Function.createDelegate(this, this.timeout);
    this.pageLoaded = Function.createDelegate(this, this.pageLoaded);
    this.endRequest = Function.createDelegate(this, this.endRequest);
    this.beginRequest = Function.createDelegate(this, this.beginRequest);

    Graph.ActionLink.initializeBase(this, [element]);
};

Graph.ActionLink.prototype =
{
    initialize: function()
    {
        Graph.ActionLink.callBaseMethod(this, "initialize");

        this._ctlA = jQuery(this.get_element());

        this._ctlA.click(Function.createDelegate(this, this.click));

        var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
        pageRequestManager.add_pageLoaded(this.pageLoaded);
        pageRequestManager.add_endRequest(this.endRequest);
        pageRequestManager.add_beginRequest(this.beginRequest);
        jQuery(document).ready(this.pageLoaded);
    },

    dispose: function()
    {
        var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
        pageRequestManager.remove_pageLoaded(this.pageLoaded);
        pageRequestManager.remove_endRequest(this.endRequest);
        pageRequestManager.remove_beginRequest(this.beginRequest);

        Graph.ActionLink.callBaseMethod(this, "dispose");
    },

    click: function(event)
    {
        if (this.loaded && this.clicked == false)
        {
            this.clicked = true;
            Graph.RaiseAction(this._ctlA);
            setTimeout(this.timeout, 500);
        }
    },

    timeout: function()
    {
        if (this.loaded)
        {
            this.clicked = false;
        }
    },

    pageLoaded: function(sender, args)
    {
        this.loaded = true;
    },

    endRequest: function(sender, args)
    {
        var error = args.get_error();
        if (typeof (error) != "undefined" && error != null)
        {
            this.loaded = true;
            this.clicked = false;
        }
    },

    beginRequest: function(sender, args)
    {
        this.loaded = false;
    }
};

Graph.ActionLink.registerClass("Graph.ActionLink", Sys.UI.Behavior);

if (typeof (Sys) != "undefined")
{
    Sys.Application.notifyScriptLoaded();
}
