/*
"You have to romance the future."  -- Sydney Secord   21 Feb 2003 (age 4)
*/

var browser = navigator.appName;
var browserVers = parseInt(navigator.appVersion);
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var dom=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1
var opr=document.getElementById&&navigator.userAgent.indexOf("Opera")!=-1


var contentLayer="";


// open a new window with a virus map from ???
function virusMap() {
    window.open( 'virusmap.html', 'virusmap',
       "toolbar=off, status=off, scrollbars=off, location=off, "
       + "directories=off, width=650, height=450" )
}
function popup(url, title) {
    var newWin = window.open( url, title,
       "toolbar=no, status=no, scrollbars=yes, location=no, "
       + "directories=no, width=620, height=400" )
    newWin.focus()
}

/*
function poptop(url1, url2, title) {
    var newWin = window.open( "poptop.html", title,
       "toolbar=no, status=no, scrollbars=yes, location=no, "
       + "directories=no, width=620, height=450" )
    newWin.focus()
alert(newWin.main.location)
    newWin.main.location = url1
    newWin.note.location = url2
alert(newWin.main.location)
}
*/


// These 2 functions require the appropriate plug-in program, such as
// Quicktime vXX+.  If the try {} fails, they do nothing.
function playSound(anObj) {
	try {
	  anObj.SetVolume(25)
	  anObj.Play()
	}
        catch(e) { return true }
}
function stopSound(anObj) {
	try { anObj.Stop() }
	catch(e) { return true }
}


// Used to highlight a dimmed image
function high(image){
	theImg=image
	highlight=setInterval("highlightit(theImg)",60)
}
// Used to dim a highlighted image
function low(image){
	clearInterval(highlight)
	if (image.style.MozOpacity)
		image.style.MozOpacity = 0.5
	else if (image.filters)
		image.filters.alpha.opacity = 50
}
function highlightit(cur){
	// for some reason, when opacity gets to 1.0 in Moz, the browser loses
	// track of the mouseout event that triggers the low() function. so I
	// used .999 with .011 increments instead.
	if (cur.style.MozOpacity < 0.999) {
		cur.style.MozOpacity = parseFloat(cur.style.MozOpacity) + 0.111
	}
	else if (cur.filters && cur.filters.alpha.opacity < 100) {
		cur.filters.alpha.opacity += 10
	}
	else if (window.highlighting) {
		clearInterval(highlighting)
	}
}


// This function uses the hash part of the URL location to run the
// fadeIn() function with the appropriate arguments.  The arguments stored
// in the hash should be the names of the div areas to show.  This is a
// workaround for navigating the site with back() and forward() (and using
// the Back and Forward buttons of the browser).
function gotoHash() {
 var hash = window.location.hash.substring(1)
 // Chop off the leading X that is put there because IE is a POS and
 // doesn't follow standards.  When I use href="abc" then name an object
 // with id="abc", IE uses that as the tag.
 hash = hash.substring(1)
 if (hash.length > 0) {
  fadeIn(hash)
 }
}



var busy = false
var currA = new Array() // array of current layers
var currI = new Array()	// array of "active link" images
var currD = 0		// current depth (# of levels)
var obj = new Array()	// working array for storing levels of the new hash

var tries = 0
var toomany = 30


function fadeIn(newH, speed) {

 // VERY IMPORTANT... don't add code before the "if (busy) return" line
 // it could easily mess up the fading of layers if another link is clicked
 // before all layer transitioning is complete, causing the transition to
 // stop and leave half-visible layers, and possibly hide some that
 // shouldn't be hidden.
 if (busy) return
 busy = true

 var tmp = ""
 var i = 0
 obj.length = 0 // initialize the size ** IMPORTANT STEP **

 if (speed == null) speed = 1


 // Prep for the layer swap.  This sets up the obj[] array with the new
 // layer display tree and initializes the visibility of the new layers as
 // well as the opacity of the new and current layers.
 nav = newH.split('_')
 tmp = nav[0]
 var max = currD > nav.length ? currD : nav.length

 // This first loop composes the obj array of layers (<div>s) to be
 // manipulated along with the currA array of currently visible layers.
 for (i=0;i<nav.length;i++) {
  //alert("tmp = "+tmp)
  obj[i]=ie4 ? eval("document.all." + tmp) : document.getElementById(tmp)
  //alert("obj["+i+"] = " + obj[i].id)

  img=ie4 ? eval("document.all." + tmp + "I") : document.getElementById(tmp+"I")
  tmp = tmp + '_' + nav[i+1]

  // Might as well take care of the white dots during this part
  if (img!=null && (typeof(currI[i])=="undefined" || currI[i].id!=img.id)) {
   img.src = "img/1x1.gif"
   if (typeof(currI[i]) != "undefined") currI[i].src = "img/1x1T.gif"
  }
  if (img!=null) currI[i] = img
  //alert("finished img swap")
 }

 // This second loop initializes the layers for fading both in and out.  If
 // it so happens that the browser supports neither the Mozilla-style
 // MozOpacity, nor the IE-style filters, an inner for loop takes over to
 // do all of the layer processing by simply swapping the layers'
 // visibility (new layers are made visible, old are made hidden).
 for (i=0;i<obj.length;i++) {

  // Only initialize it if it's different than the current
  if (typeof(currA[i]) == "undefined" || currA[i].id != obj[i].id) {
   if (obj[i].style.MozOpacity < 1) { // Mozilla-based
    //alert("Moz based")
    if (currA[i] != null) currA[i].style.MozOpacity = 0.999
    obj[i].style.MozOpacity = 0.000
   }
   else if (obj[i].filters) {	// IE-based
    //alert("IE based")
    if (currA[i] != null) currA[i].filters.alpha.opacity = 100
    obj[i].filters.alpha.opacity = 0
   } else {
    //alert("neither Moz nor IE based")

    // Not sure how to program opacity with these browsers, so just swap
    // visibility of all the layers and return.

    for (j=0;j<max;j++) {
     if (j < currD && j < obj.length && currA[j].id == obj[j].id) continue;
     if (j < currD) { // hide this layer
      currA[j].style.visibility = 'hidden'
     }
     if (j < obj.length) { // show this layer
      obj[j].style.visibility = 'visible'
      currA[j] = obj[j] // copy object to the currently visible layer array
     }
    }
    currD = obj.length
    busy = false
    return
   }

   // initialize the hidden layer (should still have little opacity, so
   // will only show faintly).
   obj[i].style.visibility = 'visible'
  }
 }
 // Set timer interval to repetedly fade in new layers and fade out
 // current layers by adjusting their opacity in steps (done in fadeSwap()
 // function).
 fader = setInterval("fadeSwap(" + speed + ")",20)
}



function fadeSwap(speed) {
//alert("speed = " + speed)
 var max = currD > obj.length ? currD : obj.length
//alert("max = " + max)
 // Iterate over all the layers (new and old)
 // this loop should go from 0 to the max length of current or new layers
 for (var i=0;i<max;i++) {
 

  if (currA[i] != null && obj[i] != null && currA[i].id == obj[i].id) continue

  // For fade-in of new layers, handle Mozilla case first, then IE
  if (i<obj.length && obj[i].style.MozOpacity<0.999) {
//alert("(Moz) brightening layer "+obj[i].id)
   obj[i].style.MozOpacity = parseFloat(obj[i].style.MozOpacity)+(0.111*speed)
  } else if (i<obj.length&&obj[i].filters&&obj[i].filters.alpha.opacity<100) {
//alert("(IE) brightening layer "+obj[i].id)
   obj[i].filters.alpha.opacity += (10*speed)
  }

  // For fade-out of old layers, handle Mozilla case first, then IE
  if (i<currD && currA[i] != null && currA[i].style.MozOpacity > 0) {
//alert("(Moz) dimming layer "+currA[i].id)
   currA[i].style.MozOpacity=parseFloat(currA[i].style.MozOpacity)-(0.111*speed)
  } else if (i<currD && currA[i] != null && currA[i].filters.alpha.opacity>0) {
//alert("(IE) dimming layer "+currA[i].id)
   currA[i].filters.alpha.opacity -= (10*speed)
  }

 } // end for()


 // Check opacity of the deapest level, not top as the top may not change
 // when a link is clicked. If the new layer set has the deapest level then
 // if its deepest layer is as opaque at I want - I'm done.  On the other
 // hand, if the previous layer set (currA) has the deepest layer, then
 // check to see that it's deepest layer has as low opacity as I want - if
 // so, I'm done.
 if (++tries > toomany
    ||
    (obj.length == max && (obj[max-1].style.MozOpacity >= 0.999 ||
     (obj[max-1].filters &&
     obj[max-1].filters.alpha.opacity >= 100)))
    ||
    (currD == max && (currA[max-1].style.MozOpacity <= 0.111 ||
     (currA[max-1].filters &&
     currA[max-1].filters.alpha.opacity <= 0)))) {
  if (window.fader) clearInterval(fader)
  currD = obj.length
//alert("currD set to " + currD + " for next round")
//alert("done")
  for (i=0;i<max;i++) {
   if (currA[i] != obj[i]) {
    if (currA[i] != null) currA[i].style.visibility = 'hidden'
    currA[i] = obj[i]
    //obj[i] = null // free the array
   }
  }
  tries = 0
  busy = false
 }
}



// ------ virus information feeds from Sophos www.sophos.com

// *****************************************************************
var count	=  10	// number should be between 1 and 10
var colspan	=  2	// 2=rank number column  1=none
var target	= '_self' // '_self' or 'new' window for links
// *****************************************************************

var tmp_count = 0;
var hoax;
var HOAXhtmltxt = '<table cellpadding="3">'
            + '<tr><td colspan="' + colspan + '">'
            + '<b class="header">Top ' + count + ' hoaxes</b></td></tr>';

for (var i=0; i<hoax.length; i+=3) {
  tmp_count++;
  if (tmp_count > count) {
    break;
  } else {
    if (colspan == 1) {
      HOAXhtmltxt += '<tr><td><a href="' + hoax[i+2] + '" target="' 
      + target + '"><nobr>' + hoax[i+1] + '</nobr></a></td></tr>';
    } else {  
      HOAXhtmltxt += '<tr><td><nobr>' + hoax[i+0] + '</nobr></td><td>' 
      + '<a href="' + hoax[i+2] + '" target="' 
      + target + '"><nobr>' + hoax[i+1] + '</nobr></a></td></tr>';
    }
  }  
}
HOAXhtmltxt += '</table>';

// *****************************************************************
// Uses count, colspan, and target from above...
// var count	=  10
// var colspan	=  2
// var target	= '_self'
// *****************************************************************

var tmp_count = 0;
var LATESThtmltxt = '<table cellpadding="3">'
            + '<tr><td colspan="' + colspan + '"><b class="header">Latest ' 
            + count + ' virus alerts</b></td></tr>';

for (var i=0; i<tenalerts.length; i+=3) {
  tmp_count++;
  if (tmp_count > count) {
    break;
  } else {
    if (colspan == 1) {
      LATESThtmltxt += '<tr><td>' 
      + '<a href="' + tenalerts[i+2] + '" target="' + target + '">'
      + '<nobr>' + tenalerts[i+1]
      + '</nobr></a></td></tr>';
    } else {  
      LATESThtmltxt += '<tr><td>' 
      + '<nobr>' + tenalerts[i+0] 
      + '</nobr></td><td>' 
      + '<a href="' + tenalerts[i+2] + '" target="' 
      + target + '"><nobr>' + tenalerts[i+1]
      + '</nobr></a></td></tr>';
    }
  }  
}
LATESThtmltxt += '</table>';
// *****************************************************************
// Uses count, colspan, and target from above...
// var count	=  10
// var colspan	=  2
// var target	= '_self'
// *****************************************************************

var tmp_count = 0;
var TOPhtmltxt = '<table cellpadding="3">'
            + '<tr><td colspan="' + colspan + '">';

if (count == 1) {
  TOPhtmltxt += '<b class="header">Top virus in ' + month + '</b></td></tr>';
} else { 
  TOPhtmltxt += '<b class="header">Top ' + count + ' viruses in ' + month + '</b></td></tr>';
}

for (var i=0; i<topten.length; i+=3) {
  tmp_count++;
  if (tmp_count > count) {
    break;
  } else {
    if (colspan == 1) {
      TOPhtmltxt += '<tr><td><a href="' + topten[i+2] + '" target="' 
    } else {  
      TOPhtmltxt += '<tr><td><nobr>' + topten[i+0] 
      + '</nobr></td><td><a href="' + topten[i+2] + '" target="' 
    }
    TOPhtmltxt += target + '"><nobr>' + topten[i+1] + '</nobr></a></td></tr>';
  }  
}
TOPhtmltxt += '</table>';

