﻿var menu;
var index;
var t1;
var t2;
var t3;
var t4;
var t5;

// Client Functions
function changeMenu(menuId, sender, language)
{
    clearTimeout(t1);
    clearTimeout(t2);
    clearTimeout(t3);
    clearTimeout(t4);
    clearTimeout(t5);
    
    menuId = menuId; //.replace(/\$/g, "_");
    var menuFactory = document.getElementById(menuId + "_TreeMenuFactory");
    var menuProducts = document.getElementById(menuId + "_TreeMenuProducts");
    var menuESolutions = document.getElementById(menuId + "_TreeMenuESolutions");
    var imgFactory = document.getElementById(menuId + "_imgFactory");
    var imgProducts = document.getElementById(menuId + "_imgProducts");
    var imgESolutions = document.getElementById(menuId + "_imgESolutions");
    
    if (sender == "factory")
    {    
        setTimeout('FactoryMove()', 300);
              
        menuFactory.style.display = "block";
        menuProducts.style.display = "none";
        menuESolutions.style.display = "none";
        imgFactory.className = "imageSelected";
        imgProducts.className = "imageUnselected";
        imgESolutions.className = "imageUnselected";
    
        if(language == 'it-IT')
        {
            setImage(imgFactoryBigItPreload.src, imgFactory);
            setImage(imgProductsItPreload.src, imgProducts);
            setImage(imgESolutionsItPreload.src, imgESolutions);
        }
        else if(language == 'en-IE')
        {
            setImage(imgFactoryBigEnPreload.src, imgFactory);
            setImage(imgProductsEnPreload.src, imgProducts);
            setImage(imgESolutionsEnPreload.src, imgESolutions);
        }
    }
    else if (sender == "products")
    {
        setTimeout('ProductsMove()', 300);
     
        menuFactory.style.display = "none";
        menuProducts.style.display = "block";
        menuESolutions.style.display = "none";
        imgFactory.className = "imageUnselected";
        imgProducts.className = "imageSelected";
        imgESolutions.className = "imageUnselected";
    
         if(language == 'it-IT')
         {
             setImage(imgFactoryItPreload.src, imgFactory);
             setImage(imgProductsBigItPreload.src, imgProducts);
             setImage(imgESolutionsItPreload.src, imgESolutions);
         }
         else if(language == 'en-IE')
         {
             setImage(imgFactoryEnPreload.src, imgFactory);
             setImage(imgProductsBigEnPreload.src, imgProducts);
             setImage(imgESolutionsEnPreload.src, imgESolutions);
         }
    }
    else if (sender == "esolutions")
    {
        setTimeout('ESolutionsMove()', 300);
        
        menuFactory.style.display = "none";
        menuProducts.style.display = "none";
        menuESolutions.style.display = "block";
        imgFactory.className = "imageUnselected";
        imgProducts.className = "imageUnselected";
        imgESolutions.className = "imageSelected";
    
        if(language == 'it-IT')
        {
            setImage(imgFactoryItPreload.src, imgFactory);
            setImage(imgProductsItPreload.src, imgProducts);
            setImage(imgESolutionsBigItPreload.src, imgESolutions);
        }
        else if(language == 'en-IE')
        {
            setImage(imgFactoryEnPreload.src, imgFactory);
            setImage(imgProductsEnPreload.src, imgProducts);
            setImage(imgESolutionsBigEnPreload.src, imgESolutions);
         }
    }
}

function FactoryMove()
{
        menu = "Factory";
        
        index = 0;
            
        MenuMove();
}

function ProductsMove()
{
        menu = "Products";
        
        index = 0;
            
        MenuMove();
}

function ESolutionsMove()
{
        menu = "ESolutions";
        
        index = 0;
            
        MenuMove();
}

function MenuMove()
{
        if(document.getElementById('ctl00_SideMenu_TreeMenu' + menu + '_TreeMenuCell_' + index).style.backgroundColor != "#7e1316")
            t1 = setTimeout('MenuSelect()', 0);
        else
            index++;
        t2 = setTimeout('MenuSelect()', 400);
        t3 = setTimeout('MenuSelect()', 800);
        t4 = setTimeout('MenuSelect()', 1200);
        t5 = setTimeout('MenuSelect()', 1600);
}

function MenuSelect()
{
    var element = document.getElementById('ctl00_SideMenu_TreeMenu' + menu + '_TreeMenuCell_' + index);
    if(element != null && element.style.backgroundColor != "#7e1316")
    {
        element.style.backgroundColor = "#7e1316";
        document.getElementById('ctl00_SideMenu_TreeMenu' + menu + '_Link_' + index).style.color = "#ffffff";

        setTimeout('MenuDeselect()', 200);
    }
}

function MenuDeselect()
{
    document.getElementById('ctl00_SideMenu_TreeMenu' + menu + '_TreeMenuCell_' + index).style.backgroundColor = "transparent";
    document.getElementById('ctl00_SideMenu_TreeMenu' + menu + '_Link_' + index).style.color = "#000000";
    
    index++;
    var element = document.getElementById('ctl00_SideMenu_TreeMenu' + menu + '_TreeMenuCell_' + index);
    if(element != null && element.style.backgroundColor == "#7e1316")
        index++;
}

function setImage(imageUrl, img)
{
    img.src = imageUrl;
}

function attachSelectedMainSidemenuEvents(object)
{
    object.onclick = new Function("changeSubSidemenu('" + object.id + "')");
}


// Fine Client Functions

