﻿/*
var topTextBanners = [['<?=$arr_scroll[0][1]?>','<?=$arr_scroll[1][1]?>','']
,['sub_detail.html','2007 Có sản phẩm mới!!','ico_ok.gif']
,['sub_detail.html','Sản phẩm mới','ico_good.gif']
,['sub_detail.html','Khuyến mãi','ico_battay.gif']
,['sub_detail.html','Công ty Tân Mai hân hạnh phục vụ quý khách','ico_ok.gif']
,]; */

var iScrollerHeight = 40;		
var iTotalArea = 0;
var bWait = true;
var bMouseOver = false;
var iScrollSpeed = 1;			
var iWaitTime = 4000;			 
var iTemp = 0;
var iMovingAmount = 40;
var arrScrollContent = new Array();
var i;

function startscroll() 			
{
	for (i = 0; i < arrScrollContent.length; i++)
	{
		insert_area(iTotalArea, iTotalArea++);  
	}
	
	window.setTimeout("scrolling()", iWaitTime);
}

function scrolling()				
{
	if (!bMouseOver && bWait)
	{
		for (i = 0; i < iTotalArea; i++)
		{
			tmp = document.getElementById('scroll_area' + i).style;
			tmp.top = parseInt(tmp.top) - iScrollSpeed;

			if (parseInt(tmp.top) <= -iScrollerHeight)
			{
				tmp.top = iScrollerHeight * (iTotalArea - 1);
			}

			if (iTemp++ == ((iMovingAmount - 1) * arrScrollContent.length + 1))
			{
				bWait = false;
				window.setTimeout("bWait=true; iTemp=0;", iWaitTime);
			}
		}
	}

	window.setTimeout("scrolling()", 0);
}

function next_scrolling()				 
{
	for (i = 0; i < iTotalArea; i++)
	{
		tmp = document.getElementById('scroll_area' + i).style;
		tmp.top = parseInt(tmp.top) - iScrollerHeight;

		if (parseInt(tmp.top) <= -iScrollerHeight)
		{
			tmp.top = iScrollerHeight * (iTotalArea - 1);
		}
	}
}

function insert_area(idx, n)
{
	var strContent
	strContent = '<div style="left: 0px; width: 250px; height: 40px; position: absolute; top: ' + (iScrollerHeight * n) + 'px" id="scroll_area' + n + '">';
	strContent += arrScrollContent[idx];
	strContent += '</div>';
	document.write(strContent);
}

function checkMouseOver()
{
	var count
	
	count = 0
	for (i = 0; i < iTotalArea; i++)
	{
		tmp = document.getElementById('scroll_area' + i).style;
		
		if (parseInt(tmp.top) % iScrollerHeight != 0)
			count++;
	}
	
	if(count == 0)
		bMouseOver = true;
}

for(i=0; i<5; i++)
{
	arrScrollContent[i] = "<table cellSpacing='0' cellPadding='0' width='100%' border='0' height='40'><tr><td width='22' align='left'><img src='upload_img/small_img/" + topTextBanners[i][2] + "' width='20' height='20'></td><td width='160' align='left'><b><font color='#FFFFFF'><a href='" + topTextBanners[i][0] + "'><font color=#FFFFFF>" + topTextBanners[i][1] + "</font></b></a></font></td></tr></table>";
}

