﻿Tygrik.Window = function()
{
   var bMoveAble = true;
   var bSizeAble = true;
   var oWindowDiv = null;
   var oWindowRoom = null;
   var oWindowTable = null;
   var oWindowBody = null;
   var oWindowRow1st = null;
   var oWindowRow2nd = null;
   var oWindowRow3rd = null;
   var oWindowColumn1st1st = null;
   var oWindowColumn1st2nd = null;
   var oWindowColumn1st3rd = null;
   var oWindowColumn2nd1st = null;
   var oWindowColumn2nd2nd = null;
   var oWindowColumn2nd3rd = null;
   var oWindowColumn3rd1st = null;
   var oWindowColumn3rd2nd = null;
   var oWindowColumn3rd3rd = null;
   var oWindowTopTable = null;
   var oWindowTopBody = null;
   var oWindowTopRow = null;
   var oWindowTopColumnTitle = null;
   var oWindowTopColumnButtons = null;
   var oWindowTitle = null;
   var oWindowButtons = null;
   var oWindowArea = null;

   var bWantedResize = false; //je treba u tohoto okna kontolovat umisteni
   var sID = "";
   var sNearID = "";
 
   var iInitialWidth = 0;
   var iInitialHeight = 0;
   var iFinalWidth = 0;
   var iFinalHeight = 0;
   var iStepWidth = 50;
   var iStepHeight = 50;
   var iActualWidth = 0;
   var iActualHeight = 0;
   var iWantedWidth = 0;
   var iWantedHeight = 0;

   var iInitialLeft = 100;
   var iInitialTop = 100;
   var iFinalLeft = 100;
   var iFinalTop = 100;
   var iStepLeft = 50;
   var iStepTop = 50;
   var iActualLeft = 100;
   var iActualTop = 100;
   var iWantedLeft = 100;
   var iWantedTop = 100;

   var iActualLevel = 0;
   var iWantedLevel = 0;
   var iInitialLevel = 0;
   var iFinalLevel = 10;
   var iStepLevelUp = 1;
   var iStepLevelDown = 2;
   var iStepLevelFast = 5;

   var bActualVisible = false;
   var bWantedVisible = false;
   var sOnExit = "";
  
   this.ID = function()
   {
      return sID;
   }

   this.Div = function()
   {
      return oWindowDiv;
   }

   this.Create = function(sIDPar, sNearIDPar, iWidth, iHeight, sStyle)
   {
      var oBox = Tygrik.System.ByID("Box");
      if (oBox != null && oWindowDiv == null)
      {
         var oImage = new Image();
         var qImages = new Array();
         qImages[0] = "Images/" + sStyle + "_1stLine1stJamb.gif";
         qImages[1] = "Images/" + sStyle + "_1stLine2ndJamb.gif";
         qImages[2] = "Images/" + sStyle + "_1stLine3rdJamb.gif";
         qImages[3] = "Images/" + sStyle + "_2ndLine1stJamb.gif";
         qImages[4] = "Images/" + sStyle + "_2ndLine3rdJamb.gif";
         qImages[5] = "Images/" + sStyle + "_3rdLine1stJamb.gif";
         qImages[6] = "Images/" + sStyle + "_3rdLine2ndJamb.gif";
         qImages[7] = "Images/" + sStyle + "_3rdLine3rdJamb.gif";
         qImages[8] = "Images/Wait.gif";
         for (var iImage = 0; iImage < 9; iImage++)
         {
            oImage.src = qImages[iImage];
         }
     
         sID = sIDPar;
         sNearID = sNearIDPar;
         iFinalWidth = iWidth;
         iFinalHeight = iHeight;
         iStepWidth = iWidth / (Tygrik.Panel.bPromptly ? 2 : 5);
         iStepHeight = iHeight / (Tygrik.Panel.bPromptly ? 2 : 5);
         
         var iBoxWidth = document.body.offsetWidth; //screen.width; //oBox.clientWidth;
         var iBoxHeight = document.body.offsetHeight; //screen.height; //oBox.clientHeight;
         var oPos = new Tygrik.Style.Pos();
         oPos.x = iBoxWidth / 2 - iFinalWidth / 2;
         oPos.y = iBoxHeight / 2 - iFinalHeight / 2;
         if (sNearID.length != 0)
         {
            var oNear = Tygrik.System.ByID(sNearID);
            if (oNear != null)
            {
               Tygrik.Style.GetPosition(oNear, oPos);

               // posunuti pod prvek
               oPos.y = oPos.y + Tygrik.Style.SizeHeight(oNear);
            }
         }
         iInitialLeft = iBoxWidth / 2;
         iInitialTop = iBoxHeight / 2;
         iFinalLeft = oPos.x;
         //alert("fl:" + iFinalLeft + " fw:" + iFinalWidth + "bw:" + iBoxWidth);
         if (iFinalLeft + iFinalWidth > iBoxWidth)
         {
            iFinalLeft = iBoxWidth - iFinalWidth;
         }
         iFinalTop = oPos.y;
         //alert("ft:" + iFinalTop + " fh:" + iFinalHeight + "bh:" + iBoxHeight);
         if (iFinalTop + iFinalHeight > iBoxHeight)
         {
            iFinalTop = iBoxHeight - iFinalHeight;
         }
         iStepLeft = (iFinalLeft > iInitialLeft ? iFinalLeft - iInitialLeft : iInitialLeft - iFinalLeft) / (Tygrik.Panel.bPromptly ? 2 : 5);
         iStepTop = (iFinalTop > iInitialTop ? iFinalTop - iInitialTop : iInitialTop - iFinalTop) / (Tygrik.Panel.bPromptly ? 2 : 5);
         iActualLeft = iInitialLeft;
         iActualTop = iInitialTop;
         iWantedLeft = iInitialLeft;
         iWantedTop = iInitialTop;
         
         oWindowDiv = document.createElement("div");
         oWindowDiv.id = sID;
         oWindowDiv.className = "ClassDiv" + sStyle;
         oWindowDiv.setAttribute(Tygrik.Window.AttributeName, sID);
         oWindowRoom = document.createElement("div");
         oWindowRoom.className = "ClassDiv" + sStyle + "Room";
         oWindowRoom.style.width = iFinalWidth +'px';
         oWindowRoom.style.height = iFinalHeight +'px';
          oWindowTable = document.createElement("table");
          oWindowTable.id = sID + "Table";
          oWindowTable.className = "ClassTable" + sStyle + "Table";
          oWindowBody = document.createElement("tbody");
          oWindowTable.appendChild(oWindowBody);
           oWindowRow1st = document.createElement("tr");
           oWindowRow1st.className = "ClassTr" + sStyle + "Row1st";
            oWindowColumn1st1st = document.createElement("td");
            oWindowColumn1st1st.className = "ClassTd" + sStyle + "Column1stLine1stJamb";
            oWindowColumn1st1st.style.width = 20 +'px';
            oWindowColumn1st1st.style.height = 50 +'px';
            oWindowRow1st.appendChild(oWindowColumn1st1st);
            oWindowColumn1st2nd = document.createElement("td");
            oWindowColumn1st2nd.className = "ClassTd" + sStyle + "Column1stLine2ndJamb";
            oWindowColumn1st2nd.style.width = iFinalWidth - 40 +'px';
            oWindowColumn1st2nd.style.height = 50 +'px';
             oWindowTopTable = document.createElement("table");
             oWindowTopTable.className = "ClassTable" + sStyle + "TopTable";
             oWindowTopBody = document.createElement("tbody");
              oWindowTopRow = document.createElement("tr");
              oWindowTopRow.className = "ClassTr" + sStyle + "TopRow";
               oWindowTopColumnTitle = document.createElement("td");
               oWindowTopColumnTitle.className = "ClassTd" + sStyle + "TopColumnTitle";
                oWindowTitle = document.createElement("div");
                oWindowTitle.className = "ClassDiv" + sStyle + "Title";
                oWindowTitle.innerHTML = "Moment prosím...";
                oWindowTopColumnTitle.appendChild(oWindowTitle);
               oWindowTopRow.appendChild(oWindowTopColumnTitle);
               oWindowTopColumnButtons = document.createElement("td");
               oWindowTopColumnButtons.className = "ClassTd" + sStyle + "TopColumnButtons";
                oWindowButtons = document.createElement("div");
                oWindowButtons.className = "ClassDiv" + sStyle + "Buttons";
                oWindowButtons.innerHTML = "";
                oWindowTopColumnButtons.appendChild(oWindowButtons);
               oWindowTopRow.appendChild(oWindowTopColumnButtons);
              oWindowTopBody.appendChild(oWindowTopRow);
              oWindowTopTable.appendChild(oWindowTopBody);
             oWindowColumn1st2nd.appendChild(oWindowTopTable);
            oWindowRow1st.appendChild(oWindowColumn1st2nd);
            oWindowColumn1st3rd = document.createElement("td");
            oWindowColumn1st3rd.className = "ClassTd" + sStyle + "Column1stLine3rdJamb";
            oWindowColumn1st3rd.style.width = 20 +'px';
            oWindowColumn1st3rd.style.height = 50 +'px';
            oWindowRow1st.appendChild(oWindowColumn1st3rd);
           oWindowBody.appendChild(oWindowRow1st);
           oWindowRow2nd = document.createElement("tr");
           oWindowRow2nd.className = "ClassTr" + sStyle + "Row2nd";
            oWindowColumn2nd1st = document.createElement("td");
            oWindowColumn2nd1st.className = "ClassTd" + sStyle + "Column2ndLine1stJamb";
            oWindowColumn2nd1st.style.width = 20 +'px';
            oWindowColumn2nd1st.style.height = iFinalHeight - 70 +'px';
            oWindowRow2nd.appendChild(oWindowColumn2nd1st);
            oWindowColumn2nd2nd = document.createElement("td");
            oWindowColumn2nd2nd.className = "ClassTd" + sStyle + "Column2ndLine2ndJamb";
            oWindowColumn2nd2nd.style.width = iFinalWidth - 40 +'px';
            oWindowColumn2nd2nd.style.height = iFinalHeight - 70 +'px';
             oWindowArea = document.createElement("div");
             oWindowArea.className = "ClassDiv" + sStyle + "Area";
             oWindowArea.style.width = iFinalWidth - 40 +'px';
             oWindowArea.style.height = iFinalHeight - 70 +'px';
             oWindowArea.innerHTML = "<img src=\"Images/Wait.gif\" alt=\"Moment prosím...\" class=\"ClassImgWait\" />";
             oWindowColumn2nd2nd.appendChild(oWindowArea);
            oWindowRow2nd.appendChild(oWindowColumn2nd2nd);
            oWindowColumn2nd3rd = document.createElement("td");
            oWindowColumn2nd3rd.className = "ClassTd" + sStyle + "Column2ndLine3rdJamb";
            oWindowColumn2nd3rd.style.width = 20 +'px';
            oWindowColumn2nd3rd.style.height = iFinalHeight - 70 +'px';
            oWindowRow2nd.appendChild(oWindowColumn2nd3rd);
           oWindowBody.appendChild(oWindowRow2nd);
           oWindowRow3rd = document.createElement("tr");
           oWindowRow3rd.className = "ClassTr" + sStyle + "Row3rd";
            oWindowColumn3rd1st = document.createElement("td");
            oWindowColumn3rd1st.className = "ClassTd" + sStyle + "Column3rdLine1stJamb";
            oWindowColumn3rd1st.style.width = 20 +'px';
            oWindowColumn3rd1st.style.height = 20 +'px';
            oWindowRow3rd.appendChild(oWindowColumn3rd1st);
            oWindowColumn3rd2nd = document.createElement("td");
            oWindowColumn3rd2nd.className = "ClassTd" + sStyle + "Column3rdLine2ndJamb";
            oWindowColumn3rd2nd.style.width = 20 +'px';
            oWindowColumn3rd2nd.style.height = 20 +'px';
            oWindowRow3rd.appendChild(oWindowColumn3rd2nd);
            oWindowColumn3rd3rd = document.createElement("td");
            oWindowColumn3rd3rd.className = "ClassTd" + sStyle + "Column3rdLine3rdJamb";
            oWindowColumn3rd3rd.style.width = 20 +'px';
            oWindowColumn3rd3rd.style.height = 20 +'px';
            oWindowRow3rd.appendChild(oWindowColumn3rd3rd);
           oWindowBody.appendChild(oWindowRow3rd);
          oWindowTable.appendChild(oWindowBody);
          oWindowRoom.appendChild(oWindowTable);
          oWindowDiv.appendChild(oWindowRoom);
          oBox.appendChild(oWindowDiv);

         Tygrik.Window.qWindows[Tygrik.Window.qWindows.length] = this;
         if(bMoveAble)
         {
            Tygrik.Style.Cursor(oWindowTitle, "move");
            Tygrik.Mouse.Drag.SetDragAble(oWindowTitle, sID);
            oWindowDiv.setAttribute(Tygrik.Mouse.Drag.AttributePosName, Tygrik.Mouse.Drag.sPosFixed);
         }
         
         if(bSizeAble)
         {
            Tygrik.Mouse.Size.doLoad();
            Tygrik.Mouse.Size.SetSizeAble(oWindowColumn1st1st, sID, Tygrik.Mouse.Size.oMethod.sUpLeft);
            Tygrik.Mouse.Size.SetSizeAble(oWindowColumn1st2nd, sID, Tygrik.Mouse.Size.oMethod.sUp);
            Tygrik.Mouse.Size.SetSizeAble(oWindowTopColumnTitle, sID, Tygrik.Mouse.Size.oMethod.sUp);
            Tygrik.Mouse.Size.SetSizeAble(oWindowColumn1st3rd, sID, Tygrik.Mouse.Size.oMethod.sUpRight);
            Tygrik.Mouse.Size.SetSizeAble(oWindowColumn2nd1st, sID, Tygrik.Mouse.Size.oMethod.sLeft);
            Tygrik.Mouse.Size.SetSizeAble(oWindowColumn2nd3rd, sID, Tygrik.Mouse.Size.oMethod.sRight);
            Tygrik.Mouse.Size.SetSizeAble(oWindowColumn3rd1st, sID, Tygrik.Mouse.Size.oMethod.sDownLeft);
            Tygrik.Mouse.Size.SetSizeAble(oWindowColumn3rd2nd, sID, Tygrik.Mouse.Size.oMethod.sDown);
            Tygrik.Mouse.Size.SetSizeAble(oWindowColumn3rd3rd, sID, Tygrik.Mouse.Size.oMethod.sDownRight);
         }

      }
   }

   this.SetSize = function(sSize)
   {
      iFinalWidth = sSize.w;
      iFinalHeight = sSize.h;
      oWindowDiv.style.width = iFinalWidth +'px';
      oWindowDiv.style.height = iFinalHeight +'px';
      oWindowRoom.style.width = iFinalWidth +'px';
      oWindowRoom.style.height = iFinalHeight +'px';
      oWindowColumn1st2nd.style.width = iFinalWidth - 40 +'px';  
      oWindowColumn2nd1st.style.height = iFinalHeight - 70 +'px'; 
      oWindowColumn2nd2nd.style.width = iFinalWidth - 40 +'px';
      oWindowColumn2nd2nd.style.height = iFinalHeight - 70 +'px';
      oWindowArea.style.width = iFinalWidth - 40 +'px';
      oWindowArea.style.height = iFinalHeight - 70 +'px';
      oWindowColumn2nd3rd.style.height = iFinalHeight - 70 +'px';
   }

   this.Show = function()
   {
      //Tygrik.Panel.PageFade();
      Tygrik.Panel.NewFade();
      var oFade = Tygrik.System.ByID("tygrik_fade");
      if (oFade != null)
      {
        oFade.setAttribute("href", "javascript:Tygrik.Window.AllHide()");
      }
      
      iWantedWidth = iFinalWidth;
      iWantedHeight = iFinalHeight;
      iWantedLeft = iFinalLeft;
      iWantedTop = iFinalTop;
      iWantedLevel = iFinalLevel;
      bWantedVisible = true;
      this.WantedResize();
   }

   this.Hide = function()
   {
      iWantedWidth = iInitialWidth;
      iWantedHeight = iInitialHeight;
      iWantedLeft = iInitialLeft;
      iWantedTop = iInitialTop;
      iWantedLevel = iInitialLevel; 
      bWantedVisible = false;
      this.WantedResize();
      
      Tygrik.Panel.NewFadeRestore();
      //Tygrik.Panel.Restore();
   }

   this.Visible = function()
   {
      return bActualVisible && bWantedVisible;
   }

   this.Exit = function(sOnExitPar)
   {
      sOnExit = sOnExitPar;
   }

   this.Destroy = function()
   {
      var oBox = Tygrik.System.ByID("Box");
      if (oBox != null && oWindowDiv != null)
      {
         var iFound = -1;
         var iWindows = Tygrik.Window.qWindows.length;
         for (var iWindow = 0; iWindow < iWindows; iWindow++)
         {
            var oWindowNow = Tygrik.Window.qWindows[iWindow];
            if (oWindowNow == this)
            {
               iFound = iWindow;
               break;
            }
         }
         if (iFound != -1)
         {
            Tygrik.Window.qWindows.splice(iFound, 1);
         }

            oWindowRow3rd.removeChild(oWindowColumn3rd3rd);
            oWindowColumn3rd3rd = null;
            oWindowRow3rd.removeChild(oWindowColumn3rd2nd);
            oWindowColumn3rd2nd = null;
            oWindowRow3rd.removeChild(oWindowColumn3rd1st);
            oWindowColumn3rd1st = null;
           oWindowBody.removeChild(oWindowRow3rd);
           oWindowRow3rd = null;
            oWindowRow2nd.removeChild(oWindowColumn2nd3rd);
            oWindowColumn2nd3rd = null;
             oWindowColumn2nd2nd.removeChild(oWindowArea);
             oWindowArea = null;
            oWindowRow2nd.removeChild(oWindowColumn2nd2nd);
            oWindowColumn2nd2nd = null;
            oWindowRow2nd.removeChild(oWindowColumn2nd1st);
            oWindowColumn2nd1st = null;
           oWindowBody.removeChild(oWindowRow2nd);
           oWindowRow2nd = null;
            oWindowRow1st.removeChild(oWindowColumn1st3rd);
            oWindowColumn1st3rd = null;
                oWindowTopColumnButtons.removeChild(oWindowButtons);
                oWindowButtons = null;
               oWindowTopRow.removeChild(oWindowTopColumnButtons);
               oWindowTopColumnButtons = null;
                oWindowTopColumnTitle.removeChild(oWindowTitle);
                oWindowTitle = null;
               oWindowTopRow.removeChild(oWindowTopColumnTitle);
               oWindowTopColumnTitle = null;
              oWindowTopBody.removeChild(oWindowTopRow);
              oWindowTopRow = null;
              oWindowTopTable.removeChild(oWindowTopBody);
              oWindowTopBody = null;
             oWindowColumn1st2nd.removeChild(oWindowTopTable);
             oWindowTopTable = null;
            oWindowRow1st.removeChild(oWindowColumn1st2nd);
            oWindowColumn1st2nd = null;
            oWindowRow1st.removeChild(oWindowColumn1st1st);
            oWindowColumn1st1st = null;
           oWindowBody.removeChild(oWindowRow1st);
           oWindowRow1st = null;
           oWindowTable.removeChild(oWindowBody);
           oWindowBody = null;
          oWindowRoom.removeChild(oWindowTable);
          oWindowTable = null;
          oWindowDiv.removeChild(oWindowRoom);
          oWindowRoom = null;
         oBox.removeChild(oWindowDiv);
         oWindowDiv = null;
      }
   }
   
   this.Title = function(sTitle)
   {
      if (oWindowTitle != null)
      {
         oWindowTitle.innerHTML = sTitle;
      }
   }
   
   this.Buttons = function(sButtons)
   {
      if (oWindowButtons != null)
      {
         oWindowButtons.innerHTML = sButtons;
      }
   }

   this.Area = function(sArea)
   {
      if (oWindowArea != null)
      {
         oWindowArea.innerHTML = sArea;
      }
   }

   this.DoFire = function(sResult)
   {     
      var qItems = sResult.split(Tygrik.Change.MarkerDo(Tygrik.MarkerItem));
      if (qItems.length == 3)
      {
         var sTitle = qItems[0];
         var sButtons = qItems[1];
         var sArea = qItems[2];

         this.Title(sTitle);
         this.Buttons(sButtons);
         this.Area(sArea);
      }
   }

   this.WantedResize = function()
   {
      bWantedResize = true;
      Tygrik.Window.TimerStart();
   }
   
   this.onResize = function()
   {
      this.WantedResize();
   }
   
   this.DoResize = function()
   {
      if (bWantedResize)
      {
         if (iActualHeight != iWantedHeight)
         {
            if (iActualHeight > iWantedHeight)
            {
               if (iActualHeight - iStepHeight > iWantedHeight)
               {
                  iActualHeight = iActualHeight - iStepHeight;
               }
               else
               {
                 iActualHeight = iWantedHeight;
               }
            }
            if (iActualHeight < iWantedHeight)
            {
               if (iActualHeight + iStepHeight < iWantedHeight)
               {
                  iActualHeight = iActualHeight + iStepHeight;
               }
               else
               {
                  iActualHeight = iWantedHeight;
               }
            }

            oWindowDiv.style.height = ((iActualHeight) + 'px');
         }

         if (iActualWidth != iWantedWidth)
         {
            if (iActualWidth > iWantedWidth)
            {
               if (iActualWidth - iStepWidth > iWantedWidth)
               {
                  iActualWidth = iActualWidth - iStepWidth;
               }
               else
               {
                  iActualWidth = iWantedWidth;
               }
            }     
            if (iActualWidth < iWantedWidth)
            {
               if (iActualWidth + iStepWidth < iWantedWidth)
               {
                  iActualWidth = iActualWidth + iStepWidth;
               }
               else
               {
                  iActualWidth = iWantedWidth;
               }
            }

            oWindowDiv.style.width = ((iActualWidth) + 'px');
         }
        
         if (iActualTop != iWantedTop)
         {
            if (iActualTop > iWantedTop)
            {
               if (iActualTop - iStepTop > iWantedTop)
               {
                  iActualTop = iActualTop - iStepTop;
               }
               else
               {
                 iActualTop = iWantedTop;
               }
            }
            if (iActualTop < iWantedTop)
            {
               if (iActualTop + iStepTop < iWantedTop)
               {
                  iActualTop = iActualTop + iStepTop;
               }
               else
               {
                  iActualTop = iWantedTop;
               }
            }

            oWindowDiv.style.top = ((iActualTop) + 'px');
         }

         if (iActualLeft != iWantedLeft)
         {
            if (iActualLeft > iWantedLeft)
            {
               if (iActualLeft - iStepLeft > iWantedLeft)
               {
                  iActualLeft = iActualLeft - iStepLeft;
               }
               else
               {
                  iActualLeft = iWantedLeft;
               }
            }     
            if (iActualLeft < iWantedLeft)
            {
               if (iActualLeft + iStepLeft < iWantedLeft)
               {
                  iActualLeft = iActualLeft + iStepLeft;
               }
               else
               {
                  iActualLeft = iWantedLeft;
               }
            }

            oWindowDiv.style.left = ((iActualLeft) + 'px');
         }
      
         if (iActualLevel != iWantedLevel)
         {
            var bShadeNow = false;
            if (iActualLevel > iWantedLevel)
            {
               iActualLevel = iActualLevel - (Tygrik.Panel.bPromptly ? iStepLevelFast : iStepLevelDown);
               bShadeNow = true;
            }     
            if (iActualLevel < iWantedLevel)
            {
               iActualLevel = iActualLevel + (Tygrik.Panel.bPromptly ? iStepLevelFast : iStepLevelUp);
               bShadeNow = true;
            }
            if (bShadeNow)
            {
               Tygrik.Style.Opacity(oWindowDiv, iActualLevel);
            }        
         }

         if (bActualVisible != bWantedVisible)
         {
            if (bWantedVisible)
            {
               if (iActualWidth != 0 ||                
                   iActualHeight != 0)
               {
                  Tygrik.Style.Visibility(oWindowDiv, true);
                  Tygrik.Style.ZIndex(oWindowDiv, 100);
                  bActualVisible = true;
               }
            }
            else
            {
               if (iActualWidth == iWantedWidth && 
                   iActualWidth == 0 && 
                   iActualHeight == iWantedHeight &&                
                   iActualHeight == 0)
               {
                  Tygrik.Style.Visibility(oWindowDiv, false);
                  Tygrik.Style.ZIndex(oWindowDiv, -100);
                  bActualVisible = false;
            
                  Tygrik.Panel.Restore();
                  if (sOnExit.length != 0)
                  {
                     setTimeout(sOnExit + "('" + sID + "')", 100);
                  }
               }
            }
         }
         
         bWantedResize = (iActualHeight != iWantedHeight || iActualWidth != iWantedWidth || iActualTop != iWantedTop || iActualLeft != iWantedLeft || iActualLevel != iWantedLevel || bActualVisible != bWantedVisible);
      }
      
      return bWantedResize;
   }
   
}

Tygrik.Window.qWindows = new Array();
Tygrik.Window.AttributeName = "tygrik_window"; 
Tygrik.Window.iWindowTimerTime = 10;
Tygrik.Window.bTimerWork = false;
Tygrik.Window.TimerStart = function()
{
   if (!Tygrik.Window.bTimerWork)
   {
      Tygrik.Window.bTimerWork = true;
      setTimeout('Tygrik.Window.onTimerWindows()', 1);
   }
}

Tygrik.Window.TimerStop = function()
{
   Tygrik.Window.bTimerWork = false;
}

Tygrik.Window.JustNow = function()
{
   Tygrik.Window.onTimerWindows();
   Tygrik.Window.onTimerWindows();
   Tygrik.Window.onTimerWindows();
   Tygrik.Window.onTimerWindows();
   Tygrik.Window.onTimerWindows();
}

Tygrik.Window.onTimerWindows = function()
{
   if (Tygrik.Window.bTimerWork)
   {
      var bStayTimer = false;
      var iWindows = Tygrik.Window.qWindows.length;
      for (var iWindow = 0; iWindow < iWindows; iWindow++)
      {
         var oWindowNow = Tygrik.Window.qWindows[iWindow];
         var bWantedResize = oWindowNow.DoResize();
         if (bWantedResize)
         {
            bStayTimer = true;
         }
      }

      if (bStayTimer)
      {
         setTimeout('Tygrik.Window.onTimerWindows()', Tygrik.Window.iWindowTimerTime);
      }
      else
      {
         Tygrik.Window.TimerStop();
      }
   }
}

Tygrik.Window.oTest = null;

Tygrik.Window.Show = function()
{
   if (Tygrik.Window.oTest == null)
   {
      Tygrik.Window.oTest = new Tygrik.Window();
      Tygrik.Window.oTest.Create("Window_Window_Test", "", 300, 200, "WindowDefault");
      Tygrik.Window.oTest.Title("Pokusné okno");
      Tygrik.Window.oTest.Buttons("<a href='javascript:Tygrik.Window.Hide()' class='ClassABandXLink Class-BandXBlock Class-BandXAdminNormal Class-BandCancelEnabled' title='Zavřít'></a>");
      Tygrik.Window.oTest.Area("Textík...");
   }
   
   Tygrik.Window.oTest.Show();
}

Tygrik.Window.Hide = function()
{
   if (Tygrik.Window.oTest != null)
   {
      Tygrik.Window.oTest.Exit("Tygrik.Window.Exit");
      Tygrik.Window.oTest.Hide();
   }
}

Tygrik.Window.Exit = function(sID)
{
   if (Tygrik.Window.oTest != null)
   {
      if (Tygrik.Window.oTest.ID() == sID)
      {
         Tygrik.Window.oTest.Destroy();     
         Tygrik.Window.oTest = null;
      }
   }
}

Tygrik.Window.SetSizeById = function(sId, oSize)
{
  if (sId != "")
  {
    var oWindow = Tygrik.Window.Find(sId);
    if (oWindow != null)
    {
      oWindow.SetSize(oSize);
      return true;
    }
  }
  return false;
}

Tygrik.Window.Find = function(sWindowId)
{
    var iLength = Tygrik.Window.qWindows.length;
    for (var iNow = 0; iNow < iLength; iNow++)
    {
       var oWindowNow = Tygrik.Window.qWindows[iNow];
       if (oWindowNow.ID() == sWindowId)
       {
          return  oWindowNow;
       }
    }   
    return null; 
}

Tygrik.Window.AllHide = function()
{
   var iLength = Tygrik.Window.qWindows.length;
    for (var iNow = 0; iNow < iLength; iNow++)
    {
       var oWindowNow = Tygrik.Window.qWindows[iNow];
       if (oWindowNow != null)
       {
          oWindowNow.Hide();
       }
    }  
}
