﻿var gomovement;
var giIntervalId;
var gDirection;
var giCurrentPos;
var giTargetPos;

//the y co-ordinates of the customize div's two positions
var kPos1 = 0;
var kPos2 = 8;

function calculatePos1() {
    var custDiv = document.getElementById('customizeDiv');
    kPos1 = (custDiv.offsetHeight + 5) * -1;
}

function move(forward) {

    document.getElementById('customizeDiv').style.zIndex = 0;
    calculatePos1();
    iCurrentPos = movement.updatePosition();

    //move the div if it is inside the specified range
    if (iCurrentPos >= kPos1 && iCurrentPos <= kPos2) {
        document.getElementById('customizeDiv').style.top = iCurrentPos + 'px'
    }

    //clear the interval if the target has been reached
    if (direction == 'forward' && iCurrentPos >= iTargetPos) {
        clearInterval(intervalId);
        setTimeout("customiseBackup();", 50);
    }
    else if (direction == 'back' && iCurrentPos <= iTargetPos) {
        clearInterval(intervalId);
        document.getElementById('customizeDiv').style.zIndex = -1;
    }
}

function showMenu() {
    /*calculatePos1();
    //get the current position of the div
    iCurrentPos = (document.getElementById('customizeDiv').style.top);
    iCurrentPos = iCurrentPos.substring(0, iCurrentPos.length - 2);

    if (iCurrentPos == "") {
    iCurrentPos = kPos1;
    }
    
    iTargetPos = kPos2;
    direction = 'forward'
    
    movement = new SmoothMovement(iCurrentPos, iTargetPos, 1);
    

    intervalId = window.setInterval(move, 1);*/
    document.getElementById('customizeDiv').style.visibility = "visible";
    customiseBackup();
}

function hideMenu() {
    /*
    calculatePos1();
    //get the current position of the div
    iCurrentPos = (document.getElementById('customizeDiv').style.top);
    iCurrentPos = iCurrentPos.substring(0, iCurrentPos.length - 2);

    if (iCurrentPos == "") {
    iCurrentPos = kPos2;
    }

    iTargetPos = kPos1;
    direction = 'back'
    movement = new SmoothMovement(iCurrentPos, iTargetPos, -1);

    intervalId = window.setInterval(move, 1);*/
    document.getElementById('customizeDiv').style.visibility = "hidden";
}

function toggleMenu() {
    /*calculatePos1();
    //get the current position of the div
    iCurrentPos = (document.getElementById('customizeDiv').style.top);
    iCurrentPos = iCurrentPos.substring(0, iCurrentPos.length - 2);

    //check if the div is at pos 1 or 2
    if (iCurrentPos == kPos1 || iCurrentPos == "") {
    showMenu();
    }
    else if (iCurrentPos == kPos2) {
    hideMenu();
    }*/
    if (document.getElementById('customizeDiv').style.visibility == "visible") {
        hideMenu();
    }
    else {
        showMenu();
    }
}

//******************* fade in ******************
function showMenu2() {
    document.getElementById('customizeDiv').style.display = "absolute";
}

function hideMenu2() {
    document.getElementById('customizeDiv').style.display = "none";
}

function toggleMenu2() {
    //check if the div is at pos 1 or 2
    if (currentDisplay == "none") {
        showMenu2();
    }
    else if (currentDisplay == "absolute") {
        hideMenu2();
    }
}
