//////////////////////////////////////////
//                                      //
//          PAGE NAVIGATION             //
//                                      //
//////////////////////////////////////////

PageNavigator.currentPageIndex = -1;
PageNavigator.currentPageNode = null;
PageNavigator.previewElem = null;
PageNavigator.previewElemId = "previewElem";
PageNavigator.timer = null;
PageNavigator.previewElemTop = null;
PageNavigator.previewElemWidth = null;
PageNavigator.previewElemHeight = "20";


function PageNavigator() {
}

PageNavigator.init = function () 
{
  if(PageNavigator.previewElemWidth != null)
  {
    PageNavigator.previewElemWidth = null;
  }
  
  if(PageNavigator.previewElemTop != null)
  {  
    PageNavigator.previewElemTop = null;
  }  
}

PageNavigator.over = function (index) 
{
  if(PageNavigator.previewElem == null)
  {
    PageNavigator.previewElem = document.getElementById(PageNavigator.previewElemId);  
  }
  PageNavigator.timer = null;

  PageNavigator.previewElem.innerHTML = PageNavigator.getTitle(index);
  if(PageNavigator.previewElem.style.display != "")
  {
    PageNavigator.previewElem.style.display = ""; 
  }  
    
  if(PageNavigator.previewElemWidth == null)
  {
    PageNavigator.previewElemWidth = System.getPageNavigationPanelElem().offsetWidth;
    PageNavigator.previewElemWidth = PageNavigator.previewElemWidth;
    PageNavigator.previewElem.style.width = PageNavigator.previewElemWidth + "px";
  }

  if(PageNavigator.previewElem.offsetHeight != PageNavigator.previewElemHeight)
  {
    PageNavigator.previewElem.style.height = PageNavigator.previewElemHeight + "px";
  }  
    
  if(PageNavigator.previewElemTop == null)
  {
    PageNavigator.previewElemTop = System.getPageNavigationPosPanelElem().offsetTop;
  }  
  PageNavigator.previewElem.style.top = (PageNavigator.previewElemTop - PageNavigator.previewElem.offsetHeight) + "px";    
}

PageNavigator.out = function (index) 
{
  PageNavigator.timer = setTimeout("PageNavigator.hide();", 1000);
}

PageNavigator.click = function (index) 
{
  // sem zakomentiral, ker mi odznači prvi page, če kliknem na isti node //
  //if(PageNavigator.currentPageIndex != index)
  {
    if(PageNavigator.currentPageIndex != -1)
    {
      var prevElem = document.getElementById("nav" + PageNavigator.currentPageIndex);
      System.convertClickToDefaultImagePath(prevElem, prevElem.src);
      prevElem.style.cursor = "pointer";
    }

    var imgElem = document.getElementById("nav" + index);

    System.convertDefaultToClickImagePath(imgElem, imgElem.src);
    imgElem.style.cursor = "default";

    System.getPageIndexTextFieldElem().value = index;
    PageNavigator.currentPageIndex = parseInt(index);

    // change frame content //
    var htmlPath = PageNavigator.currentPageNode.getHtmlPath(index-1);

    if(System.getContentFrameElem().src)
    {
      System.getContentFrameElem().src = htmlPath;  
    }

    // change page title panel //
    system.menu.content.changePageTitlePanel(PageNavigator.currentPageNode, index-1);

    // change page document (doc, xls) panel //
    system.menu.content.changePageDocumentPanel(PageNavigator.currentPageNode);
  }  
}

PageNavigator.left = function()
{
  var newIndex = PageNavigator.currentPageIndex - 1;
  if(newIndex > 0)
  {
    PageNavigator.click(newIndex);
  }  
}

PageNavigator.right = function()
{
  var newIndex = PageNavigator.currentPageIndex + 1;

  if(newIndex <= PageNavigator.currentPageNode.pages.length)
  {
    PageNavigator.click(newIndex);
  }  
}

PageNavigator.hide = function()
{
  if(PageNavigator.timer != null && PageNavigator.previewElem != null)
  {
    PageNavigator.previewElem.style.display = "none";
    PageNavigator.timer = null;
  }  
}

PageNavigator.getTitle = function(index)
{
  var pageTagList = PageNavigator.currentPageNode.pages;
  var pageTitleTag = pageTagList[index-1].getElementsByTagName(Node.TAG_TITLE);  
  var pageTitle = XmlTools.getLanguageNodeValue(pageTitleTag[0])

  return pageTitle;
}