var scrl_alldiv = "container";
var scrl_belt = "belt";
var scrl_arrbott = "scrollbottom";
var scrl_arrtop = "scrolltop";
var scrl_picid = "isgallerypic";
var scrl_btntop = "btn_top";
var scrl_btnbottom = "btn_bottom";
var scrl_move = 0;
var scrl_lastmove = 0;
var scrl_ontop = 0;
var scrl_timeouttop;
var scrl_timeoutbottom;
var scrl_allheight = 0;
var scrl_viewheight = 0;
var scrl_preloadcnt = 1;
var tri_Heights = Array();
var tri_ScrollPics = Array();

function tri_Scroll_GetViewHeight()
{
	var h = 0;
	var preload_h;
	for (var i = 1; i < scrl_count + 1; i++)
	{
		tri_Heights[scrl_picid + i] = (gid(scrl_picid + i).offsetHeight + scrl_margin);
		h = (tri_Heights[scrl_picid + i] > h) ? tri_Heights[scrl_picid + i] : h;
		if (i <= scrl_preloadpic)
		{
			preload_h += tri_Heights[scrl_picid + i];
			var p = i;
		}
	}
	scrl_allheight = gid(scrl_belt).offsetHeight;
	scrl_ch = gid(scrl_alldiv).offsetHeight;
	scrl_viewheight = (scrl_ch > (h + scrl_margin)) ? scrl_ch : (h + scrl_margin);
	if (scrl_ch < (h + scrl_margin))
	{
		gid(scrl_alldiv).height = (h + scrl_margin) + "px";
	}
	if (scrl_allheight <= scrl_viewheight)
	{
		gid(scrl_btnbottom).style.display = "none";
		gid(scrl_btnbottom + "_off").style.display = "block";
		gid(scrl_btntop).style.display = "none";
		gid(scrl_btntop + "_off").style.display = "block";
	}
	if (preload_h <= scrl_viewheight)
	{
		var j = 0;
		do 
		{
			p++;
			preload_h += tri_Heights[scrl_picid + p];
			tri_Scroll_PreloadPic();
			j++;
		} 
		while (preload_h <= scrl_viewheight);
		scrl_preloadcnt = j;
		scrl_preloadpic = p;
	}
}


function tri_Scroll_MoveTop()
{
	if (!scrl_timeoutbottom)
	{
		if ( (scrl_move > (0 - tri_Heights[scrl_picid + scrl_picnum]) || (0 - scrl_allheight) > (scrl_ontop + scrl_move)) && (scrl_viewheight < (scrl_allheight + scrl_ontop + scrl_move)) )
		{
			scrl_move -= (scrl_step < (tri_Heights[scrl_picid + scrl_picnum] + scrl_move)) ? scrl_step : tri_Heights[scrl_picid + scrl_picnum] + scrl_move;
			scrl_lastmove = (scrl_move) ? (0 - scrl_move) : scrl_lastmove;
			gid(scrl_belt).style.top = (scrl_ontop + scrl_move) + "px";
			scrl_timeouttop = setTimeout("tri_Scroll_MoveTop();", 5);
		}
		else
		{
			tri_Scroll_PreloadPic();
			clearTimeout(scrl_timeouttop);
			scrl_timeouttop = 0;
			scrl_ontop += scrl_move;
			scrl_picnum = (scrl_picnum < scrl_count) ? scrl_picnum + 1 : scrl_picnum;
			scrl_move = 0;
			gid(scrl_btnbottom).style.display = (scrl_picnum != 1) ? "block" : "none";
			gid(scrl_btnbottom + "_off").style.display = (scrl_picnum != 1) ? "none" : "block";
			gid(scrl_btntop).style.display = (scrl_viewheight < (scrl_allheight + scrl_ontop)) ? "block" : "none";
			gid(scrl_btntop + "_off").style.display = (scrl_viewheight < (scrl_allheight + scrl_ontop)) ? "none" : "block";
		}
	}
}

function tri_Scroll_MoveBottom()
{
	if (!scrl_timeouttop)
	{
		if (scrl_move < scrl_lastmove && scrl_ontop < 0 && scrl_lastmove > 0)
		{
			scrl_move += (scrl_step > (scrl_lastmove - scrl_move)) ? (scrl_lastmove - scrl_move) : scrl_step;
			gid(scrl_belt).style.top = (scrl_ontop + scrl_move) + "px";
			scrl_timeoutbottom = setTimeout("tri_Scroll_MoveBottom();", 5);
		}
		else
		{
			clearTimeout(scrl_timeoutbottom);
			scrl_timeoutbottom = 0;
			scrl_ontop += scrl_move;
			scrl_picnum = (scrl_picnum > 1) ? scrl_picnum - 1 : scrl_picnum;
			scrl_lastmove = (tri_Heights[scrl_picid + (scrl_picnum - 1)]) ? tri_Heights[scrl_picid + (scrl_picnum - 1)] : 0;
			scrl_move = 0;
			gid(scrl_btnbottom).style.display = (scrl_picnum != 1) ? "block" : "none";
			gid(scrl_btnbottom + "_off").style.display = (scrl_picnum != 1) ? "none" : "block";
			gid(scrl_btntop).style.display = (scrl_picnum < scrl_count) ? "block" : "none";
			gid(scrl_btntop + "_off").style.display = (scrl_picnum < scrl_count) ? "none" : "block";
		}
	}
}


function tri_Scroll_PreloadPic()
{
	var cnt = scrl_preloadpic + scrl_preloadcnt + 1;
	var j = scrl_preloadpic + 1;
	for (var i = (scrl_preloadpic + 1); i < cnt; i++)
	{
		if (tri_ScrollPics[i])
		{
			gid(scrl_picid + i).innerHTML = tri_ScrollPics[i];
			gid(scrl_picid + i).style.backgorundColor = "#f0f";
			scrl_preloadpic = j;
			j++;
		}
	}
}
