﻿// To intialize the auto scroll Zco_NewsInit(); should be called in page laod.

var zco_NewsPanelID = "testDiv";
var zco_NewsPanelScrollIncrement = 100;
var zco_NewsAutoScrollInterval = 5000;
var zco_NewsPlay = false;
var zco_NewsPanelHeight = null;
var zco_NewsTimer = null;
var zco_NewsPanelDiv = null;

function Zco_NewsScrollUp()
{
	if(zco_NewsPanelDiv.scrollTop > 0 )
	{
		zco_NewsPanelDiv.scrollTop -= zco_NewsPanelScrollIncrement;
		Zco_NewsSetTimeOut("Zco_NewsScrollDown();");
	}else{
		Zco_NewsScrollBottom();
	}
}


function Zco_NewsScrollDown()
{
	if((zco_NewsPanelDiv.scrollTop + zco_NewsPanelHeight) < zco_NewsPanelDiv.scrollHeight)
	{
		zco_NewsPanelDiv.scrollTop += zco_NewsPanelScrollIncrement;
		Zco_NewsSetTimeOut("Zco_NewsScrollDown();");
	}
	else{
		Zco_NewsScrollTop();
	}
}

function Zco_NewsScrollTop()
{
	zco_NewsPanelDiv.scrollTop = 0;
	Zco_NewsSetTimeOut("Zco_NewsScrollDown();");
}

function Zco_NewsScrollBottom()
{
	zco_NewsPanelDiv.scrollTop = (zco_NewsPanelDiv.scrollHeight-zco_NewsPanelHeight);
	Zco_NewsSetTimeOut("Zco_NewsScrollTop();")
}

function Zco_NewsInit()
{
	zco_NewsPanelDiv = document.getElementById(zco_NewsPanelID);
	if(zco_NewsPanelHeight == null)zco_NewsPanelHeight = zco_NewsPanelDiv.offsetHeight;
	Zco_NewsScrollTop();
}

function Zco_NewsSetTimeOut(strExpression)
{
	if(zco_NewsPlay == true)
	{
		Zco_NewsClearTimeOut();			
		zco_NewsTimer = setTimeout(strExpression,zco_NewsAutoScrollInterval);
	}	
}

function Zco_NewsClearTimeOut()
{
	clearTimeout(zco_NewsTimer);
}


