﻿function ScrollManager_Track(elementSelector, hiddenFieldId) {
	$(elementSelector).scroll(function () {
		$('#' + hiddenFieldId + ':hidden').val($(this).scrollLeft() + ',' + $(this).scrollTop());
	});

	// this prevents ajax from maintaining scroll position
	if (window.Sys && Sys.WebForms) {
		Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(function () {
			Sys.WebForms.PageRequestManager.getInstance()._scrollPosition = null;
		});
	}
}

function ScrollManager_Restore(elementSelector, hiddenFieldId) {
	var $el = $(elementSelector);
	var pos = $('#' + hiddenFieldId + ':hidden').val().split(',');

	$el.scrollLeft(parseInt(pos[0], 10));
	$el.scrollTop(parseInt(pos[1], 10));

	// DOM ready may fire prior to window load.  In IE this means no
	// scrolling occurs, so wait for the window load event and try again.
	$(window).bind("load", function () {
		$el.scrollLeft(parseInt(pos[0], 10));
		$el.scrollTop(parseInt(pos[1], 10));
	});
}

