///  uwaga w <body musimy dorzucic nastepujace parametry:
///  style='overflow-x: hidden;overflow-y: scroll;' onLoad='start()'
///
///  np. <body bgcolor='#F0F000' style='overflow-x: hidden;overflow-y: scroll;' onLoad='start()'>


var scrollerWidth, scrollerHeight, scrollerLeft, scrollerTop, scrollerPause, scrollerStep;
var scrollerCLeft, scrollerCRight, scrollerCTop, scrollerCBtm;
var scrollTimer, scrollerTWidth, scrollerText;
var length;


var xSite = 780 ; // szerokosc strony
var LeftMargin =  6;  // margines z lewej strony
var RightMargin = 6;   // margines z prawej strony
var xpos = xSite - LeftMargin - RightMargin;
var CenterSite =1; // czy serwis jest centrowany (tak jak portale)
	 scrollerTop    = 2; // margines od gory
	 scrollerHeight = 22; // wysokosc
	 scrollerStep   = 1;  // krok w predkosci


function scrollText() 
{

	if (obj.xpos > (LeftClip - length))
	{
		  obj.xpos -= 1
		  obj.left = obj.xpos
     
		  document.all.text.style.clip = "rect("+-10+" "+(xpos - obj.xpos)+" "+xpos+" "+(scrollerLeft - obj.xpos)+")";
	  
		  setTimeout ("scrollText()", 50)
	}
	else 
	{
		  reset();
	}
}

function reset()
{
  	obj.xpos = xpos
	obj.left = obj.xpos
	setTimeout ("scrollText()", 50)
}


// potrzebne
function start() 
{
	window.onresize = onWinResize;

	if (scrollTimer) clearTimeout(scrollTimer);

	winW = (document.layers)? window.innerWidth-16 : document.body.offsetWidth-20;
	if (winW < xpos) winW = xpos;

	if (CenterSite==1)
	{
	   scrollerLeft = Math.round((winW- xSite) / 2) + LeftMargin;
	}
	else
	{
	   scrollerLeft = LeftMargin;
	}

	scrollerWidth  = xpos;

	

	if (document.all) 
	{
		text.innerHTML=scrollerText;
		scrollerTWidth=text.offsetWidth;
		document.all.text.style.posTop=scrollerTop;
		document.all.text.style.posLeft=scrollerLeft+scrollerWidth;
		scrollerCLeft=0; scrollerCRight=0; scrollerCTop=0; scrollerCBtm=scrollerHeight;
		
		document.all.text.style.clip ="rect("+scrollerCTop+" "+scrollerCRight+" "+scrollerCBtm+" "+scrollerCLeft+")";
		scrollText();
	}
	if (document.layers) 
	{
		document.text.document.write(scrollerText);
		document.text.document.close();
		
		scrollerTWidth = document.text.document.width;
		
		document.text.top = scrollerTop;
		document.text.left = scrollerLeft+scrollerWidth;
		document.text.clip.left=0; 
		document.text.clip.right=0;
		document.text.clip.top=0; 
		document.text.clip.bottom = scrollerHeight;
		
		scrollText();
	}

	
}


function scrollText() 
{
	if (document.all) 
	{
		if (document.all.text.style.posLeft >= scrollerLeft - scrollerTWidth) 
		{
				document.all.text.style.posLeft -= scrollerStep;
				scrollerCRight += scrollerStep;
				if (scrollerCRight > scrollerWidth) scrollerCLeft += scrollerStep;
				document.all.text.style.clip ="rect("+scrollerCTop+" "+scrollerCRight+" "+scrollerCBtm+" "+scrollerCLeft+")";
				scrollTimer=setTimeout("scrollText()",scrollerPause);
		}
		else scrollReset();
	}

	if (document.layers) 
	{
		if (document.text.left >= scrollerLeft - scrollerTWidth) 
		{
				document.text.left -= scrollerStep;
				document.text.clip.right += scrollerStep;
				if (document.text.clip.right > scrollerWidth) document.text.clip.left += scrollerStep;
				scrollTimer=setTimeout("scrollText()",scrollerPause);
		}
		else scrollReset();
	}
}

function scrollReset() 
{
	if (document.all) 
	{
			document.all.text.style.posLeft = scrollerLeft + scrollerWidth;
			scrollerCLeft=0; scrollerCRight=0;
			document.all.text.style.clip ="rect("+scrollerCTop+" "+scrollerCRight+" "+scrollerCBtm+" "+scrollerCLeft+")";
			scrollText();
	}

	if (document.layers) 
	{
			document.text.document.write(scrollerText);
			document.text.document.close();
			document.text.left=scrollerLeft+scrollerWidth;
			document.text.clip.left=0; document.text.clip.right=0;
			scrollText();
	}
}

function scrollSpeed(inc) 
{
	if (inc == 0) scrollerStep = 0;	else scrollerStep += inc;
	if (scrollerStep >= 20) scrollerStep = 20;
	if (scrollerStep<0) scrollerStep = 0;
}

function resizeFix() 
{
	if (!document.layers) return;

	
	if (winW != window.innerWidth || heightCheck != window.innerHeight)
	{

		document.location.href = document.location.href;
	}
	
}

function onWinResize() 
{
	resizeFix();
	start();
}
