var MaxWidth = 300;
var MaxHeight = 284;
var timer_id = null;
var timer_id_h = null;
var timer_switch = null;
var initializedImage = 5;
var imgMovecnt=0;
var imgarray=null;


function LoadArrows() 
{
	var TheSettings = document.getElementById('InnerDIV');  
	if(!TheSettings) 
		return false;
	var Left = parseInt(TheSettings.style.left);
	if(isNaN(Left)) Left  = 0;
	var Width = document.all ? TheSettings.offsetWidth : document.getElementById('TheTable').offsetWidth;
	if(-Left + MaxWidth  >= Width ) 
	{
		document.images['ScrollBtnRight'].src = 'layout/arrow_right_disabled.gif';
		document.images['ScrollBtnRight'].style.cursor = 'arrow';
	} 
	else 
	{
		document.images['ScrollBtnRight'].src = 'layout/arrow_right.gif';
		document.images['ScrollBtnRight'].style.cursor = 'pointer';
	}
	if(Left >= 0) 
	{
		document.images['ScrollBtnLeft'].src = 'layout/arrow_left_disabled.gif';
		document.images['ScrollBtnLeft'].style.cursor = 'arrow';		
	} 
	else 
	{
		document.images['ScrollBtnLeft'].src = 'layout/arrow_left.gif';
		document.images['ScrollBtnLeft'].style.cursor = 'pointer';
	}
}

function ScrollTo(Where) 
{
	var Timeout  = 30;
	var ScrollAmount = 1;
	var TheSettings = document.getElementById('InnerDIV');  
	var Left = parseInt(TheSettings.style.left);
	var Width = document.all ? TheSettings.offsetWidth : document.getElementById('TheTable').offsetWidth;  
	if(isNaN(Left)) Left  = 0;
	if(isNaN(Width )) Width = 0;
	//window.status = 'Left: ' + Left + '\nWidth: ' + Width;
	//window.status = "SlovakiaReal";
	var IsNextTimer = true;
	if(Where < 0) 
	{
		Left-=ScrollAmount ;
		if(-Left + MaxWidth  > Width ) 
		{
			Left = -(Width - MaxWidth );
			IsNextTimer = false;
		}
	} 
	else 
	{
		Left+=ScrollAmount ;
		if(Left > 0) 
		{
			Left = 0;
			IsNextTimer = false;			
		}
	}
	TheSettings.style.left = Left + 'px';
	LoadArrows();
	
	if(IsNextTimer) 
	{
		timer_id = setTimeout("ScrollTo(" + Where + ")", Timeout  );
	}
}

function ScrollHTo(Where) 
{	
	var Timeout  = 60;
	var ScrollAmount = 1;
	var TheSettings = document.getElementById('InnerDIVHor');  
	var Top = parseInt(TheSettings.style.top);
	var Height = document.all ? TheSettings.offsetHeight : document.getElementById('TheTableHor').offsetHeight;  
	if(isNaN(Top)) Top  = 0;
	if(isNaN(Height )) Height = 0;
	//window.status = "SlovakiaReal";
	var IsNextTimer = true;
	if(Where < 0) 
	{
		Top-=ScrollAmount;
		
		if(-Top + MaxHeight  > Height ) 
		{
			Top = -(Height - MaxHeight );
			Where = 1;
		}
	} 
	else 
	{
		Top+=ScrollAmount ;
		if(Top > 0) 
		{
			Top = 0;
			Where = -1;
		}
	}
	
	TheSettings.style.top = Top + 'px';
	
	
	/*if(imgMovecnt==64)
	{
		initImages(initializedImage);
		initializedImage++;
		imgMovecnt=0;
	}*/
	 
	imgMovecnt++;
	 
	if(IsNextTimer) 
	{
		timer_id_h = setTimeout("ScrollHTo(" + Where + ")", Timeout);
	}
}

function loadScrollImages()
{
	ScrollHTo(-1);
}

function initImages(pos)
{
	if(imgarray==null || imgarray.length==0)
	{
		return;
	}
	
	if(pos<imgarray.length)
	{
		var imgScrl = document.getElementById('scrollImage'+pos);  
		if(imgScrl==null)
		{
			return;
		}
		else
		{
			//alert("img/tb_"+imgarray[pos]);
			imgScrl.src="./img/tb_"+imgarray[pos];
		}
	}
}

function setArray(arr)
{
	imgarray = arr;
}

function stopScroll() 
{ 
	if (timer_id) clearTimeout(timer_id); 
}

function stopHScroll() 
{ 
	if (timer_id_h) clearTimeout(timer_id_h); 
}