home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 February / Chip_2003-02_cd1.bin / tema / tipy / skyguard.mht / záhlaví.js < prev    next >
Encoding:
Text File  |  2003-01-06  |  4.3 KB  |  106 lines

  1. var speed = 10 
  2. var pause = 4000
  3. var timerID = null
  4. var bannerRunning = false
  5. var ar = new Array()
  6.  
  7. ar[0] = "Vφtejte na strßnkßch firmy Sky GUARD, spol. s r.o."
  8. ar[1] = "Tato strßnka je v∞novßna nejmodern∞jÜφmu bezpeΦnostnφmu za°φzenφ"
  9. ar[2] = "SkyGuard"
  10. ar[3] = "Vyu₧ijte naÜich akΦnφch slev"
  11.  
  12. var message = 0
  13.  
  14. var state = ""
  15.  
  16. clearState()
  17.  
  18. function stopBanner() {        
  19.         // if banner is currently running        
  20.         if (bannerRunning)                
  21.         // stop the banner                
  22.         clearTimeout(timerID)        
  23.         // timer is now stopped        
  24.         timerRunning = false
  25. }
  26.  
  27. // start the banner
  28. function startBanner() {        
  29. // make sure the banner is stopped        
  30.         stopBanner()        
  31. // start the banner from the current position        
  32.         showBanner()
  33. }
  34.  
  35. // assign state a string of "0" characters of the length of the current message
  36. function clearState() {        
  37. // initialize to empty string        
  38.         state = ""        
  39. // create string of same length containing 0 digits        
  40.         for (var i = 0; i < ar[message].length; ++i) {                
  41.                 state += "0"        
  42.         }
  43. }
  44.  
  45. // display the current message
  46. function showBanner() {        
  47. // if the current message is done        
  48.         if (getString()) {                
  49.         // increment message                
  50.                 message++                
  51.         // if new message is out of range wrap around to first message                
  52.         if (ar.length <= message)                        
  53.                 message = 0                
  54.                 // new message is first displayed as empty string                
  55.                 clearState()                
  56. // display next character after pause milliseconds                
  57.                 timerID = setTimeout("showBanner()", pause)        
  58.         } 
  59.         else {                
  60. // initialize to empty string                
  61.                 var str = ""                
  62. // built string to be displayed (only character selected thus far are displayed)                
  63.         for (var j = 0; j < state.length; ++j) {                        
  64.                 str += (state.charAt(j) == "1") ? ar[message].charAt(j) : "     "                
  65.         }                                
  66.         document.title = str                
  67.         timerID = setTimeout("showBanner()", speed)        
  68.         }
  69. }
  70.  
  71. function getString() {        
  72.         // set variable to true (it will stay true unless proven otherwise)        
  73.         var full = true        
  74.         // set variable to false if a free space is found in string (a not-displayed char)        
  75.         for (var j = 0; j < state.length; ++j) {                
  76.                 // if character at index j of current message has not been placed in displayed string                
  77.                 if (state.charAt(j) == 0)                        
  78.                 full = false        
  79.         }        
  80.         // return true immediately if no space found (avoid infinitive loop later)        
  81.         if (full) return true        
  82.         // search for random until free space found (braoken up via break statement)        
  83.         while (1) {                
  84.                 // a random number (between 0 and state.length - 1 == message.length - 1)                
  85.                 var num = getRandom(ar[message].length)                
  86.                 // if free space found break infinitive loop                
  87.         if (state.charAt(num) == "0")                        
  88.                 break        
  89.         }        
  90.         // replace the 0 character with 1 character at place found        
  91.         state = state.substring(0, num) + "1" + state.substring(num + 1, state.length)        
  92.         // return false because the string was not full (free space was found)        
  93.         return false
  94. }
  95.  
  96. function getRandom(max) {        
  97.         // create instance of current date        
  98.         var now = new Date()                
  99.         // create a random number (good generator)        
  100.         var num = now.getTime() * now.getSeconds() * Math.random()        
  101.         // cut random number to value between 0 and max - 1, inclusive        
  102.         return num % max
  103. }
  104. startBanner()
  105. // -->
  106.