home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 August / Chip_2004-08_cd1.bin / program / delphi / adresy / ee_soubory / Utils.js < prev   
Text File  |  2004-05-11  |  6KB  |  256 lines

  1. var
  2.   Menus,           // Textdescription of all menus.
  3.   themenu,         // Current menu on screen.
  4.   themenuStyle,    // The style member of the current menu.
  5.   thestring;       // Helper for browser detection.
  6.  
  7.   Images = new Array();
  8.  
  9. //-------------------------------------------------------------------------------------------------
  10.  
  11. function PreloadImages()
  12. {
  13.   for (i = 0; i < PreloadImages.arguments.length;i++)
  14.   {
  15.     Images[i] = new Image();
  16.     Images[i].src = PreloadImages.arguments[i];
  17.   };
  18. };
  19.  
  20. //-------------------------------------------------------------------------------------------------
  21.  
  22. function GetObject(Name)
  23.  
  24. {
  25.   if (is.DOM1 || is.opera6)
  26.   {
  27.     this.obj = document.getElementById(Name);
  28.     this.style = this.obj.style;
  29.   }
  30.   else
  31.     if (is.ie)
  32.     {
  33.       this.obj = document.all[Name];
  34.       this.style = this.obj.style;
  35.     }
  36.     else
  37.       if (is.nav)
  38.       {
  39.         this.obj = GetObjectNetscape4(document, Name);
  40.         this.style = this.obj;
  41.       };
  42. };
  43.  
  44. //-------------------------------------------------------------------------------------------------
  45.  
  46. function GetObjectNetscape4(obj, Name)
  47.  
  48. {
  49.   var
  50.     x = obj.layers;
  51.   var
  52.     thereturn;
  53.  
  54.   for (var i = 0; i < x.length; i++)
  55.   {
  56.     if (x[i].id == Name)
  57.       thereturn = x[i];
  58.     else
  59.       if (x[i].layers.length)
  60.       {
  61.         var
  62.           tmp = getObjNN4(x[i],name);
  63.         if (tmp)
  64.           thereturn = tmp;
  65.       }
  66.   }
  67.   return thereturn;
  68. };
  69.  
  70. //-------------------------------------------------------------------------------------------------
  71.  
  72. // fade-in/out effect
  73.  
  74. var
  75.   FadeObject;
  76. var
  77.   DoMenuFade = false;
  78.  
  79. //-------------------------------------------------------------------------------------------------
  80.  
  81. function InitFade(which)
  82. {
  83.   if (which.style.MozOpacity > 0)
  84.     which.style.MozOpacity = 0
  85.   else
  86.     if (which.filters && which.filters[0].opacity > 0)
  87.       which.filters[0].opacity = 0;
  88. };
  89.  
  90. //-------------------------------------------------------------------------------------------------
  91.  
  92. function FadeIn(which)
  93. {
  94.   if (window.highlighting)
  95.     clearInterval(highlighting);
  96.  
  97.   if (FadeObject)
  98.   {
  99.     InitFade(FadeObject);
  100.     FadeObject.style.visibility = "hidden";
  101.   };
  102.   InitFade(which);
  103.   which.style.visibility = "visible";
  104.   FadeObject = which;
  105.   highlighting = setInterval("FadeStep(FadeObject, 20)", 50)
  106. };
  107.  
  108. //-------------------------------------------------------------------------------------------------
  109.  
  110. function FadeOut(which)
  111. {
  112.   if (window.highlighting)
  113.     clearInterval(highlighting);
  114.  
  115.   FadeObject = which;
  116.   highlighting = setInterval("FadeStep(FadeObject, -20)", 50)
  117. };
  118.  
  119. //-------------------------------------------------------------------------------------------------
  120.  
  121. function FadeStep(which, step)
  122. {
  123.   if (step > 0)
  124.   {
  125.     if (which.style.MozOpacity < 1)
  126.       which.style.MozOpacity = parseFloat(which.style.MozOpacity) + step / 100
  127.     else
  128.       if (which.filters && which.filters[0].opacity < 100)
  129.         which.filters[0].opacity += step
  130.       else
  131.         if (window.highlighting)
  132.           clearInterval(highlighting);
  133.   }
  134.   else
  135.   {
  136.     if (which.style.MozOpacity > 0)
  137.       which.style.MozOpacity = parseFloat(which.style.MozOpacity) + step / 100
  138.     else
  139.       if (which.filters && which.filters[0].opacity > 0)
  140.         which.filters[0].opacity += step
  141.       else
  142.         if (window.highlighting)
  143.         {
  144.           clearInterval(highlighting);
  145.           which.style.visibility = "hidden";
  146.           FadeObject = null;
  147.         };
  148.   };
  149. };
  150.  
  151. //-------------------------------------------------------------------------------------------------
  152.  
  153. function DelayHideMenu()
  154. {
  155.   ClearShowMenu();
  156.  
  157.   delayhide = setTimeout("hidemenu()", 500)
  158. };
  159.  
  160. //-------------------------------------------------------------------------------------------------
  161.  
  162. function clearhidemenu()
  163. {
  164.   if (window.delayhide)
  165.     clearTimeout(delayhide)
  166. };
  167.  
  168. //-------------------------------------------------------------------------------------------------
  169.  
  170. function hidemenu()
  171. {
  172.   if (window.themenu)
  173.   {
  174.     if ((is.ie || is.nav6up || is.opera) && DoMenuFade)
  175.       FadeOut(window.themenu)
  176.     else
  177.       if (is.DOM1)
  178.         themenuStyle.visibility = "hidden"
  179.       else
  180.         themenu.visibility = "hide";
  181.     window.themenu = null;
  182.   };
  183. };
  184.  
  185. //-------------------------------------------------------------------------------------------------
  186.  
  187. function ClearShowMenu()
  188. {
  189.   if (window.delayshow)
  190.     clearTimeout(delayshow)
  191. };
  192.  
  193. //-------------------------------------------------------------------------------------------------
  194.  
  195. function DoShowMenu()
  196.  
  197. {
  198.   if ((is.nav6up || is.ie || is.opera) && DoMenuFade)
  199.     FadeIn(themenu)
  200.   else
  201.   {
  202.     if (themenu.style.MozOpacity)
  203.       themenu.style.MozOpacity = 1
  204.     else
  205.       if (themenu.filters && themenu.filters[0].opacity)
  206.         themenu.filters[0].opacity = 100;
  207.     if (is.DOM1)
  208.       themenuStyle.visibility = "visible"
  209.     else
  210.       themenu.visibility = "show";
  211.   };
  212. };
  213.  
  214. //-------------------------------------------------------------------------------------------------
  215.  
  216. function dropit(e, whichone, x, y)
  217. {
  218.   var
  219.     NewMenu,
  220.     WasVisible;
  221.  
  222.   WasVisible = (window.themenu);
  223.   clearhidemenu();
  224.  
  225.   NewMenu = is.DOM1 || is.opera6 ? document.getElementById(whichone) : eval(whichone);
  226.   if (WasVisible && (NewMenu == window.themenu))
  227.     return;
  228.  
  229.   hidemenu();
  230.  
  231.   themenu = NewMenu;
  232.   themenuStyle = is.DOM1 || is.opera6 ? themenu.style : themenu;
  233.  
  234.   themenuoffsetX = (is.ie) ? document.body.scrollLeft : 0;
  235.   themenuoffsetY = (is.ie) ? document.body.scrollTop : 0;
  236.  
  237.   if (is.opera || is.ie)
  238.   {
  239.     themenuStyle.left = x;
  240.     themenuStyle.top = (is.opera) ? y + 8 : y;
  241.   }
  242.   else
  243.   {
  244.     themenuStyle.left = (e.pageX - e.layerX) + x + 'px';
  245.     themenuStyle.top = e.pageY - e.layerY + y + 'px';
  246.   };
  247.  
  248.   if (WasVisible)
  249.     DoShowMenu()
  250.   else
  251.     delayshow = setTimeout("DoShowMenu()", 200);
  252.  
  253.   return true;
  254. };
  255.  
  256. //-------------------------------------------------------------------------------------------------