/**
 * scrollObj object definition
 *
 * used to store data about the position and status of the window's scrolling
 * also contains a reference to the window object.
 */
function scrollObj()
{
    this.win = window;
    this.xTarget = 0;
    this.yTarget = 0;
    this.slideTime = 0;
    this.stop = false;
    this.moving = false;
    this.yA = 0;
    this.xA = 0;
    this.yD = 0;
    this.xD = 0;
    this.B = 0;
    this.C = 0;
}
// create a new scrollObj object
var so = new scrollObj();
/**
 * xSlideTo
 *
 * main scrolling function called from the page, which slides the window to
 * its destination.
 * @param integer x coordinate of the new window position
 * @param integer y coordinate of the new window position
 * @param integer uTime duration of the scrolling operation
 */
function xSlideTo(x,y,uTime) {
    if (!so.timeout) {
        so.timeout = 25;
    }
    so.xTarget = x;
    so.yTarget = y;
    so.slideTime = uTime;
    so.stop = false;
    so.yA = so.yTarget - xScrollTop();
    so.xA = so.xTarget - xScrollLeft(); // A = distance
    so.B = Math.PI / (2 * so.slideTime); // B = period
    so.yD = xScrollTop();
    so.xD = xScrollLeft(); // D = initial position
    var d = new Date();
    so.C = d.getTime();
    if (!so.moving) {
        xSlide();
    }
}
/**
 * xSlide
 *
 * main function used to scroll the window. Called initially by xScrollTo after
 * all the scrollObj properties have been set, then called using a setTimeout
 * to animate (slide) the window into position.
 */
function xSlide() {
    var now, s, t, newY, newX;
    now = new Date();
    t = now.getTime() - so.C;
    if (so.stop) {
        so.moving = false;
    } else if (t < so.slideTime) {
        setTimeout("xSlide()", so.timeout);
        s = Math.sin(so.B * t);
        newX = Math.round(so.xA * s + so.xD);
        newY = Math.round(so.yA * s + so.yD);
        so.win.scrollTo(newX, newY);
        so.moving = true;
    } else {
        so.win.scrollTo(so.xTarget, so.yTarget);
        so.moving = false;
    } 
}
/**
 * utility functions taken from the x library (http://www.cross-browser.com)
 * Copyright (c) 2004 Michael Foster, Licensed LGPL (gnu.org)
 */
function xScrollLeft() {
    var offset = 0;
    if (document.documentElement && document.documentElement.scrollLeft) {
        offset = document.documentElement.scrollLeft;
    } else if (document.body && xDef(document.body.scrollLeft)) {
        offset = document.body.scrollLeft;
    }
    return offset;
}
function xScrollTop() {
    var offset=0;
    if (document.documentElement && document.documentElement.scrollTop) {
        offset = document.documentElement.scrollTop;
    } else if (document.body && xDef(document.body.scrollTop)) {
        offset = document.body.scrollTop;
    }
    return offset;
}
