﻿    //Array to store the names of divs
	var itemArray = new Array();
	
	//when set to false, the news will stop scrolling
	var allowScroll = true;
	
	//sets up the initial position of layers
	function setupArticles() {
		setArticlePos();		
		moveUp(0,false);
	}
	
	var ie = (document.getElementById&&document.all);
	var ns = (document.getElementById&&!document.all);
	var loops = 0;
	
	//alert('=' + loops);
	
	function setArticlePos() {
	
		var scrollDiv = document.getElementById('scrollDiv');
		//loop over each item in the array
		for(var i=0;i<itemArray.length;i++) {
		
			//get the article object
			var articleDiv = document.getElementById(itemArray[i]);
			//if this is the first news article, set it to the bottom of the surrounding div.
			if(i==0) {
			
				//first loop, then start articles at top of div
				if(loops == 0) 
				{
					articleDiv.style.top = '0px';
				}
				else 
				{
					//articleDiv.style.top = (scrollDiv.offsetHeight + 3) + 'px';
					articleDiv.style.top = (scrollDiv.offsetHeight + 3) + 'px';
					
				}
			}
			else {
				articleDiv.style.top = (document.getElementById(itemArray[i-1]).offsetTop + document.getElementById(itemArray[i-1]).offsetHeight + 3) + 'px';
			}
		}
		loops++;
	}
	function moveUp(itemNum,lastItem) {
		if(allowScroll) {
			var topDiv = document.getElementById(itemArray[itemNum]);
			var bottomDiv = document.getElementById(itemArray[itemArray.length-1]);
			var scrollDiv = document.getElementById('scrollDiv');
			
			
			//if the bottom div is at the top, move all to the bottom
			if((bottomDiv.offsetTop + bottomDiv.offsetHeight) <= 0) {
				//set to original pos
				setArticlePos();
				moveUp(0,false);
			}
			else if((topDiv.offsetTop > 0) || (lastItem && (topDiv.offsetTop + topDiv.offsetHeight) > 0)) {
				//move articles up
				for(var i=0;i<itemArray.length;i++) {
					var thisArticle = document.getElementById(itemArray[i]);
					thisArticle.style.top = (thisArticle.style.top.replace('px','') - 1) + 'px';
				}
				setTimeout('moveUp(' + itemNum + ',' + lastItem + ')',2);
			}
			//else if the second div has hit the top
			else {
				var newItemNum;
				if(itemNum<itemArray.length-1) {
					newItemNum = itemNum + 1;
				}
				else if(!lastItem) {
					newItemNum = itemNum;
				}
				else {
					itemNum = 0
				}
				//pause on the news article, then scroll again
				setTimeout('moveUp(' + newItemNum + ',' + (itemNum<itemArray.length-1?'false':'true') + ')',4000);
			}
		} 
		else {
			setTimeout('moveUp(' + itemNum + ',' + lastItem + ')',2);
		}
	}


