// JavaScript Opening Animation - Copyright 2006, Ken O. Burtch

  // Global variables for animation

  var ns6=document.getElementById&&!document.all
  var ie=document.all
  var comp_char = 3       // computed characters: used to determine what to animation
  var start_delay=20      // time to delay the start of the animation after page load
  var animation_speed=80  //in milliseconds
  var n=-start_delay

  var base_offset_spacing=1.1                 // starting space between characters
  var inc_offset_spacing=0.05                 // amount to change each iteration
  var offset_spacing=base_offset_spacing      // spacing for current item
  var offset_colour=15                        // fade factor (0..15)
  var offset_colour_str

  // Left-side function to access elements by id on different browsers

  function crossref(number){
    var crossobj=document.all? eval("document.all.compchar"+number) : document.getElementById("compchar"+number)
    return crossobj
  }

  function crossref_bar(number){
    var crossobj=document.all? eval("document.all.bar_"+number) : document.getElementById("bar_"+number)
    return crossobj
  }


  // Hexidecimal Conversion

  var hexDigit=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
  function dec2hex(dec){return(hexDigit[dec>>4]+hexDigit[dec&15]);}
  function hex2dec(hex){return(parseInt(hex,16))}

// Animation function

// This really needs to be rewritten to be cleaner

function cool_text(){

  // Initialization at startup

  if (n == -start_delay){
     m = base_offset_spacing
     n++

  // Countdown to begin

  } else if ( n < 0 ) {
     n++

     // Flicker the "Now Loading" message

     if ( Math.random() > 0.4 ) {
        crossref(4).style.color="#3366FF";
     } else {
        crossref(4).style.color="#5599FF";
     }

  // First Phase: slidy words

  } else if ( n < comp_char ) {

       // Simulate bar graph

       // These numbers are hacked to look decent...no particular logic
       crossref_bar(n*2+Math.floor(2.5-m)-1).style.backgroundColor = "#000080";

       // Flicker the "Now Loading" message
       if ( Math.random() > 0.4 ) {
          crossref(4).style.color="#3366FF";
       } else {
          crossref(4).style.color="#5599FF";
       }

       // Still fading into black?  Do the fade calculation

       if ( offset_colour > 0 ) {
          offset_colour--
          offset_colour_str = "#" + dec2hex( offset_colour + offset_colour * 16 ) +
             dec2hex( offset_colour + offset_colour * 16 ) +
             dec2hex( offset_colour + offset_colour * 16 )
       }

       // Update offset spacing.  when ideal is reached, move to next line
       // m is the counter for how much shrinkage remains

       m = m - inc_offset_spacing

       if ( m >= inc_offset_spacing ) {
          crossref(n).style.letterSpacing = m + "em"
          crossref(n).style.color = offset_colour_str
       } else {

       // continue

          crossref(n).style.letterSpacing = 0
          crossref(n).style.color = "#000000"
          m = base_offset_spacing
          offset_colour=15
          n++
       }


  // Second Phase: fade in PegaSoft title and messages

  } else if ( n == comp_char ) {

       // End of slidy fade text--fade in final stuff
       // A bit hard-coded but it works...

       if ( offset_colour == 15 ) {
          crossref(4).innerHTML = "Connecting to PegaSoft.ca ..."
       }

       if ( offset_colour > 1 ) {
          offset_colour--
          offset_colour_str = "#" + dec2hex( 255 - ( ( 255 - hex2dec( "33" ) ) / offset_colour) ) +
             dec2hex( 255 - ( ( 255 - hex2dec( "66" ) ) / offset_colour) ) +
             dec2hex( 255 - ( ( 255 - hex2dec( "FF" ) ) / offset_colour) )
          crossref(n).style.color = offset_colour_str
          crossref(n+1).style.color = offset_colour_str
          crossref(n+2).style.color = offset_colour_str
          offset_colour_str = "#" + dec2hex( 255 - (offset_colour + offset_colour * 16) ) +
             dec2hex( 255 - (offset_colour + offset_colour * 16 ) ) +
             dec2hex( 255 - (offset_colour + offset_colour * 16 ) )
          for (m=0;m<comp_char;m++) {
              crossref(m).style.color = offset_colour_str
          }
       } else {
          crossref(n).style.color = "#3366FF"
          crossref(n+1).style.color = "#3366FF"
          crossref(n+2).style.color = "#3366FF"
          for (m=0;m<comp_char;m++) {
              crossref(m).style.color = "#FFFFFF"
          }
          n=-start_delay
          clearInterval(animation_task)
          return
       }

   }

} // cool_text

// Initialization of the animation task

function begin_cool_text(){
   if (document.all||document.getElementById)
      animation_task=setInterval("cool_text()",animation_speed)
}

begin_cool_text()

