var newsItemsHeadings = {};
var newsItemsContents = {};
var newsItemsIds = {};

var pe = null;
var menuHasFocus = false;
var currentlyOpenedList = null;


window.onload=setBehaviors;
function setBehaviors(){

  /////////////////////////////////////////
  //COMPORTAMIENTO MENU PRINCIPAL//////////
  ///////////////////////////////////////
  setMainMenuKeyboardNavigation();



 
  /////////////////////////////////
  ////COMPORTAMIENTO PILARES///////
  /////////////////////////////////
  $$('#nav2 .nav_li_link_level_1').each(function(item) {
      item.onmouseover = function(){item.style.backgroundPosition='bottom left'};
      item.onmouseout = function(){item.style.backgroundPosition='top left'};
  });

  /////////////////////////////////////////////////////////
  ///////COMPORTAMIENTO ITEMS INDICE//////////////
  //ESCONDER CONTENIDO DE PARRAFOS/////////////////////
  ///////////////////////////////////////////////////
  //
  /////////////////////////////////////////////////////
  setIndexItemsBehavior();
  hideMainContent();

  ////////////////////////////////////////////////
  ////////COMPORTAMIENTO NOTICIAS ENSENANZA///////
  ///////////////////////////////////////////////////
  
  /*setMainNewsBehaviors();*/


}

function setMainMenuKeyboardNavigation()
{
  var newCount = 300;

  $$('#nav1 .nav_li_level_1').each(function(item) {
      newCount++;
      if(item.firstDescendant().next()!=null)
      {
        item.style.zIndex = newCount;
        
        item.onmouseover = function(){
            item.firstDescendant().next().style.visibility='visible';
            item.firstDescendant().style.backgroundPosition = 'bottom center';
             menuHasFocus = true;
        };
        item.onmouseout = function(){
            item.firstDescendant().next().style.visibility='hidden'
            item.firstDescendant().style.backgroundPosition = 'top center';
            menuHasFocus = false;
        };
      }
  });



  $$('#nav1 .nav_li_link_level_1').each(function(item) {
      newCount++;
          item.style.zIndex = newCount;
        
        item.onmouseover = function(){
           // item.firstDescendant().next().style.visibility='visible';
            item.firstDescendant().next().style.visibility = 'visible';
            item.firstDescendant().style.backgroundPosition = 'bottom center';
             menuHasFocus = true;
             currentlyOpenedList = item.next();
        };

 
       
               item.onfocus = function(){
              //hide currently opened list if it exists 
              if(currentlyOpenedList!=null)
              {
                 currentlyOpenedList.style.visibility = 'hidden';
              }
              menuHasFocus = true;
              item.next().style.visibility = 'visible';
              currentlyOpenedList = item.next();
              item.firstDescendant().next().style.visibility='visible';
        };
        item.onblur = function(){
              pe = new PeriodicalExecuter(checkOpenedMenu, 1); 
              menuHasFocus = false;
              //hide list if focus is not within current list
        };

  });



  $$('#nav1 .nav_li_link_level_2').each(function(item) {
       item.onblur = function(){
         pe = new PeriodicalExecuter(checkOpenedMenu, 1); 
         menuHasFocus = false;
       };
       item.onfocus = function(){
         menuHasFocus = true;
         currentlyOpenedList.style.visibility = 'visible';
       };

       item.onmouseover = function(){
         menuHasFocus = true;
         //currentlyOpenedList.style.visibility = 'visible';
       };
   
 
  });
  
  $$('#nav1 .nav_li_link_level_3').each(function(item) {
       item.onblur = function(){
         pe = new PeriodicalExecuter(checkOpenedMenu, 1); 
         menuHasFocus = false;
       };
       item.onfocus = function(){
         menuHasFocus = true;
         currentlyOpenedList.style.visibility = 'visible';
       };
  });

}

function setIndexItemsBehavior()
{
  $$('#da1 .headingsList a').each(function(item){
    item.onclick = function(){showMainContent()};
  });
  $$('#da1 a.backToIndexLink').each(function(item){
    item.onclick = function(){hideMainContent()};
  });


}

function hideMainContent()
{
  $$('#da1 .pageItemBox').each(function(item){
    item.style.display = 'none';
  });

}

function showMainContent()
{
  $$('#da1 .pageItemBox').each(function(item){
    item.style.display = 'block';
  });

}

