﻿var wArray;

$(document).ready(
   function() {

       //predispone l'array delle larghezze
       wArray = new Array();
       wArray["#ulCOMPANY"] = "345px";
       wArray["#ulSERVICES"] = "288px";
       wArray["#ulTECHNOLOGY"] = "130px";

       $('.sottovoci').addClass("sottovoci-hidden");

       $("#liCOMPANY").click(
          function() {
              ToogleSubmenu("#ulCOMPANY");
              return false;
          });
       $("#liServizi").click(
      function() {
          ToogleSubmenu("#ulSERVICES");
          return false;
      });
       $("#liTechnologies").click(
      function() {
          ToogleSubmenu("#ulTECHNOLOGY");
          return false;
      });

   }
 );

function SetCurrentSection(code,currentSection) {

    var ul = '#ul' + code;
    ToogleSubmenu(ul);

    SetCurrentSubMenu(ul,currentSection);

};


function ToogleSubmenu(div) {

    //chiude gli altri menu
    $(".sottovoci-hidden").each(function() {
        $(this).animate({ width: "0px" }, 350);
        SwapValue($(this), "-", "+");
    });


    //apre il menu
    if ($(div).css("width") == "0px") {
        $(div).animate({ width: wArray[div] }, 350);
        SwapValue(div, "+", "-");
    }
}

function SwapValue(div, value1, value2) {
    var text = $(div).closest("li").prev("li").children("a").html();
    text = text.replace(value1, value2);
    $(div).closest("li").prev("li").children("a").html(text);

}

function SetCurrentSubMenu(div, currentSection) {
    $(div).children().children().eq(currentSection).attr({
        style: "color:white"
    });
}

