// ------------------------------------------------------------------
// navigation box
// ------------------------------------------------------------------
var navigationBoxTimers = new Array();

// items events definitions
var navigationBoxItemEvents = "onmouseover = 'javascript: navigationBoxStartChangingClass( this, \"highlightedSiteMapItem\" );' onmouseout = 'javascript: navigationBoxStartChangingClass( this, \"bluredSiteMapItem\" ); '";

// this callback must be assigned to the mouse out and mouse over event 
// of the navigation box to change it's height
function navigationBoxStartChangingClass( element, className )
{
  // every event has the priority, so clearing the timer first
  if ( navigationBoxTimers[element.id] )
  {
    clearTimeout( navigationBoxTimers[element.id] );
    navigationBoxTimers[element.id] = false;
  };
    
  // checking, if the height must be changed and setting the timer for this
  //if ( element.className != className )
  {
    // changing the site helper panel
    navigationBoxTimers[element.id] = setTimeout( function()
      {
        // setting the class name
        element.className = className;
        navigationBoxTimers[element.id] = false;
      },
      navigationBoxTimeout
    )
  }
}
    
// fills the navigation box with the site map
function fillNavigationBox()
{
  var navigationBox = obtainElementById( navigationBoxId );
  
  // skipping if documents descriptions are not defined
  if ( !DOCUMENTS_DESCRIPTIONS[LANGUAGE] )
    return false;
  
  // rebuilding the documents descriptions to the current
  // document localization
  
  if ( navigationBox )
  {
    var content = buildNavigationBoxContentLevel( new Array(), "<table class='highlightedSiteMapItem' width='100%'><tr><td width='20%'><ul><li><a href='/'>"+SITE_SCREEN_NAME+"</a></li></ul><td> " )+"</td></tr></table>";

    navigationBox.innerHTML = content;
  };
}

// appends the current site map level documents to the content
// and returns it
// calls itself inside to perform the tree structure treatment
function buildNavigationBoxContentLevel( siteMapLevel, content )
{
  // obtaining the site map subarray in the current level container level
  var currentSiteMap;
  var expression = "currentSiteMap = SITE_MAP";
  for ( var levelI = 0; levelI < siteMapLevel.length; levelI++ )
    expression += "['" + siteMapLevel[levelI] + "']";
  eval( expression );
  
  // treating all documents in the current level
  if ( !isEmpty(currentSiteMap) )
  {
    for ( var documentName in currentSiteMap )
    {
      // configuring the current site map level
      var currentSiteMapLevel = new Array();
      for ( var levelI = 0; levelI < siteMapLevel.length; levelI++ )
        currentSiteMapLevel[levelI] = siteMapLevel[levelI];
      currentSiteMapLevel[currentSiteMapLevel.length] = documentName;

      // storing the content
      var path = currentSiteMapLevel.join( "/" ) + "/";
      var title = "";
      var summary = "";
      var url = "";
      for ( var i = 0; i < DOCUMENTS_DESCRIPTIONS[LANGUAGE].length; i++ )
        if ( DOCUMENTS_DESCRIPTIONS[LANGUAGE][i]['path'] == path )
        {
          title = DOCUMENTS_DESCRIPTIONS[LANGUAGE][i]['title'];
          summary = DOCUMENTS_DESCRIPTIONS[LANGUAGE][i]['summary'];
          url = DOCUMENTS_DESCRIPTIONS[LANGUAGE][i]['url'];
          break;
        };

      // highlighting the current position in the site map
      var isCurrentUrlItem = true;
      for ( var levelI = 0; levelI < currentSiteMapLevel.length; levelI++ )
      {
        if ( !DOCUMENT_PATH[levelI] ||
             currentSiteMapLevel[levelI] != DOCUMENT_PATH[levelI] )
        {
          isCurrentUrlItem = false;
          break;
        };
      };
      var className = isCurrentUrlItem ? "class='currentUrlSiteMapItem'" : "";
      
      content += "<table cellpadding='0' cellspacing='0' width='100%' id='"+path+"' class='bluredSiteMapItem' "+navigationBoxItemEvents+"><tr><td width='20%'><ul><li>" + "<div "+className+"><a href='"+url+"'>"+title+"</a></div></li></ul></td>";
      
      // moving deeper
      if ( !isEmpty(currentSiteMap[documentName]) )
        content = buildNavigationBoxContentLevel( currentSiteMapLevel, content+"<td>" )+"</td>";
      
      content += "</tr></table>";
    };
  };
  
  // done
  return content;
}
