/*******************************************************************************
Cross Browser Support
*******************************************************************************/

function nn4_getElementById(id) { return document[id]; }
function ie_getElementById(id) { return document.all[id]; }
function nn6_getElementById(id) { return document.getElementById(id); }
function nn4_getIdStyle(id) { return document[id]; }
function ie_getIdStyle(id) { return document.all[id].style; }
function nn6_getIdStyle(id) { return document.getElementById(id).style; }

var cb_getElementById = null;
var cb_getIdStyle = null;

if (document.layers)
{
    cb_getElementById = nn4_getElementById;
    cb_getIdStyle = nn4_getIdStyle;
}

if (document.all)
{
    cb_getElementById = ie_getElementById;
    cb_getIdStyle = ie_getIdStyle;
}

if (!document.all && document.getElementById)
{
    cb_getElementById = nn6_getElementById;
    cb_getIdStyle = nn6_getIdStyle;
}

/*******************************************************************************
Object Constuctors
*******************************************************************************/

function slidingMenu()
{
    this.menus = new Array;
    /*
    The total sliding distance is the product of the stepSize and numOfSteps
    variables. If the number of steps is too low the sliding may become jerky.
    However, is the number of steps is too high the sliding may become too slow.
    */
    this.stepSize = 6;
    this.numOfSteps = 19;
    this.slidingDist = this.stepSize * this.numOfSteps;
    this.isSliding = 0;
    this.upStepNum = 0;
    this.upMenu = null;
    this.upTimer = null;
    this.downStepNum = 0;
    this.downMenu = null;
    this.downTimer = null;
    this.openedMenu = null;
    this.name = "slidingMenuVar";
    eval(this.name + " = this");

    this.addMenu = addMenu;
    this.openMenu = openMenu;
    this.stepUp = stepUp;
    this.stepDown = stepDown;
    this.slideMenu = slideMenu;
}

/*******************************************************************************
Funtions
*******************************************************************************/

function addMenu(id)
{
    this.menus[this.menus.length] = cb_getIdStyle(id);
}

function openMenu(num)
{
    if (this.isSliding > 0)
        return;

    if (this.openedMenu == num)
    {
        return;
    }

    if (this.openedMenu != null)
    {
        this.menus[this.openedMenu + 1].top =
            parseInt(this.menus[this.openedMenu + 1].top) - this.slidingDist + "px";
    }

    this.menus[num + 1].top = parseInt(this.menus[num + 1].top) + this.slidingDist + "px";
    this.openedMenu = num;
}

function stepUp()
{
    this.menus[this.upMenu].top = parseInt(this.menus[this.upMenu].top) - this.stepSize + "px";

    if (this.upStepNum >= this.numOfSteps - 1)
    {
        clearInterval(this.upTimer);
        this.isSliding--;
    }
    else
    {
        this.upStepNum++;
    }
}

function stepDown()
{
    this.menus[this.downMenu].top = parseInt(this.menus[this.downMenu].top) + this.stepSize + "px";

    if (this.downStepNum >= this.numOfSteps - 1)
    {
        clearInterval(this.downTimer);
        this.isSliding--;
    }
    else
    {
        this.downStepNum++;
    }
}

function slideMenu(num)
{
    if (this.isSliding > 0)
        return;

    if (this.openedMenu == num)
    {
        /* Keep menu open. */
        return;
        
        this.isSliding++;
        this.upStepNum = 0;
        this.upMenu = num + 1;
        this.upTimer = setInterval(this.name + ".stepUp()", 1);
        this.openedMenu = null;
        return;
    }

    if (this.openedMenu != null)
    {
        this.isSliding++;
        this.upStepNum = 0;
        this.upMenu = this.openedMenu + 1;
        this.upTimer = setInterval(this.name + ".stepUp()", 1);
    }

    this.isSliding++;
    this.downStepNum = 0;
    this.downMenu = num + 1;
    this.downTimer = setInterval(this.name + ".stepDown()", 1);
    this.openedMenu = num;
}

/*******************************************************************************
Custom Funtions
*******************************************************************************/

function initSlidingMenu()
{
    slidingMenu = new slidingMenu();
    slidingMenu.addMenu("menu0");
    slidingMenu.addMenu("menu1");
    slidingMenu.addMenu("menu2");
    slidingMenu.addMenu("menu3");
    slidingMenu.addMenu("menu4");
    slidingMenu.addMenu("menu5");
}