﻿// JScript File


var barheight = null;
var blockheight = null;
var falseheight = null;
var menu1now = null;
var menu1go = null;
var menu2now = null;
var menu2go = null;
var menu3now = null;
var menu3go = null;
var menu4now = null;
var menu4go = null;
var falseposition = null;
var menuselected = 'menu2';
var inc = null;
var starting = null;
var moving = null;
var initialising = null;
var objmenu1 = null;
var objmenu2 = null;
var objmenu3 = null;
var objmenu4 = null;
var objfalse = null;
var objswapmenu1 = null;
var objswapmenu2 = null;

function initmenu() {
    logevent('initmenu');
    
//  Initialise the country select box
//  Now that the page is loaded, make the flag visible  
    hidecountries();
    var objccpanel = document.getElementById('countrychoice');
    objccpanel.style.visibility = 'visible';
    
//  Variables to define navigation parameters - size and start points  
    inc = 20;
    barheight = 40;
    blockheight = 360;
    falseheight = 11;
    falseposition = - falseheight;
    menu1go = menu1now = blockheight;
    menu2go = menu2now = barheight;
    menu3go = menu3now = barheight;
    menu4go = menu4now = barheight;
    
//  Set ub objxxxx variables once to improve realtime  
    objmenu1 = document.getElementById('menu1');
    objmenu2 = document.getElementById('menu2');
    objmenu3 = document.getElementById('menu3');
    objmenu4 = document.getElementById('menu4');
    objfalse = document.getElementById('falsebottom');
    objswapmenu1 = document.getElementById('swapmenu1');
    objswapmenu2 = document.getElementById('swapmenu2');
    objmenu1.style.height = blockheight + 'px';
    objmenu2.style.height = barheight + 'px';
    objmenu3.style.height = barheight + 'px';
    objmenu4.style.height = barheight + 'px';
    objfalse.style.top = falseposition + 'px';
    
//  Makes menu visible before webcall determines the right starting position  ??
    var objnavigation = document.getElementById('navigation');
    objnavigation.style.visibility = 'visible';
    
    initialising = true;
    etwist.FindMenu('menu2', OnFind, OnError);
}

function selectmenu(objectID) {
    logevent('selectmenu');
    setuptogoto(objectID);
    starting = true;
    animate();
    etwist.MenuChange(objectID, OnComplete, OnError);
}

function jumptomenu(objectID) {
    logevent('jumptomenu');
    setuptogoto(objectID);
    menu1now = menu1go;
    menu2now = menu2go;
    menu3now = menu3go;
    menu4now = menu4go;
    objmenu1.style.height = menu1now + 'px';
    objmenu2.style.height = menu2now + 'px';
    objmenu3.style.height = menu3now + 'px';
    objmenu4.style.height = menu4now + 'px';
    if (objectID == 'menu4') {
        objfalse.style.visibility = 'hidden';}
    else {objfalse.style.visibility = 'visible'}
    initialising = false;
    etwist.MenuChange(objectID, OnComplete, OnError);
}

function setuptogoto(objectID) {
    menuselected = objectID;
    if (objectID == 'menu1') {
        objmenu1.style.backgroundImage = 'url(images/menu1selected.jpg)';
        objswapmenu1.style.backgroundImage = 'url(images/menu1.jpg)';
        objmenu2.style.backgroundImage = 'url(images/menu2.jpg)';
        objmenu3.style.backgroundImage = 'url(images/menu2.jpg)';
        objmenu4.style.backgroundImage = 'url(images/menu2.jpg)';
        objfalse.style.backgroundImage = 'url(images/falsebottom.jpg)';
        menu1go = blockheight;
        menu2go = barheight;
        menu3go = barheight;
        menu4go = barheight;
        if (menu4now == barheight) objfalse.style.visibility = 'visible';
    }
    else if (objectID == 'menu2') {
        objmenu1.style.backgroundImage = 'url(images/menu1.jpg)';
        objswapmenu1.style.backgroundImage = 'url(images/menu1selected.jpg)';
        objmenu2.style.backgroundImage = 'url(images/menu2selected.jpg)';
        objmenu3.style.backgroundImage = 'url(images/menu2.jpg)';
        objmenu4.style.backgroundImage = 'url(images/menu2.jpg)';
        objfalse.style.backgroundImage = 'url(images/falsebottom.jpg)';
        menu1go = barheight
        menu2go = blockheight;
        menu3go = barheight;
        menu4go = barheight;
        if (menu4now == barheight) objfalse.style.visibility = 'visible';
    }
    else if (objectID == 'menu3') {
        objmenu1.style.backgroundImage = 'url(images/menu1.jpg)';
        objswapmenu1.style.backgroundImage = 'url(images/menu1selected.jpg)';
        objmenu2.style.backgroundImage = 'url(images/menu2.jpg)';
        objmenu3.style.backgroundImage = 'url(images/menu2selected.jpg)';
        objmenu4.style.backgroundImage = 'url(images/menu2.jpg)';
        objfalse.style.backgroundImage = 'url(images/falsebottom.jpg)';
        menu1go = barheight
        menu2go = barheight;
        menu3go = blockheight;
        menu4go = barheight;
        if (menu4now == barheight) objfalse.style.visibility = 'visible';
    }
    else if (objectID == 'menu4') {
        objmenu1.style.backgroundImage = 'url(images/menu1.jpg)';
        objswapmenu1.style.backgroundImage = 'url(images/menu1selected.jpg)';
        objmenu2.style.backgroundImage = 'url(images/menu2.jpg)';
        objmenu3.style.backgroundImage = 'url(images/menu2.jpg)';
        objmenu4.style.backgroundImage = 'url(images/menu2selected.jpg)';
        objfalse.style.backgroundImage = 'url(images/falsebottomselected.jpg)';
        menu1go = barheight
        menu2go = barheight;
        menu3go = barheight;
        menu4go = blockheight;
        objfalse.style.visibility = 'hidden';
    }
}

function animate() {
    logevent('animate');
    var alreadymoving = moving;
    moving = false;
    menu1now = movemenu(objmenu1, menu1go, menu1now);
    menu2now = movemenu(objmenu2, menu2go, menu2now);
    menu3now = movemenu(objmenu3, menu3go, menu3now);
    menu4now = movemenu(objmenu4, menu4go, menu4now);
    if (menu4now == barheight) {
        objfalse.style.visibility = 'visible';
    }
    if (moving == true) {
        if (!((alreadymoving == true) && (starting == true))) {
            starting = false; 
            setTimeout('animate()', 5);
        }
    }
    starting = false;
    return;
}

function movemenu(objectID, moveto, movefrom) {
    if (moveto == movefrom) {
        return movefrom;
    }
    else if (moveto > movefrom) {
        movefrom = movefrom + inc;
    }
    else {
        movefrom = movefrom - inc;
    }
    objectID.style.height = movefrom + 'px';   
    moving = true;
    return movefrom;
 
}

function OnComplete(results, context, methodName) {
    logevent('OnComplete');
}

function OnError(results, context, methodName) {
}

function OnFind(results, context, methodName) {
    logevent('OnFind');
    initialising = false;
    jumptomenu(results);
}

function showcountries() {
    logevent("mousein");
    var objddpanel = document.getElementById('countrydropdown');
    objddpanel.style.visibility = 'visible';
    var objccpanel = document.getElementById('countrychoice');
    objccpanel.style.height = '82px';
}

function hidecountries() {
    logevent("mouseout");
    var objddpanel = document.getElementById('countrydropdown');
    objddpanel.style.visibility = 'hidden';
    var objccpanel = document.getElementById('countrychoice');
    objccpanel.style.height = '33px';
}

function logevent(outputtext) {
//    var objlabel = document.getElementById('ctl00_jsmessages');
//    var basetext = objlabel.innerText + ' '
//    objlabel.innerText = basetext + outputtext + " (menuselected = " + menuselected + ")";
}
