/// 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;
/// if (isMoz == 1), assume it's one of:
 ///  - Mozilla 
 ///  - Opera 5, set to be identified as 'Mozilla X',
 ///    with X one of (5.0; 4.76; 3.0)

/// following not needed anymore, because we have "isOpera" now
 /// var isOpera5IE5 = ( document.all && (window.pageYOffset || window.pageYOffset == 0) ) ? 1 : 0;
 //// if (isOpera5IE5 == 1), then assume browser is Opera set to
 /// identify as 'MSIE 5' although it does not support all properties of it
 


/// 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;
} 




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 ] );

}

function update(scrollPos) {
  thediv = getDiv('A');
  setTop(thediv, scrollPos);
}

var S;
  
function initSpy() {  
  S = new scrollSpy(update);
  S.start();
}
