/* ---[ load init ]--- */
	window.onload = init;

/* ---[ init ]--- */
	function init()
	{


		// Maximize window
		//window.moveTo( 0,0 );
		//window.resizeTo( screen.width,screen.height );

		adjtabs();
		
		if( document.getElementsByTagName )
		{
			var a 	= document.getElementsByTagName( 'a' );
			for( var i = 0; i < a.length; i++ )
			{
				a[i].onfocus = function(){ this.blur() };
			}
		}
		
		filterLinks();
		
		if ( scrollto != '_' ) 
		{ 
			ScrollWin.scroll(scrollto); 
		}
		
		initShow();
		
		runShowStart();		
	}


/* ---[ Filter Links for scrolling with Scroll object ]--- */

	var scrollto	= "_";

	function filterLinks()
	{
	
		if( document.getElementsByTagName )
		{
		
			var a 	= document.getElementsByTagName( "a" );
			
			for( var i = 0; i < a.length; i++ )
			{
				temp = a[i].href.split('#');
				
				if ( temp[1] && ( a[i].id == currentSection || !a[i].id ) && ( temp[1] != 'news-comments' ) )
				{	
					a[i].href	= 'javascript: ScrollWin.scroll(\'_'+ temp[1] +'\');';
				}
			}
		}
		
		temp = location.href.split('#');
		
		if ( temp[1] )
		{
			t  = temp[1].replace( '%20', ' ' );
			t  = t.replace( '%20', ' ' );
			
			scrollto = "_" + t;
		}  
	
	}
	
	var ScrollWin = 
	{
		w3c : document.getElementById,
		iex : document.all,
		scrollLoop : false, 
		scrollInterval : null, // setInterval id
		currentBlock : null,   // object reference
		getWindowHeight : function(){
			if(this.iex) return (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
			else return window.innerHeight;
		},
		getScrollLeft : function(){
			if(this.iex) return (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
			else return window.pageXOffset;
		},
		getScrollTop : function(){
			if(this.iex) return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
			else return window.pageYOffset;
		},
		getElementYpos : function(el){
			var y = 0;
			while(el.offsetParent){
				y += el.offsetTop
				el = el.offsetParent;
			}
			return y;
		},
		scroll : function(num){ 
			if(!this.w3c){
				location.href = "#"+this.anchorName+num;
				return;
			}
			if(this.scrollLoop){
				clearInterval(this.scrollInterval);
				this.scrollLoop = false;
				this.scrollInterval = null;
			}
			if(this.currentBlock != null) this.currentBlock.className = this.offClassName;
			this.currentBlock = document.getElementById(this.blockName+num); 
			this.currentBlock.className = this.onClassName;
			var doc = document.getElementById(this.containerName);
			var documentHeight = this.getElementYpos(doc) + doc.offsetHeight;
			var windowHeight = this.getWindowHeight();
			var ypos = this.getElementYpos(this.currentBlock);
			if(ypos > documentHeight - windowHeight) ypos = documentHeight - windowHeight;
			this.scrollTo(0,ypos);
		},
		scrollTo : function(x,y){
			if(this.scrollLoop){
				var left = this.getScrollLeft();
				var top = this.getScrollTop();
				if(Math.abs(left-x) <= 1 && Math.abs(top-y) <= 1){
					window.scrollTo(x,y);
					clearInterval(this.scrollInterval);
					this.scrollLoop = false;
					this.scrollInterval = null;
				}else{
					window.scrollTo(left+(x-left)/2, top+(y-top)/2);
				}
			}else{
				this.scrollInterval = setInterval("ScrollWin.scrollTo("+x+","+y+")",100);
				this.scrollLoop = true;
			}
		}
	};

	ScrollWin.containerName = "container"; // The id name of the div containing the content
	ScrollWin.anchorName    = "anchor";    // The alpha portion of the anchor names
	ScrollWin.blockName     = "block";     // The alpha portion of the content blocks
	ScrollWin.onClassName   = "active";    // The CSS class name for the 'on' state
	ScrollWin.offClassName  = "visited";   // The CSS class name for the 'off' state
	
/* ---[ Sliding tabs ]--- */
	function tabsSlider(id, sx, sy)
	{
		var el	= d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		window[id + "_obj"] 		= el;
		
		if(d.layers)	el.style	= el;
		
		el.cx = el.sx = sx;el.cy = el.sy = sy;
		
		el.sP	= function(x,y){this.style.left=x+px;this.style.top=y+px;};
		
		el.flt=function()
		{
			var pX, pY;
			pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
			document.documentElement && document.documentElement.clientWidth ? 
			document.documentElement.clientWidth : document.body.clientWidth;
			pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
			document.documentElement.scrollTop : document.body.scrollTop;
			if(this.sy<0) 
			pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
			document.documentElement.clientHeight : document.body.clientHeight;
			this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
			this.sP(this.cx, this.cy);
			setTimeout(this.id + "_obj.flt()", 10);
		}
		
		var xx = getObj(id);
		xx.visibility = 'visible';
		return el;
	}
	
	function adjtabs()
	{
	
		var off	= 29; // width of tabs
	
		document.getElementById( 'divTopLeft' ).style.display	= 'none';
		
		var win	= getWindow();
		win		= win.split( '.' );
		
		var wW	= parseInt( win[0] );
		var wH	= parseInt( win[1] );
		var pos	= ( wW - 720 ) / 2 - off;

		tabsSlider( "divTopLeft", pos, 20 ).flt();
		
		if ( pos > 0  )
		{
			document.getElementById( 'divTopLeft' ).style.display	= 'block';
		}
	
	}


/* ---[ Popup Code ]--- */
	var popup = null;
	
	function makePopup(file, width, height, resize){
		var doCenter 	= false;		
		resize=false;
		//if((popup == null) || popup.closed){
			propties 	= '';

			if(resize) size = 'yes'; else size = 'no';	

			for(var item in window){ 
				if(item == 'screen'){ 
					doCenter = true; break; 
				} 
			}

			if(doCenter){
				if(screen.width <= width || screen.height <= height) size = 'yes';

				WndTop  = (screen.height - height) / 2;
				WndLeft = (screen.width  - width)  / 2;

				propties = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 
				'status=no,toolbar=no,directories=no,menubar=no,location=no,top=' + WndTop + ',left=' + WndLeft;
			}
			else{
				if(navigator.appName=='Netscape' && navigator.javaEnabled()){	

					var toolkit = java.awt.Toolkit.getDefaultToolkit();
					var screen_size = toolkit.getScreenSize();
		
					if(screen_size.width <= width || screen_size.height <= height) size = 'yes';	

					WndTop  = (screen_size.height - height) / 2;
					WndLeft = (screen_size.width  - width)  / 2;

					propties = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 
					'status=no,toolbar=no,directories=no,menubar=no,location=no,top=' + WndTop + ',left=' + WndLeft;
				}
				else{
					size = 'yes';

					propties = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 
					'status=no,toolbar=no,directories=no,menubar=no,location=no';
				}
			}
		
			var random	= Math.round( Math.random() * 100 );	
			popup = open(file, 'popup' + random, propties);
	}

	function closePopup()
	{
		if( popup != null )
		{
			popup.close();
			popup = null;
		}
	}


/* ---[ Masthead Slideshow ]--- */
	var show;
	var show_f;
	
	function initShow()
	{
		show		= document.getElementById( 'show' );
		show_f 	= new Fadomatic( show, 10, 0 );
	}
	
	function runShowStart()
	{
		show_f.fadeOut();
	
		setTimeout( "runShowStop()", 600 );
	
	}
	
	function runShowStop()
	{
		
		var tmp	= show.style.background;
		var rtmp	= show.style.background;
	
		var randomnumber;
	
		while ( tmp == rtmp )
		{
			randomnumber	= Math.floor( Math.random() * 20 + 1 );   /* Change the x in "x + 1" here to change teh number of expected masthead slides in the /inc/html/pix/mastheads folder */ 

			rtmp					= 'url(/inc/html/NWHI/pix/mastheads/' + randomnumber + '.jpg) 10px 10px no-repeat transparent';
		
			
		}

		document.getElementById( 'show' ).style.background	= rtmp;

		setTimeout( "show_f.fadeIn()", 600 );
	
		setTimeout( "runShowStart()", 9000 );
	
	}


/* ---[ Tools ]--- */
	function getAnchorPosition( anchorname ) 
	{
	
		var useWindow	= false;
		var coordinates	= new Object();
		var x			= 0;
		var y			= 0;
		var use_gebi	= false;	
		var use_css		= false;
		var use_layers	= false;
	
		if (document.getElementById) 
		{ 
			use_gebi	= true; 
		}
		else if (document.all) 
		{ 
			use_css		= true; 
		}
		else if (document.layers) 
		{ 
			use_layers	= true; 
		}
		
		if (use_gebi && document.all) 
		{
			x	= AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
			y	= AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
		else if (use_gebi) 
		{
			var o;
			o	= document.getElementById(anchorname);
			x	= AnchorPosition_getPageOffsetLeft(o);
			y	= AnchorPosition_getPageOffsetTop(o);
		}
		else if (use_css) 
		{
			x	= AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
			y	= AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
		else if (use_layers) 
		{
			var found	= 0;
			for (var i = 0; i < document.anchors.length; i++) 
			{
				if (document.anchors[i].name==anchorname) 
				{ 
					found=1; 
					break; 
				}
			}
			
			if (found==0) 
			{
				coordinates.x	= 0; 
				coordinates.y	= 0; 
				return coordinates;
			}
			
			x	= document.anchors[i].x;
			y	= document.anchors[i].y;
		}
		else 
		{
				coordinates.x	= 0; 
				coordinates.y	= 0; 
				
				return coordinates;
		}
	
		coordinates.x	= x;
		coordinates.y	= y;
	
		return coordinates;
	}
	
	function AnchorPosition_getPageOffsetLeft (el) 
	{
		var ol	= el.offsetLeft;
		while ((el=el.offsetParent) != null) 
		{ 
			ol 	+= el.offsetLeft; 
		}
		
		return ol;
	}
	
	function AnchorPosition_getWindowOffsetLeft (el) 
	{
		return AnchorPosition_getPageOffsetLeft(el) - document.body.scrollLeft;
	}	
	
	function AnchorPosition_getPageOffsetTop (el) 
	{
		var ot	= el.offsetTop;
		while((el=el.offsetParent) != null) 
		{ 
			ot += el.offsetTop; 
		}
		
		return ot;
	}
	
	function AnchorPosition_getWindowOffsetTop (el) 
	{
		return AnchorPosition_getPageOffsetTop(el) - document.body.scrollTop;
	}
	
	
	var b 			= new browser();
	var ns 			= (navigator.appName.indexOf("Netscape") != -1);
	var d 			= document;
	var px 			= document.layers ? "" : "px";
	
	function browser()
	{
		this.dom 	= (document.getElementById) ? true : false;
		this.ns4 	= (document.layers) ? true : false;
		this.ie 	= (document.all) ? true : false;
		this.ns6 	= this.dom && !this.ie
		this.ie4 	= this.ie && !this.dom;
		this.opera 	= (navigator.userAgent.indexOf("Opera") != -1);
		this.mac 	= (navigator.appVersion.indexOf("Mac") != -1);
		this.macie4 = this.ie4 || this.mac;
		this.dhtml 	= (this.dom || this.ns4 || this.ie || this.ie4 || 
		this.opera || !this.mac) ? true : false;
		this.dhtml 	= (this.mac)?false:true;
		return this;
	}
	
	
	function getObj(name)
	{
		if (document.getElementById)
		{
			return document.getElementById(name).style;
		}
		else if (document.all)
		{
			return document.all[name].style;
		}
		else if (document.layers)
		{
			return document.layers[name];
		}
		else 
		{
			return false;
		}
	}

	function getWindow()
	{

		var winW, winH;

		if (parseInt(navigator.appVersion)>3) 
		{
 			if (navigator.appName=="Netscape") 
			{
  				winW = window.innerWidth;
  				winH = window.innerHeight;
 			}
 			if (navigator.appName.indexOf("Microsoft")!=-1) 
			{
  				winW = document.body.offsetWidth;
  				winH = document.body.offsetHeight;
 			}
		}	

		return winW +'.'+ winH;
	}

