var ie4 = (document.all) ? 1 : 0;
var ns4 = (document.layers) ? 1 : 0;
var ns6 = (document.getElementById&&!document.all) ? 1 : 0;

if(typeof tapps_number=='undefined') var tapps_number = 6;
if(typeof tapps_speed=='undefined') var tapps_speed = 3;
if(typeof tapps_speed2=='undefined') var tapps_speed2 = tapps_speed;
if(typeof stopSnow=='undefined') var stopSnow = 1;

var tapps_images = "/images/tapps_trans.gif";
var tapps_width  = 11;
var tapps_height = 15;
var dx, xp, yp;    // coordinate and position variables
var am, stx, sty;  // amplitude and step variables
var i, screen_width = 800, screen_height = 600;

dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();

if (ns4||ns6) {
         screen_width = self.innerWidth;
         screen_height = self.innerHeight;
         }
else if (ie4) {
              screen_width = document.body.clientWidth;
              screen_height = document.body.clientHeight;
              }


for (i = 0; i < tapps_number; ++ i) {
                          dx[i] = 0;                        // set coordinate variables
                          xp[i] = Math.random()*(screen_width-50);  // set position variables
                          yp[i] = Math.random()*screen_height;
                          am[i] = Math.random()*20;         // set amplitude variables
                          stx[i] = 0.02 + Math.random()/10; // set step variables
                          sty[i] = 0.7 + Math.random();     // set step variables
                          if (ns4) {                      // set layers
                                   if (i == 0) {
                                               document.write("<layer name=\"dot"+ i +"\" left=\""+tapps_width+"\" ");
                                               document.write("top=\""+tapps_height+"\" visibility=\"show\"><img src=\"");
                                               document.write(tapps_images + "\" border=\"0\"></layer>");
                                               }
                                   else {
                                        document.write("<layer name=\"dot"+ i +"\" left=\""+tapps_width+"\" ");
                                        document.write("top=\""+tapps_height+"\" visibility=\"show\"><img src=\"");
                                        document.write(tapps_images + "\" border=\"0\"></layer>");
                                        }
                                   }
                          else if (ie4||ns6) {
                                        if (i == 0) {
                                                    document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
                                                    document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
                                                    document.write("visible; TOP: "+tapps_height+"px; LEFT: "+tapps_width+"px;\"><img src=\"");
                                                    document.write(tapps_images + "\" border=\"0\"></div>");
                                                    }
                                        else {
                                             document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
                                             document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
                                             document.write("visible; TOP: "+tapps_height+"px; LEFT: "+tapps_width+"px;\"><img src=\"");
                                             document.write(tapps_images + "\" border=\"0\"></div>");
                                             }
                                        }
                          }

function tappsNS() {
                   for (i = 0; i < tapps_number; ++ i) {
                                             yp[i] += sty[i];
                                             if (yp[i] > screen_height-50 ) {
                                                                            xp[i] = Math.random()*(screen_width-am[i]-30);
                                                                            yp[i] = 0;
                                                                            stx[i] = 0.02 + Math.random()/10;
                                                                            sty[i] = 0.7 + Math.random();
                                                                            screen_width = self.innerWidth;
                                                                            screen_height = self.innerHeight;
                                                                            }
                                             dx[i] += stx[i];
                                             document.layers["dot"+i].top = yp[i] + window.pageYOffset;
                                             document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]) + window.pageXOffset;
                                             }
                   if (stopSnow == 1) { tapps_speed2 = 1000000; }
                   else { tapps_speed2 = tapps_speed; }
                   setTimeout("tappsNS()", tapps_speed2);
                   }

function tappsIE() {
                   for (i = 0; i < tapps_number; ++ i) {
                                             yp[i] += sty[i];
                                             if (yp[i] > screen_height-50) {
                                                                           xp[i] = Math.random()*(screen_width-am[i]-30);
                                                                           yp[i] = 0;
                                                                           stx[i] = 0.02 + Math.random()/10;
                                                                           sty[i] = 0.7 + Math.random();
                                                                           screen_width = ns6 ? window.innerWidth-5 : document.body.clientWidth;
                                                                           screen_height = ns6 ? window.innerHeight-5 : document.body.clientHeight;
                                                                           }
                                             dx[i] += stx[i];
                                             if (ie4) {
                                                      document.all["dot"+i].style.pixelTop = yp[i] + document.body.scrollTop;
                                                      document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]) + document.body.scrollLeft;
                                                      }
                                             else if (ns6) {
                                                           document.getElementById("dot"+i).style.top=yp[i] + window.pageYOffset;
                                                           document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i]);
                                                           }
                                             }
                   if (stopSnow == 1 || ns6) { tapps_speed2 = 1000000; }
                   else { tapps_speed2 = tapps_speed; }
                   setTimeout("tappsIE()", tapps_speed2);
                   }

if (ns4) {
         tappsNS();
         }
else if (ie4||ns6) {
              tappsIE();
              }
