<!--
/// Part of Opera browser detection script copied from 
/// http://developer.netscape.com/docs/examples/javascript/browser_type.html

var agt = navigator.userAgent.toLowerCase();
var isOpera = ( (agt.indexOf("opera") != -1)
                 && document.getElementById   ) ? 1 : 0;


var isNav4 = (document.layers && !isOpera) ? 1 : 0;
var isIE4  = (document.all && !isOpera) ? 1 : 0;

var isMoz  = ( document.getElementById && !(isNav4 || isIE4 || isOpera) ) ? 1 : 0;


/// Netscape 4 Resize Fix
/// Copied from Dan Steinman's "Dynamic Duo" site:
/// http://www.dansteinman.com/dynduo/en/widthheight.html

if (isNav4) {
  widthCheck = window.innerWidth;
  heightCheck = window.innerHeight;
  window.onResize = resizeFix;
}

function resizeFix() {
  if ( widthCheck != window.innerWidth || heightCheck != window.innerHeight )
    document.location.href = document.location.href;
} 


// smooth moving

var smooth_timer;

// TODO: use a Timer for this, not TimeOut?

function setSmoothTop(cur_abs_top, target_rel_top, scrolled, timeout) {
  layer = smooth_layer;
  target_abs_top = scrolled + target_rel_top;
  diff = target_abs_top - cur_abs_top;
  
  if (diff != 0) {
    diff_part = lookup_diff(diff);
    new_abs_top = cur_abs_top + diff_part;
    setTop(layer, new_abs_top);
    cmdstring = "setSmoothTop(" + new_abs_top + "," + target_rel_top + "," + scrolled + "," + timeout + ")";

    if (smooth_timer) {
      // When the user didn't wait for the div to reposition itself but has scrolled
      // before the div was ready, a timeout for the scrolling will be active. Remove
      // it, otherwise the div will never finish positioning itself, as the two timeouts
      // work against each other.
      window.clearTimeout(smooth_timer);
    }
    smooth_timer = window.setTimeout( cmdstring, timeout );
  }
}


function getTop(layer) {
  if (isNav4)
    t = layer.top;
  else
    if (isIE4)
      t = layer.style.pixelTop;
    else
      if (isMoz) {
        t = layer.style.top;
      }
      else
        if (isOpera)          
          t = layer.style.top;
  i = parseInt(t); // remove '..px' if present
  return i
}

function setTop(layer, t) {
  if (isNav4)
    layer.top = t;
  else
    if (isIE4)
      layer.style.pixelTop = t;
    else
      if (isMoz) {
        var p = '' + t + 'px';
        layer.style.top = p;
      }
      else
        if (isOpera)          
          layer.style.top = t;
}

function getDiv(divname) {
	// given name 'divname', return div object
	// if div is within otherdiv, use 'otherdivname.divname' format as parameter

	divs = divname.split('.'); 

	if (isNav4) {
		s = '';
		for (i = 0; i < divs.length; i++) {
			s += 'document.layers.' + divs[i];
			if (i < divs.length - 1) 
				s += '.';
		}		
		return  eval(s);
	}

	if (isIE4)
		return eval( 'document.all.' + divs[ divs.length-1 ] );

	if (isMoz || isOpera)
		return document.getElementById(divs[ divs.length-1 ] );
}

var do_smooth = 1;
var smooth_timeout = 30;

function lookup_diff(i) { // undefined for i=0
  
  if (i > 0) {
    n = 0.10 * i;
    if (n > 3) n++;
    return Math.ceil(n)
  } 
  if (i < 0) {
    n = 0.10 * i;
    if (n < -3) n--;
    return Math.floor(n)
  }
  if (i == 0)
    return 'error';
}


// getDiv() is, measured in time, an expensive function.
// Making ..._layer global vars will probably be faster than 
// calling getDiv() all the time.

var moving_layer;
var smooth_layer;


function update(scrollPos) {
  if (do_smooth)
    setSmoothTop( getTop(smooth_layer), 10, scrollPos,
                  smooth_timeout);
  else {
    setTop(moving_layer, scrollPos+10);
  }
}

var S;
 
function initSpy() {
  moving_layer = getDiv('A','Indice1');
  smooth_layer = moving_layer; 
  S = new scrollSpy(update);
  S.start();
}


// -->