﻿function slLoad(sender) {
    var run = Function.createDelegate(historyInstance, historyInstance.init);
    run(sender);
}


historyManager = function() {
    this._silverlightControl = null;
    this._sHM = null;
}

historyManager.prototype = {
    init: function(sender) {
        //the sender variable contains a reference to the Silverlight object.
        //get it and store it in a local variable
        this._silverlightControl = sender;
        //get and store a reference to the silverlightHistoryManager managed object
        //exposed from Silverligt using RegisterScriptableObject
        this._sHM = this._silverlightControl.Content.silverlightHistoryManager;
        //pass "this" object in to the Silverlight application so it may call back to 
        //register history events.
        this._sHM.SetJSHistoryObject(this);
    },
    navigationEventHandler: function(sender, args) { //This method will be called by ASP.NET AJAX when the user uses the back and forward buttons.
        if (this._sHM != null) {
            this._sHM.LoadPoint(sender, args.get_state().data);
        }
    },
    addHistPoint: function(pointData, pageTitle) { //This method is called from Silverlight to add a new history point.
        Sys.Application.addHistoryPoint({ data: pointData }, pageTitle);
    }
}

//Instantiate the historyManager. 
var historyInstance = new historyManager();

//Create a delegate to preserve scope when the navigation event handler fires.
var handler = Function.createDelegate(historyInstance, historyInstance.navigationEventHandler);

//Add the delegate tot he add_navigate event. This will cause the navigationEventHandler method of 
//historyManager to fire when the user uses the back and forward buttons in the browser.
Sys.Application.add_navigate(handler);