/**
 * Copyright 2003 (C) Massvision
 * Padajuci meniji
 * @file    dropDown.js
 * @author  Milos Veskovic
 * @brief   Padajuci meniji(ide u paketu sa style sheet-om "dropDown.css" za setovanje izgleda menija po nivoima)
 * @todo    treba uraditi menije sleva (trenutno radi samo za padajuce menije sa glavnom navigacijom odozgo)
 */

   var agt=navigator.userAgent.toLowerCase();
   var is_nav  = ((agt.indexOf("mozilla")!=-1) && (agt.indexOf("spoofer")==-1)
                  && (agt.indexOf("compatible") == -1) && (agt.indexOf("opera")==-1)
                  && (agt.indexOf("webtv")==-1));
   var is_major = parseInt(navigator.appVersion);
   var isNN=(navigator.appName=="Netscape");
   var is_opera = (agt.indexOf("opera") != -1);
   var not_nav6 = (is_nav && (is_major < 5));
   var objectsToHideById = new Array();
   var replacementObjects = new Array();


   /**
    * Konstruktor
    * @brief Konstruktor
    * @params params parametri za setovanje
    * @code
         var DropDownParams = {
                  DropDownMenuName    : "DropDownMenus"              // ime objekta (obavezan)
                 ,MySitemap           : sitemap                      // niz za padajuce menije (sitemap) (obavezan)
                 ,DropDownMenuId      : "DropDownMenu"               // parametar (prefix) za id padajuceg menija
                 ,AditionalStartLeft  : 20                           // dodatna vrednost pocetne pozicije sleva (left) za prvi nivo (level)
                 ,StartMenuTableWidth : 240                          // fiksna vrednost sirine tabele (dodatno se siri ako je sadrzaj siri od vrednosti)
                 ,MenuTableDataWrap   : "wrap"                       // parametar za setovanje "wrap" metode unutar tabele default "nowrap"
                 ,TableDimensions     : "CheckTableDimensions"       // parametar za ime celije preko koje se odredjuje da li je menjana velicina fonta na strani
                 ,MenuUpButtonCell    : "MenuUpButtonCell"           // parametar (prefix) za ime celija glavnog menija
                 ,MenuUpSeparatorCell : "MenuUpSeparatorCell"        // parametar za ime celije koja je eventualni separator izmedju celija glavnog menija
                 ,DropDownTableLevel  : "dropDownTableLevel"         // parametar za ime klase tabele style-a koja se koristi
                 ,DropDownClassName   : "dropDownCellLevel"          // parametar za ime klase celije style-a koja se koristi
                 ,Level0Active        : true                         // parametar za setovanje aktivnosti prvog nivoa padajuceg menija default "false"
                 ,AppendixHeight      : 368                          // parametar za rucno setovanje pocetne gornje pozicije padajuceg menija default "0"
                 ...
                 };
         var DropDownMenus = new DropDown(DropDownParams);
         DropDownMenus.initDropDownMenus();
    * @tip U "body" tagu bi na akcije "onLoad i onResize" trebalo pozvati funkciju "DropDownMenus.checkScrolling();", a na akciju "onClick" bi trebalo pozvati funkciju "DropDownMenus.hideAllMenus();"
    */
function DropDown(params)
{
   /**
    * Parametri za setovanje
    * @brief Parametri za setovanje
    * @comment Ovi parametri se mogu setovati po volji
    */
   // ime objekta koji je kreiran
   this.DropDownMenuName = params.DropDownMenuName ? params.DropDownMenuName : 0;
   // niz cele sitemap-e
   this.MySitemap = params.MySitemap ? params.MySitemap : 0;
   // trenutno aktivna strana
   this.CurrActivePage = params.CurrActivePage ? params.CurrActivePage : "";
   // parametar (prefix) za id padajuceg menija
   this.DropDownMenuId = params.DropDownMenuId ? params.DropDownMenuId : "DropDownMenu";
   // parametri za setovanje pauza sklanjanja lejera
   this.MainMenuTimeOut = params.MainMenuTimeOut ? params.MainMenuTimeOut : 1500;
   this.SubMenuTimeOut = params.SubMenuTimeOut ? params.SubMenuTimeOut : 1500;
   this.MainMenuHideTimeOut = null; // nemenjati
   this.SubMenuHideTimeOut = null; // nemenjati
   // dodatna vrednost pocetne pozicije odozgo (top) za prvi nivo (level)
   // !!! mora da se promeni "dropDownTableLevel0"/"padding top" u style sheet-u
   // !!! ne radi u exploreru pa se trenutno nekoristi
   this.AditionalStartHeight = params.AditionalStartHeight ? params.AditionalStartHeight : 0;
   // dodatna vrednost pocetne pozicije sleva (left) za prvi nivo (level)
   this.AditionalStartLeft = params.AditionalStartLeft ? params.AditionalStartLeft : 0;
   // fiksna vrednost sirine tabele (dodatno se siri ako je sadrzaj siri od vrednosti)
   this.StartMenuTableWidth = params.StartMenuTableWidth ? params.StartMenuTableWidth : 0;
   // parametar za setovanje "wrap" metode unutar tabele
   // wrap: wrapuje text;
   // nowrap: sve u jednoj liniji (default)
   this.MenuTableDataWrap = params.MenuTableDataWrap ? params.MenuTableDataWrap : "nowrap";
   // parametar za ime celije preko koje se odredjuje da li je menjana velicina fonta na strani
   this.TableDimensions = params.TableDimensions ? params.TableDimensions : "";
   // parametar (prefix) za ime celija glavnog menija
   // na ovo ime se dodaje id glavnog menija
   this.MenuUpButtonCell = params.MenuUpButtonCell ? params.MenuUpButtonCell : "";
   // parametar za ime celije koja je eventualni separator izmedju celija glavnog menija
   // ako je 0 nece se uzimati u obzir (default)
   this.MenuUpSeparatorCell = params.MenuUpSeparatorCell ? params.MenuUpSeparatorCell : 0;
   // parametar za ime klase tabele style-a koja se koristi
   this.DropDownTableLevel = params.DropDownTableLevel ? params.DropDownTableLevel : "dropDownTableLevel";
   // parametar za ime klase celije style-a koja se koristi
   this.DropDownClassName = params.DropDownClassName ? params.DropDownClassName : "dropDownCellLevel";
   // parametar za setovanje aktivnosti prvog nivoa padajuceg menija
   this.Level0Active = params.Level0Active ? params.Level0Active : false;
   // parametar za rucno setovanje pocetne gornje pozicije padajuceg menija
   this.AppendixHeight = params.AppendixHeight ? params.AppendixHeight : 0;

   // "empty.html" (for i-frame)
   this.EmptyDocPath = params.EmptyDocPath ? params.EmptyDocPath : "";


   /**
    * Lokalni parametri
    * @brief Lokalni parametri
    * @comment NE DIRATI
    */
   // lejeri odnosno meniji
   this.MenuItem = new Array();
   // niz pocetne pozicije odozgo (top) za prvi nivo (level)
   this.MainMenuTopPosition = new Array();
   // niz pocetne pozicije sleva (left) za prvi nivo (level)
   this.MainMenuLeftPosition = new Array();
   // niz pocetne pozicije odozgo (top) za prvi meni
   this.MainMenuTopPositionAfterCheck = 0;
   // niz pocetne pozicije sleva (left) za prvi meni
   this.MainMenuLeftPositionAfterCheck = 0;
   // sirina celije preko koje se proverava promena velicine slova
   this.CheckTableDimensionWidth = 0;
   // visina celije preko koje se proverava promena velicine slova
   this.CheckTableDimensionHeight = 0;
   // sirina prozora browsera (nedirati parametar)
   this.StartWindowWidth = 0;
   // niz aktivnih menija po nivou (level)
   this.ActivMenuItemNamesByLevel = new Array();
   // niz aktivnih clasa po nivou (level)
   this.ActivClassNamesByLevel = new Array();
   // niz pocetne pozicije odozgo za menije po nivou (level)
   this.TopPositionsByLevel = new Array();
   // niz pocetne pozicije sleva za menije po nivou (level)
   this.LeftPositionsByLevel = new Array();
   // parametar za setovanje aktivne strane
   this.FoundActivePage = 0;
   // parametar za setovanje aktivnog parent-a strane
   // !!! ovo treba proveriti za vise od dva nivoa
   this.FoundParentPage = 0;
}



   /**
    * Funkcija koja se poziva iz "kora"
    * @brief Funkcija koja se poziva iz "kora"
    * @comment postoje dve varijante:
              1. pozvati funkciju i proslediti joj niz(sitemap-e) (mora da se uradi odmah iza "body" taga)
              2. pozvati je bez parametara (radi samo proveru pozicija menija events:"onLoad, onResize...")
    */
   DropDown.prototype.initDropDownMenus = function()
   {
      if(!isNN || !not_nav6){
         if(this.MySitemap && this.DropDownMenuName){
            this.findActivePages(this.MySitemap);
            this.createSitemap(this.MySitemap);
         }
      }
      this.createMaskLayers();
   }


   /**
    * Pronalazi aktivnu stranu
    * @brief Pronalazi aktivnu stranu
    * @param newArray: niz sitemap-e
    */
   DropDown.prototype.findActivePages = function(newArray)
   {
      for (var i=0; i<newArray.length; i++) {
   		this.findActivePage(newArray[i]);
   	}
   }
   /**
    * Pronalazi aktivnu stranu, prosledjuje joj se niz (rekurzivno)
    * @brief Pronalazi aktivnu stranu, prosledjuje joj se niz (rekurzivno)
    * @param newArray: niz koji se trenutno pretrazuje
    */
   DropDown.prototype.findActivePage = function(newArray)
   {
      if(!this.FoundActivePage && this.CurrActivePage!=""){
         for (var i=0; i<newArray.length; i++) {
      		if(newArray[i][5]==this.CurrActivePage){
      		   newArray[i][4] = 1;
      		   this.FoundActivePage = 1;
      		}
      		if(!this.FoundActivePage && newArray[i][3]){
               this.findActivePage(newArray[i][6])
      		}
      		if(this.FoundActivePage && !this.FoundParentPage){
      		   newArray[i][4] = 1;
      		   this.FoundParentPage = 1;
      		}
      	}
      	this.FoundParentPage = 0;
      }
   }


   /**
    * Proverava pozicije svih padajucih menija
    * @brief Proverava pozicije svih padajucih menija
    */
   DropDown.prototype.checkScrolling = function()
   {
   	var shoudCheck = this.getStartPosition();
   	if( shoudCheck && this.MySitemap && this.DropDownMenuName ){
   		this.MainMenuTopPosition[0] = this.MainMenuTopPositionAfterCheck;
   		this.MainMenuLeftPosition[0] = this.MainMenuLeftPositionAfterCheck;
   		this.StartWindowWidth = document.body.clientWidth;
   		this.recalculateSitemap(this.MySitemap);
   	}
   }
   /**
    * Odredjuje startnu poziciju prvog menija
    * @brief Odredjuje startnu poziciju prvog menija
    * @return shoudCheck: true/false da li treba setovati pozicije menija
    */
   DropDown.prototype.getStartPosition = function()
   {
      var shoudCheck = 0;
      if(   (this.CheckTableDimensionWidth != document.getElementById(this.TableDimensions).offsetWidth)
   	      || (this.CheckTableDimensionHeight != document.getElementById(this.TableDimensions).offsetHeight)
   	      || this.StartWindowWidth != document.body.clientWidth
   	   )
   	{
   	   shoudCheck = 1;
         this.CheckTableDimensionWidth = document.getElementById(this.TableDimensions).offsetWidth;
         this.CheckTableDimensionHeight = document.getElementById(this.TableDimensions).offsetHeight;
         this.MainMenuLeftPositionAfterCheck = document.getElementById("MenuLeftCell").offsetWidth; // !!! ovo nemoze da bude ovako, ali otom potom
   	   this.MainMenuTopPositionAfterCheck = document.getElementById("MenuUpCell").offsetHeight + this.AppendixHeight; // !!! ovo nemoze da bude ovako, ali otom potom
   	}
   	return shoudCheck;
   }
   /**
    * Setovanje pozicija osnovne sitemap-e
    * @brief Setovanje pozicija osnovne sitemap-e
    * @param newArray: niz sitemap-e
    */
   DropDown.prototype.recalculateSitemap = function(newArray)
   {
   	for (var i=0; i<newArray.length; i++) {
   		var menuName = this.DropDownMenuId+i;
   		this.MenuItem[menuName].MenuTableSetPosition(menuName,i,0,i,newArray);
   	}
   }
   /**
    * Setovanje pozicija padajuceg menija
    * @brief Setovanje pozicija padajuceg menija
    * @param
         newArray:   niz koji se trenutno pozicionira
         level:      nivo trenutnog niza
         mainMenu:   id glavnog menija
         menuName:   ime padajuceg menija
    */
   DropDown.prototype.recalculatePosition = function(newArray, level, mainMenu, menuName)
   {
   	for (var i=0; i<newArray.length; i++) {
   		this.MenuItem[menuName].MenuTableSetPosition(menuName,i,level,mainMenu,newArray);
   	}
   }


   /**
    * Kreiranje osnovnih menija sitemap-e
    * @brief Kreiranje osnovnih menija sitemap-e
    * @param newArray: niz sitemap-e
    */
   DropDown.prototype.createSitemap = function(newArray)
   {
   	for (var i=0; i<newArray.length; i++) {
   		var menuName = this.DropDownMenuId+i;
   		this.MenuItem[menuName] = new MenuItemTable(menuName,i,0,i,newArray,this.DropDownMenuName);
   	}
   }
   /**
    * Kreiranje padajuceg menija
    * @brief Kreiranje padajuceg menija
    * @param
         newArray:   niz koji se trenutno krera
         level:      nivo trenutnog niza
         mainMenu:   id glavnog menija
         menuName:   ime padajuceg menija
    */
   DropDown.prototype.createDropMenu = function(newArray, level, mainMenu, menuName)
   {
   	for (var i=0; i<newArray.length; i++) {
   		this.MenuItem[menuName] = new MenuItemTable(menuName,i,level,mainMenu,newArray,this.DropDownMenuName);
   	}
   }


   /**
    * Sakriva sve padajuce menije
    * @brief Sakriva sve padajuce menije
    */
   DropDown.prototype.hideAllMenus = function()
   {
      var startLevel = this.Level0Active ? 1 : 0;
      for(var i=startLevel; i<this.ActivMenuItemNamesByLevel.length; i++){
         this.MenuItem[this.ActivMenuItemNamesByLevel[i]].MenuTableHide();
      }
      for(var i=0; i<this.ActivClassNamesByLevel.length; i++){
         if( this.ActivClassNamesByLevel[i].className == this.DropDownClassName+i+"Over" ){
            this.ActivClassNamesByLevel[i].className = this.DropDownClassName+i+"Off";
         }else if(this.ActivClassNamesByLevel[i].className == this.DropDownClassName+i+"OverMenu"){
            this.ActivClassNamesByLevel[i].className = this.DropDownClassName+i+"OffMenu";
         }
      }
      unhideExternalObjects();
   }
   /**
    * Sakriva padajuce menije
    * @brief Sakriva padajuce menije
    * @param level: nivo od koga se sakrivaju padajuci meniji
    */
   DropDown.prototype.hideSubMenus = function(level)
   {
      for(var i=level; i<this.ActivMenuItemNamesByLevel.length; i++){
         this.MenuItem[this.ActivMenuItemNamesByLevel[i]].MenuTableHide();
      }
      for(var i=(level-1); i<this.ActivClassNamesByLevel.length; i++){
         if( this.ActivClassNamesByLevel[i].className == this.DropDownClassName+i+"Over" ){
            this.ActivClassNamesByLevel[i].className = this.DropDownClassName+i+"Off";
         }else if(this.ActivClassNamesByLevel[i].className == this.DropDownClassName+i+"OverMenu"){
            this.ActivClassNamesByLevel[i].className = this.DropDownClassName+i+"OffMenu";
         }
      }
   }


   /**
    * Over glavnog menija
    * @brief Over glavnog menija
    * @comment mora se pozvati na mouseOver
    * @param id: id glavnog menija
    */
   DropDown.prototype.MainMenuOver = function(id)
   {
      var menuName = this.DropDownMenuId+id;
   	if(!isNN || !not_nav6){
   		this.checkScrolling();
   		if(this.ActivMenuItemNamesByLevel[0] && this.ActivMenuItemNamesByLevel[0]!=menuName){
   			this.hideAllMenus();
   		}
   		if(this.MenuItem[menuName]){
   			if (this.MainMenuHideTimeOut) clearTimeout(this.MainMenuHideTimeOut);
   			this.MenuItem[menuName].MenuTableShow();
   			this.ActivMenuItemNamesByLevel[0] = menuName;
   		}
   	}
   }
   /**
    * Out glavnog menija
    * @brief Out glavnog menija
    * @comment mora se pozvati na mouseOut
    * @param id: id glavnog menija
    */
   DropDown.prototype.MainMenuOut = function(id)
   {
   	if(!isNN || !not_nav6){
   		this.checkScrolling();
   		var menuName = this.DropDownMenuId+id;
   		if(this.ActivMenuItemNamesByLevel[0] == menuName){
   			if (this.MainMenuHideTimeOut) clearTimeout(this.MainMenuHideTimeOut);
   			this.MainMenuHideTimeOut = setTimeout(this.DropDownMenuName+".hideAllMenus();",this.MainMenuTimeOut);
   		}
   	}
   }
   /**
    * Press glavnog menija
    * @brief Press glavnog menija
    * @comment mora se pozvati na mouseClick ili href
    * @param id: id glavnog menija (trenutno se nekoristi, ali mozda ce se nesto dodavati pa nije lose da i on postoji)
    */
   DropDown.prototype.MainMenuPress = function(id)
   {
   	this.hideAllMenus();
   }


   /**
    * Over padajucih menija
    * @brief Over padajucih menija
    * @param
         haveSub:    true/false da li postoji submeni
         mainMenu:   id glavnog menija
         level:      nivo padajuceg menija
         menuName:   ime padajuceg menija
         id:         objekat celije na kojoj se nalazi kursor
    */
   DropDown.prototype.DropDownMenuOver = function(haveSub,mainMenu,level,menuName,id)
   {
      this.checkScrolling();
      if ( this.ActivMenuItemNamesByLevel[0] == this.DropDownMenuId+mainMenu ) {
   		if (this.MainMenuHideTimeOut) clearTimeout(this.MainMenuHideTimeOut);
   	}
   	if(haveSub){
   	   if (this.SubMenuHideTimeOut) clearTimeout(this.SubMenuHideTimeOut);
   		var menuItemId = menuName;
   		if(this.ActivMenuItemNamesByLevel[level] && this.ActivMenuItemNamesByLevel[level]!=menuItemId){
   			this.hideSubMenus(level);
   		}
   		this.ActivClassNamesByLevel[(level-1)] = id;
   		if(id.className == this.DropDownClassName+(level-1)+"OffMenu"){
   		   id.className = this.DropDownClassName+(level-1)+"OverMenu";
   		}
   	   this.ActivMenuItemNamesByLevel[level] = menuItemId;
   		this.MenuItem[menuItemId].MenuTableShow();
   	}else{
   	   if(id.className == this.DropDownClassName+level+"Off")
   		   id.className = this.DropDownClassName+level+"Over";
   	   var newLevel = level+1;
   	   this.hideSubMenus(newLevel);
   	   if (this.SubMenuHideTimeOut) clearTimeout(this.SubMenuHideTimeOut);
   	   this.SubMenuHideTimeOut = setTimeout(this.DropDownMenuName+".hideSubMenus("+newLevel+");",this.SubMenuTimeOut);
      }
   }
   /**
    * Out padajucih menija
    * @brief Out padajucih menija
    * @param
         haveSub:    true/false da li postoji submeni
         mainMenu:   id glavnog menija
         level:      nivo padajuceg menija
         menuName:   ime padajuceg menija
         id:         objekat celije na kojoj se nalazi kursor
    */
   DropDown.prototype.DropDownMenuOut = function(haveSub, mainMenu,level,menuName,id) {
      this.checkScrolling();
   	if(haveSub){
   		var menuItemId = menuName;
   		if(this.ActivMenuItemNamesByLevel[level] && this.ActivMenuItemNamesByLevel[level]==menuItemId){
   			if (this.SubMenuHideTimeOut) clearTimeout(this.SubMenuHideTimeOut);
   			this.SubMenuHideTimeOut = setTimeout(this.DropDownMenuName+".hideSubMenus("+level+");",this.SubMenuTimeOut);
   		}
   	}else{
   	   if(id.className == this.DropDownClassName+level+"Over")
   	      id.className = this.DropDownClassName+level+"Off";
      }
   	if(this.ActivMenuItemNamesByLevel[0] == this.DropDownMenuId+mainMenu){
   		if (this.MainMenuHideTimeOut) clearTimeout(this.MainMenuHideTimeOut);
   		this.MainMenuHideTimeOut = setTimeout(this.DropDownMenuName+".hideAllMenus();",this.MainMenuTimeOut);
   	}
   }
   /**
    * Press padajucih menija
    * @brief Press padajucih menija
    * @param
         targetAddress: adresa (location) na koji se ide
         targetWindow:  target prozor u kome se otvara nova strana
    */
   DropDown.prototype.DropDownMenuPress = function(targetAddress, targetWindow){
      focus();
      this.hideAllMenus();
   	if(targetAddress != "empty"){
   		if(targetWindow == "_self"){
   			location = targetAddress;
   		}else if(targetWindow == "_blank"){
   			window.open(targetAddress);
   		}
   	}
   }
   /**
    * Kreira maske (ie fix za "providne" lejere)
    * @brief Kreira maske (ie fix za "providne" lejere)
    */
   DropDown.prototype.createMaskLayers = function()
   {
   	for (i=0;i<5;i++)
   	   if (!document.getElementById('dropDownMask'+i))
   	   	document.write( '<iframe id="dropDownMask'+i+'" style="visibility: hidden; width: 0px; height: 0px; z-index:'+(i+1)+'; '
   	   	               +'LEFT: 0px; POSITION: absolute; TOP: 0px;" src="'+ this.EmptyDocPath +'" frameborder="0" scrolling="no">'
   	   	               +'</iframe>'
   	   	              );
   }


   /**
    * Kreira objekat padajuceg menija
    * @brief Kreira objekat padajuceg menija
    * @param
         menuName:	ime padajuceg menija
         id:			id padajuceg menija
         level:		nivo padajuceg menija
         mainMenu:	id glavnog menija
         newArray:	niz elemenata padajuceg menija
    */
   function MenuItemTable(menuName,id,level,mainMenu,newArray,DropDownMenuName) {
   //	alert(menuName);
   	this.menuName	= menuName;
   	this.id			= id;
   	this.level		= level;
   	this.mainMenu	= mainMenu;
   	this.sitemap	= newArray;
   	this.DropDownMenuName	= DropDownMenuName;

   	this.menu		= new MenuTable(this.menuName,this.id,this.level,this.mainMenu,this.sitemap,this.DropDownMenuName);
   	this.menu.CreateMenuTable();
   }
   /**
    * Prikazuje padajuci meni
    * @brief Prikazuje padajuci meni
    */
   MenuItemTable.prototype.MenuTableShow = function()
   {
   	hideExternalObjects();
   	this.menu.ShowLayer();
   }
   /**
    * Sakriva padajuci meni
    * @brief Sakriva padajuci meni
    */
   MenuItemTable.prototype.MenuTableHide = function()
   {
   	this.menu.HideLayer();
   }
   /**
    * Setuje poziciju padajuceg menija
    * @brief Setuje poziciju padajuceg menija
    * @param
         menuName:	ime padajuceg menija
         id:			id padajuceg menija
         level:		nivo padajuceg menija
         mainMenu:	id glavnog menija
         newArray:	niz elemenata padajuceg menija
    */
   MenuItemTable.prototype.MenuTableSetPosition = function(menuName,id,level,mainMenu,newArray)
   {
      var DropDownObject = eval(this.DropDownMenuName);
   	var menuLeftPos = DropDownObject.MainMenuLeftPositionAfterCheck;
   	var menuTopPos = DropDownObject.MainMenuTopPositionAfterCheck;
   	var addHeight = 0;

   	if(mainMenu != 0 && level==0){ // ovo treba promeniti kada se bude dodavao padajuci meni sleva
   		menuLeftPos = DropDownObject.MainMenuLeftPosition[mainMenu] = DropDownObject.MainMenuLeftPosition[(mainMenu-1)]
   						   +eval("document.getElementById('"+DropDownObject.MenuUpButtonCell+(mainMenu-1)+"').offsetWidth");
         if(DropDownObject.MenuUpSeparatorCell){
            menuLeftPos = DropDownObject.MainMenuLeftPosition[mainMenu] += eval("document.getElementById('"+DropDownObject.MenuUpSeparatorCell+"').offsetWidth");
         }
   		menuTopPos = DropDownObject.MainMenuTopPosition[mainMenu] = DropDownObject.MainMenuTopPosition[0];
   	} // ovo treba promeniti kada se bude dodavao padajuci meni sleva

   	if(level != 0){
   		menuLeftPos = DropDownObject.LeftPositionsByLevel[level];
   		this.left = menuLeftPos;
   		var parentLevel = level-1;
   		DropDownObject.TopPositionsByLevel[level] = DropDownObject.TopPositionsByLevel[parentLevel];
   		this.top = DropDownObject.TopPositionsByLevel[parentLevel];
   	}else{
   	   if(DropDownObject.AditionalStartLeft) menuLeftPos += DropDownObject.AditionalStartLeft;
   		DropDownObject.LeftPositionsByLevel[level] = menuLeftPos;
   		this.left = menuLeftPos;
   		DropDownObject.TopPositionsByLevel = Array();
   		if(DropDownObject.AditionalStartHeight) addHeight = 1;
   		DropDownObject.TopPositionsByLevel[level] = menuTopPos;
   		this.top = menuTopPos;
   	}
   	this.menu.top = this.top;
   	this.menu.left = this.left;
   	this.menu.SetPosLayer();
   	for(var i=0; i<newArray[id].length; i++){
   	   if( i != 0 ) DropDownObject.TopPositionsByLevel[level] += eval("document.getElementById('level"+this.level+"myTableDataMenu"+menuName+(i-1)+"').offsetHeight");
   	   if(addHeight && i == 0) DropDownObject.TopPositionsByLevel[level] += DropDownObject.AditionalStartHeight;
   		if(newArray[id][i][3]){
   			var newLevel = level+1;
   			var subMenuName = menuName+i;
   			var groupMaxWidth = DropDownObject.LeftPositionsByLevel[level] + eval("document.getElementById('myTableMenu"+menuName+"').offsetWidth") + eval("document.getElementById('myTableMenu"+subMenuName+"').offsetWidth");
   			var groupMinWidth = DropDownObject.LeftPositionsByLevel[level] - eval("document.getElementById('myTableMenu"+subMenuName+"').offsetWidth");
   			DropDownObject.LeftPositionsByLevel[newLevel] = DropDownObject.LeftPositionsByLevel[level] + eval("document.getElementById('myTableMenu"+menuName+"').offsetWidth");
   			if(groupMaxWidth > DropDownObject.StartWindowWidth && groupMinWidth > 0){
   				DropDownObject.LeftPositionsByLevel[newLevel] = DropDownObject.LeftPositionsByLevel[level] - eval("document.getElementById('myTableMenu"+subMenuName+"').offsetWidth");
   			}
   			DropDownObject.recalculatePosition(Array(newArray[id][i][6]), newLevel, mainMenu, subMenuName);
   		}
   	}
   }



   /**
    * Rad sa objektom - padajucim menijem
    * @brief Rad sa objektom - padajucim menijem
    * @param
         menuName:	ime padajuceg menija
         id:			id padajuceg menija
         level:		nivo padajuceg menija
         mainMenu:	id glavnog menija
         newArray:	niz elemenata padajuceg menija
    */
   function MenuTable(menuName,id,level,mainMenu,newArray,DropDownMenuName){
   	this.menuName	= menuName;
   	this.id			= id;
   	this.level		= level;
   	this.mainMenu	= mainMenu;
   	this.sitemap	= newArray;
   	this.DropDownMenuName = DropDownMenuName;
   	this.DropDownObject = eval(this.DropDownMenuName);

   	this.top 		= this.DropDownObject.MainMenuTopPosition[0];
   	this.left		= this.DropDownObject.MainMenuLeftPosition[0];
   	this.width		= this.DropDownObject.StartMenuTableWidth;
   	this.height		= 1;
   	this.z			= 100*(this.level+1) + 100*this.id + this.id;
   	this.ref 		= this.menuName;
   }
   /**
    * Kreira padajuci meni
    * @brief Kreira padajuci meni
    */
   MenuTable.prototype.CreateMenuTable = function()
   {
   	var text = this.getFirstLine(this.ref,this.width,this.height,this.top,this.left,this.z,"hidden");
   	text += "<table cellspacing=\"0\" border=\"0\" width=\""+this.width+"\" class=\""+this.DropDownObject.DropDownTableLevel+this.level+"\" id=\"myTableMenu"+this.menuName+"\">";
   	for(var i=0; i<this.sitemap[this.id].length; i++){
   	   CellClassName = this.DropDownObject.DropDownClassName+this.level+"Off";
   		if(this.sitemap[this.id][i][4]){
            CellClassName = this.DropDownObject.DropDownClassName+this.level+"On";
   		}
   		if(this.sitemap[this.id][i][3]){
   			newLevel = this.level+1;
   			subMenuName = this.menuName+i;
   			CellClassNameMenu = CellClassName+"Menu";
   			text += "<tr><td "+this.DropDownObject.MenuTableDataWrap+" class=\""+CellClassNameMenu+"\" id=\"level"+this.level+"myTableDataMenu"+this.menuName+i+"\" onmouseover=\""+this.DropDownMenuName+".DropDownMenuOver(1, "+this.mainMenu+", "+newLevel+", '"+subMenuName+"', this)\" onmousemove=\""+this.DropDownMenuName+".DropDownMenuOver(1, "+this.mainMenu+", "+newLevel+", '"+subMenuName+"', this)\" onmouseout=\""+this.DropDownMenuName+".DropDownMenuOut(1, "+this.mainMenu+", "+newLevel+", '"+subMenuName+"', this)\" onclick=\""+this.DropDownMenuName+".DropDownMenuPress('"+this.sitemap[this.id][i][1]+"', '"+this.sitemap[this.id][i][2]+"')\">"+this.sitemap[this.id][i][0]+"</td></tr>";
   			this.DropDownObject.createDropMenu(Array(this.sitemap[this.id][i][6]), newLevel, this.mainMenu, subMenuName);
   		}else{
   			text += "<tr><td "+this.DropDownObject.MenuTableDataWrap+" class=\""+CellClassName+"\" id=\"level"+this.level+"myTableDataMenu"+this.menuName+i+"\" onmouseover=\""+this.DropDownMenuName+".DropDownMenuOver(0, "+this.mainMenu+", "+this.level+", '"+this.menuName+"', this)\" onmousemove=\""+this.DropDownMenuName+".DropDownMenuOver(0, "+this.mainMenu+", "+this.level+", '"+this.menuName+"', this)\" onmouseout=\""+this.DropDownMenuName+".DropDownMenuOut(0, "+this.mainMenu+", "+this.level+", '"+this.menuName+"', this)\" onclick=\""+this.DropDownMenuName+".DropDownMenuPress('"+this.sitemap[this.id][i][1]+"', '"+this.sitemap[this.id][i][2]+"')\">"+this.sitemap[this.id][i][0]+"</td></tr>";
   		}
   	}
   	text += "</table>";
   	text += this.getLastLine();
   	document.write(text);
   }
   /* deo za osnovne stvari sa lejerima */
   MenuTable.prototype.getFirstLine = function(id,w,h,t,l,z,v)
   {
      return("<div id=\""+id+"\" style=\"position:absolute; width:"+w+"px; height:"+h+"px; left:"+l+"px; top:"+t+"px; z-index:"+z+"; visibility:"+v+"\">");
   }
   MenuTable.prototype.getFirstLinePic = function(id,w,h,t,l,z,v,pic)
   {
   	return("<div id=\""+id+"\" style=\"position:absolute; width:"+w+"px; height:"+h+"px; left:"+l+"px; top:"+t+"px; z-index:"+z+"; background-image:url("+pic+"); visibility:"+v+"\">");
   }
   MenuTable.prototype.getFirstLineCol = function(id,w,h,t,l,z,v,col)
   {
   	return("<div id=\""+id+"\" style=\"position:absolute; width:"+w+"px; height:"+h+"px; left:"+l+"px; top:"+t+"px; z-index:"+z+"; background-color:"+col+"; visibility:"+v+"\">");
   }
   MenuTable.prototype.getLastLine = function()
   {
      return("</div>");
   }

   MenuTable.prototype.ShowLayer = function()
   {
   	eval("document.getElementById(\""+this.ref+"\").style.visibility=\"visible\"");
      // adjust & show mask layer
      document.getElementById('dropDownMask'+this.level).style.top = document.getElementById(this.ref).style.top; 
      document.getElementById('dropDownMask'+this.level).style.left = document.getElementById(this.ref).style.left; 
      document.getElementById('dropDownMask'+this.level).style.width = document.getElementById('myTableMenu'+this.ref).offsetWidth + 'px';
      document.getElementById('dropDownMask'+this.level).style.height = document.getElementById('myTableMenu'+this.ref).offsetHeight + 'px';
      document.getElementById('dropDownMask'+this.level).style.visibility = 'visible';     
   }
   MenuTable.prototype.HideLayer = function()
   {
   	eval("document.getElementById(\""+this.ref+"\").style.visibility=\"hidden\"");
      // hide mask layer
      document.getElementById('dropDownMask'+this.level).style.visibility = 'hidden';
   }
   MenuTable.prototype.SetPosLayer = function(){
   	eval("document.getElementById(\""+this.ref+"\").style.top=\""+this.top+"\"");
   	eval("document.getElementById(\""+this.ref+"\").style.left=\""+this.left+"\"");
   }
   /* deo za osnovne stvari sa lejerima */


function hideExternalObjects()
{
   for (var i=0; i<objectsToHideById.length; i++)
      if (document.getElementById(objectsToHideById[i]))
         document.getElementById(objectsToHideById[i]).style.display = "none";         
   for (var i=0; i<replacementObjects.length; i++)
      if (document.getElementById(replacementObjects[i]))
         document.getElementById(replacementObjects[i]).style.display = "inline";         
}
function unhideExternalObjects()
{
   for (var i=0; i<objectsToHideById.length; i++)
      if (document.getElementById(objectsToHideById[i]))
         document.getElementById(objectsToHideById[i]).style.display = "inline";
   for (var i=0; i<replacementObjects.length; i++)
      if (document.getElementById(replacementObjects[i]))
         document.getElementById(replacementObjects[i]).style.display = "none";

}


