

function positionLoop(_object) {

	//var yDestination;

	var dir;
	
	//dir=dir/Math.abs(dir);
	if(parseInt(_object.top) > parseInt(_object.yEnd) ) dir="down";
	else if(parseInt(_object.top) < parseInt(_object.yEnd) ) dir="up";
	else dir=0;
		//alert("dir:"+dir);

	 //yDestination = _object.yEnd;
	//console.log(dir);

	var currentY;
	currentY = document.getElementById(_object.id).offsetTop;//+ parseInt(dir);
	//alert("dir:"+dir+"yEnd"+_object.yEnd+"offsetTop"+document.getElementById(_object.id).offsetTop+"currentY"+currentY);
	document.getElementById('newsRSS_0').innerHTML=" dir: "+dir+" yEnd "+_object.yEnd+" offsetTop "+document.getElementById(_object.id).offsetTop+" currentY "+currentY;
	//console.log("top : "+ _object.top + " yDestination :" +yDestination +" dir : "+ dir);

	if (dir == "down" && currentY >  _object.yEnd) //moving up...so looking for
	{
		if(currentY > _object.yEnd)
		{
		document.getElementById(_object.id).style.top = (currentY-1)+'px';
		//document.getElementById(_object.id).style.opacity = 1+_object.ySpeed/10;
		//console.log(_currentY +" : " +_object.yEnd);

		setTimeout(positionLoop,100,_object);
		}
	}
	else if (dir == "up" && currentY < _object.yEnd)
	//	else if (_object.ySpeed > 0 && top >= topMin)
	{
		if(currentY < _object.yEnd)
		{
		//console.log(_currentY +" : " +_object.yEnd);
		document.getElementById(_object.id).style.top = (currentY+1)+'px';
		//document.getElementById(_object.id).style.opacity = 1+_object.ySpeed/10;
		setTimeout(positionLoop,100,_object);
		}
	}
	else
	{
			document.getElementById('newsRSS_0').innerHTML=dir;

		//flip destination with start position
		 var yTemp=_object.yEnd;
		 var topTemp=_object.top;
		 
		 _object.yEnd=topTemp;
		 _object.top=yTemp;
		
		//alert(_object.top);
		//alert(_object.yEnd);

/*
		delete yTemp;
		delete topTemp;
*/

		//console.log("at end");
	}
	delete currentY;
	delete dir;
	

}


	function moveLeft (_id) 
	{
	
		
		var position = document.getElementById(_id).offsetLeft -6;
		var leftMin = -document.getElementById(_id).offsetWidth;
		var leftMax = document.width;	
		//reset position if the position hits 0-divwidth
		if (position <= leftMin)
		{
			document.getElementById(_id).style.left = document.width + 'px';
		}
		else
		{
			//update position
			document.getElementById(_id).style.left = position +'px';//((left+document.width)%(document.width*2))+'px';
		}
	}
	
	function moveLeftStop (_id) 
	{
		var acc = document.getElementById(_id).offsetLeft / document.width;
		var position = document.getElementById(_id).offsetLeft - (20*acc);
		//var position = document.getElementById(_id).offsetLeft - 1;

		//position = position * acc;
		var leftMin = 0;
		var leftMax = document.width;	
		//reset position if the position hits 0-divwidth
		if (position <= leftMin)
		{
			document.getElementById(_id).style.left = leftMin + 'px';
		}
		else
		{
			document.getElementById(_id).style.left = position +'px';//((left+document.width)%(document.width*2))+'px';
		}
	}

function moveRightStop (_id) 
	{
		var acc = (document.getElementById(_id).offsetLeft / 600) * -1;
		var position = document.getElementById(_id).offsetLeft + (20*acc);
		//var position = (document.getElementById(_id).offsetLeft) + 1;

		var leftMin = 0;
		var leftMax = document.width;	
		//reset position if the position hits 0-divwidth
		if (position >= leftMin)
		{
			document.getElementById(_id).style.left = ''+leftMin + 'px';
		}
		else
		{
			document.getElementById(_id).style.left = ''+position +'px';
		}
	}
	
	function swipeLeftOffscreen(_id)
	{
		var acc = 1- Math.abs(document.getElementById(_id).offsetLeft / document.getElementById(_id).offsetWidth);
		var position = document.getElementById(_id).offsetLeft -(20*acc);
		//var position = document.getElementById(_id).offsetLeft - 1;

		//position = position * acc;
		var leftMin = 0 - document.getElementById(_id).offsetWidth;
		var leftMax = document.width;	
		//reset position if the position hits 0-divwidth
		//document.getElementById(_id).innerHTML = "leftMin : "+position + " "+ acc;
		if (position <= leftMin)
		{
			document.getElementById(_id).style.left = leftMin + 'px';
		}
		else
		{
			document.getElementById(_id).style.left = position +'px';//((left+document.width)%(document.width*2))+'px';
		}
	}

function swipeRightOffscreen(_id)
	{
		var acc = 1 - document.getElementById(_id).offsetLeft / document.getElementById(_id).offsetWidth;
		if (acc <=.1) acc = 1;
		var position = document.getElementById(_id).offsetLeft +(20*acc);
		var leftMin = 0 - document.getElementById(_id).offsetWidth;
		var leftMax = document.width+100;	
		//reset position if the position hits 0-divwidth
		//document.getElementById(_id).innerHTML = "leftMin : "+position + " "+ acc;
		if (position >= leftMax)
		{
			document.getElementById(_id).style.left = (document.width+100) + 'px';
		}
		else
		{
			document.getElementById(_id).style.left = position +'px';//((left+document.width)%(document.width*2))+'px';
		}
	}


	function blinkOut(_obj,op)
	{
		if(!op)op=1;
		var el=document.getElementById(_obj.id);
		el.style.opacity=op;
		if(el.style.visibility=='visible')
		{
			if(op>0) setTimeout(blinkOut,33,_obj,op-.05);
			else blinkIn(_obj);
		}
	}
	
	function blinkIn(_obj,op)
	{
		if(!op)op=0;
		var el=document.getElementById(_obj.id);	
		document.getElementById(_obj.id).style.opacity=op;
		if(el.style.visibility=='visible')
		{
			if(op<1)setTimeout(blinkIn,33,_obj,op+.05);
			else blinkOut(_obj);
		}
	}
	
	
	function fadeOut(_obj,op)
	{
		if(!op)op=1;
		var el=document.getElementById(_obj.id);
		el.style.opacity=op;
		if(el.style.visibility=='visible')
		{
			if(op>0) setTimeout(fadeOut,33,_obj,op-.05);
			//else fadeIn(_obj);
		}
	}
	
	function fadeIn(_obj,op)
	{
		if(!op)op=0;
		var el=document.getElementById(_obj.id);	
		document.getElementById(_obj.id).style.opacity=op;
		if(el.style.visibility=='visible')
		{
			if(op<1)setTimeout(fadeIn,33,_obj,op+.05);
			//else fadeOut(_obj);
		}
	}
	
	
	function scrollUp(_obj, pos)	
	{
		var el=document.getElementById(_obj.id);	

		if(!pos)pos=el.scrollTop;
		if(el.scrollTop >= el.scrollHeight-el.offsetHeight)pos=0;

		el.scrollTop=pos;
		//if(!clipPos)clipPos=0;
		//el.scrollTop=pos;
		//el.scrollTop = el.scrollHeight;
		//alert(pos);

		//var height=el.offsetHeight;
		//alert(pos);
		//document.getElementById(_obj.id).style.top=pos+"px";
		//el.style.clip='rect('+clipPos+'px '+580+'px '+(250+clipPos)+'px '+0+'px)';
		
		if(el.style.visibility=='visible')
		{
			setTimeout(scrollUp,33,_obj,pos+3.5);
		}

	
	}
	
function bottomScroll(_id,_maxHeight)
{
var el=document.getElementById(_id);	
//if (el.offsetHeight > _maxheight)
{
el.style.height = _maxHeight+'px';
//el.style.backgroundColor = 'red';
//el.style.overflow = 'visible';

}
	el.scrollTop = el.scrollHeight;
	//console.log(el.scrollHeight);
	if(el.style.visibility=='visible')
		{
		//setTimeout(bottomScroll,10000, _obj,_maxHeight);
		}
}

function arrayReveal(_titleObject, _array, _index, _type)
{
	quoteFlag = 1;

	if (_index < _array.length && _type == 0)
	{	
	_titleObject.insertHTML(_titleObject.html+' '+_array[_index]);
	setTimeout(arrayReveal,10000/(1.3*_array.length),_titleObject,_array,_index+1,0);
	}
	else if (_index < _array.length && _type == 1)
	{
	_titleObject.insertHTML(_titleObject.html+''+_array[_index]);
	setTimeout(arrayReveal,10000/(1.5*_array.length),_titleObject,_array,_index+1,1);
	}
	else
	{
	quoteFlag = 0;
	}
}


function arrayRevealRight(_titleObject, _array, _index, _type)
{
	
	
	if (_index < _array.length)
	{
	_titleObject.insertHTML(_titleObject.html+''+_array[_index]);
	if(_index == 5 || _index == 20|| _index == 35)
	{
_titleObject.insertHTML(_titleObject.html+'<people>');
}
	if (_index == 12 || _index == 27|| _index == 41)
	{
	_titleObject.insertHTML(_titleObject.html+'</people>');
	}
	
	setTimeout(arrayRevealRight,10000/(1.5*_array.length),_titleObject,_array,_index+1,1);
	}
	else
	{
	rightFlag = 0;
	}
}	
	/*
	this.scroll = function () {
	if (this.scrollFlag == 1)
	{
		var top = document.getElementById(this.id).offsetTop + this.ySpeed;

		var topMin = -document.getElementById(this.id).offsetHeight;
		var topMax = document.height + document.getElementById(this.id).offsetHeight;
		if (top <= topMin)
		{
		//this.updateText();
		document.getElementById(this.id).style.top = topMax +'px';
		}
		else if (top >= topMax)
		{
		document.getElementById(this.id).style.top = topMin + 'px';
		}
		else
		{
		document.getElementById(this.id).style.top = top +'px';//((left+document.width)%(document.width*2))+'px';
		}	
		
		
		
		
		
		
		
		var left = document.getElementById(this.id).offsetLeft + this.xSpeed;
		var leftMin = -document.getElementById(this.id).offsetWidth;
		var leftMax = document.width;
		if (left <= leftMin)
		{
			//	this.updateText();

		document.getElementById(this.id).style.left = document.width + 'px';
		}
		else if (left >= leftMax)
		{
			//	this.updateText();

		document.getElementById(this.id).style.left = leftMin + 'px';
		}
		else
		{
		document.getElementById(this.id).style.left = left +'px';//((left+document.width)%(document.width*2))+'px';
		}
	}
	this.updateText();

	}
	*/