/* Sliding string (cross-browser solution)							 */
/* Made by Antons Sisojevs. SIA Lattelkom Riga, Latvia				 */
/* mailto: asisojev@yahoo.co.uk										 */
/* You can use this script freely just leave this comments intouched */

var msgWidth, bannerWidth = 794;
var timerID;
var paused = false;
var msgOffset = 10;
var mozilla = 0;
var xPos, yPos;

function checkIt(agent, string)
{
	place = agent.indexOf(string) + 1;
	thestring = string;
	return place;
}

/* Function to start and stop scrolling */
function scroll(type) {
	if (paused) paused = false;
	else
		if (type == 'start') {
			mozilla = checkIt(navigator.userAgent.toLowerCase(), 'mozilla');
			msgWidth = document.getElementById('canvasText1' ).clientWidth;
			document.getElementById('canvasText1' ).style.left = bannerWidth;
			document.getElementById('canvasText2' ).style.left = bannerWidth + msgOffset + 1;
			document.getElementById('bannerArea').style.width = bannerWidth + "px";
			scrollIt(bannerWidth, bannerWidth + msgOffset + 1, 3, 30);
		} else 
			if (timerID != null) clearTimeout(timerID);
}

/* Function to reset the text layer for next scroll */
function stop_scroll() {
  paused = true;
//  alert("Left1: " + xPos + "; Left2: " + yPos +  "; msgWidth: "+document.getElementById('canvasText1' ).offsetWidth + "; bannerWidth: " + bannerWidth);
}


/* Function that does the actually scrolling */
function scrollIt(Left1, Left2, dx, speed) {
  if (paused)
    timerID = setTimeout("scrollIt(" + Left1 + ", " + Left2 + ", " + dx + ", " + speed + ")", speed);
  else { 
	  var el1 = document.getElementById('canvasText1');
	  var el2 = document.getElementById('canvasText2');
	  if (mozilla)	  
		msgWidth = document.getElementById('canvasText1' ).offsetWidth;

	  if ((Left1<0) && (Left1 + msgWidth<bannerWidth) && (Left2>bannerWidth + msgOffset))  {
		  Left2 = bannerWidth + msgOffset;
	  }

	  Left1 -= dx;


	  if (Left2 <= bannerWidth + msgOffset) {
		  Left2 -= dx;
		  el2.style.left = Left2;
	  }
	  
//	  xPos = Left1;
//	  yPos = Left2;

	  if (Left1 > -msgWidth) {
		  el1.style.left = Left1;
		  timerID = setTimeout("scrollIt(" + Left1 + ", " + Left2 + ", " + dx + ", " + speed + ")", speed);
	  } else {
		  Left1 = Left2 - dx;
		  Left2 = bannerWidth + msgOffset + 1;
		  el1.style.left = Left1;
		  el2.style.left = Left2;

		  timerID = setTimeout("scrollIt(" + Left1 + ", " + Left2 + ", " + dx + ", " + speed + ")", speed);
	  }


	}
}
