﻿// JScript File

function initMenu(menuNr, menuDiv)
{
    doMenu();
    openMenu(menuNr);
    document.getElementById(menuDiv).style.display = "";
}

var lastWidth = 64;
var lastWidthTo = 64;

function doMenu()
{
    for (i=0; i<cmMenuWidthArray.length; i++)
    {
        // Breedte van hoofdmenu's zodat het actieve menu breder wordt en de rest schuift
        cmMenuWidthArray[i]  = cmMenuWidthArray[i]  + (cmMenuWidthToArray[i] - cmMenuWidthArray[i] ) / 10;
        cmMenuWidthArray[i] = alMost(cmMenuWidthArray[i], cmMenuWidthToArray[i]);
        document.getElementById("menu1_" + cmMenuHdfPnlIDArray[i]).style.width = Math.round(cmMenuWidthArray[i]) + "px";
        
        // Left van logo stukjes met een variabele speed zodat er een soort glas effect ontstaat
        cmMenuLeftArray[i]  = cmMenuLeftArray[i]  + (cmMenuLeftToArray[i] - cmMenuLeftArray[i] ) / (1 + i * 5);
        cmMenuLeftArray[i] = alMost(cmMenuLeftArray[i], cmMenuLeftToArray[i]);
        document.getElementById("menu1_" + cmMenuSubHdfPnlIDArray[i]).style.marginLeft = Math.round(-cmMenuLeftArray[i]) + "px";
        
        cmMenuTopArray[i]  = cmMenuTopArray[i]  + (cmMenuTopToArray[i] - cmMenuTopArray[i] ) / 10;
        cmMenuTopArray[i] = alMost(cmMenuTopArray[i], cmMenuTopToArray[i]);
        
        // Middel de margin top boven het logo zodat het minder versprint als de foto
        document.getElementById("menu1_" + cmMenuSubHdfPnlIDArray[i]).style.marginTop = Math.round(60 - (cmMenuTopArray[i] / 2)) + "px";
        
        // Hoogte van foto (Bepaald ook verspringing van andere vlakken)
        document.getElementById("menu1_" + cmMenuftPnlIDArray[i]).style.height = Math.round(150 + cmMenuTopArray[i]) + "px";
        
        // Verplaats het subsub menu (de tree) zodat het actieve menu in beeld schuift
        cmSubMenuLeftArray[i]  = cmSubMenuLeftArray[i]  + (cmSubMenuLeftToArray[i] - cmSubMenuLeftArray[i] ) / 10;
	    cmSubMenuLeftArray[i] = alMost(cmSubMenuLeftArray[i], cmSubMenuLeftToArray[i]);
        document.getElementById("menu1_" + cmMenusbPPnlIDArray[i]).style.marginLeft = Math.round(cmMenuLeftArray[i] - cmSubMenuLeftArray[i]) + "px";

	}
	
	// Breedte van de laatste foto bepalen
	lastWidth  = lastWidth  + (lastWidthTo -lastWidth) / 10;
	lastWidth = alMost(lastWidth, lastWidthTo);
    document.getElementById("menu1_" + cmMenuftPnlIDArray[cmMenuftPnlIDArray.length - 1]).style.width = Math.round(lastWidth) + "px";
	
	// En nog een keer
    setTimeout("doMenu()", 20);
}

// Afronden op het einde van de beweging
function alMost(nu, to)
{
    if (Math.abs(to - nu) < 3) 
    {
        return to;
    } else {
        return nu;
    }
}

// Open menu item menuNr en sluit de rest
function openMenu(menuNr)
{  
    // basis waarde
    menuTop = (cmMenuWidthArray.length - menuNr) * 20;
    left = 0;
    
    if (menuNr == cmMenuWidthArray.length - 1)
    {
        lastWidthTo = 350;
    } else {
        lastWidthTo = 64;
    }
    
    // Doorloop menu's
    for (i=0; i<cmMenuWidthArray.length; i++)
    {
        leftAdd = 0;
        if (i==0)
        {
            cmMenuWidthToArray[i] = 128;
            cmSubMenuLeftToArray[i] = 350-64;
            leftAdd = 63;
        } else {
            cmMenuWidthToArray[i] = 64;
            cmSubMenuLeftToArray[i] = 350;
            leftAdd = 63;
        }
        
        if (i == 1) leftAdd = 128;
        if (i == menuNr+1) leftAdd = 350;
        left += leftAdd;
        
        cmMenuLeftToArray[i] = left - 30;
        
        if (i <= menuNr) menuTop += 30; else menuTop -= 30; 
        cmMenuTopToArray[i] = menuTop;
	}
	
	// Actieve menu
	if (menuNr >= 0)
	    cmMenuWidthToArray[menuNr] = 350;
	    
	cmSubMenuLeftToArray[menuNr] = -20;
	   
	// laaste menu altijd breed (Voor maastricht woord)
	cmMenuWidthToArray[cmMenuWidthArray.length-1] = 740;
}