
var RB_bannerWidth = 162;
var RB_speedPeriod = 10;
var RB_speedDistance = 4;

var position = 0;

var RB_direction = 0;

var RB_autoScroll = true;
var RB_autoScrollDelay = 7000;
var RB_autoDirection = -1;

function RB_init() {
	//alert('RB1');

	containerWidth = document.getElementById('RB_Container').style.width;

	if(containerWidth / RB_bannerWidth > RB_bannersUrls.length - 1) {
		return; //nedostatek banneru na rolovani;
	}

	//alert('RB2');

	container = document.getElementById('RB_Container');

	for(i=0; i < RB_bannersUrls.length; i++) {
		link = document.createElement('a');
		link.href=RB_bannersUrls[i];

		ban = document.createElement('div');
		ban.setAttribute('class', 'banner');
		ban.className = 'banner';
		ban.style.position = 'absolute';
		ban.id = 'banner_' + i;

		ban.style.left = (i * RB_bannerWidth) + 'px';
		ban.style.top = '0px';

		label = document.createElement('a');
		label.href=RB_bannersUrls[i];
		label.innerHTML = RB_bannersLabels[i];
		label.setAttribute('class', 'bannerLabel');
		label.className = 'bannerLabel';

		if(imgSrc = RB_bannersImgUrls[i]) {
			img = document.createElement('img');
			img.setAttribute('class', 'HPBannerImg');
			img.className = 'HPBannerImg';
			img.src = imgSrc;
			link.appendChild(img);
		}

		ban.appendChild(label);
		ban.appendChild(link);


		container.appendChild(ban);
	}
	cl = document.createElement('div');
	cl.setAttribute('class', 'cl');
	cl.className = 'cl';

	container.appendChild(cl);

	RB_autoScroll = true;
	//ert('tak to zacnem');
	window.setTimeout('RB_rollByStep(' + RB_autoDirection + ', \'auto\')', RB_autoScrollDelay);
}

function RB_rollByStep(direction, runBy) {

	isEnd = false; //indikuje, ze skoncil jeden automaticky popojezd.

	if((!RB_autoScroll) && (runBy == 'auto')) {
		//alert('auto neni, ale ja mam delat auto, tak to odkladam;');
		window.setTimeout('RB_rollByStep(' + RB_autoDirection + ', \'auto\')', RB_autoScrollDelay);
		return;
	}


	if(!RB_autoScroll) {
		if(RB_direction != direction)
			return;
	} else { //RB_auto scroll je, invokovano to muze byt jakkoliv
		if(runBy == 'auto') { //invokovano auto
			//no proc by ne
		} else { //invokovano rucne, ale pritom je zapnuto auto scroll. pitomost - konec
			return;
		}
	}

	container = document.getElementById('RB_Container');
	firstBan = false;
	for(i = 0; i < container.childNodes.length; i++) {
		if(!container.childNodes[i].tagName) continue;
		if(!container.childNodes[i].id) continue;
		if(!firstBan)
			firstBan = container.childNodes[i];
		lastBan = container.childNodes[i];
	}

	if(direction == 1) { //doprava
		for(i = 0; i < container.childNodes.length; i++) {
			if(!container.childNodes[i].tagName) continue;
			if((container.childNodes[i].className != 'banner') && (container.childNodes[i].getAttribute('class') != 'banner')) continue;
			//alert(container.childNodes[i].style.left);
			container.childNodes[i].style.left = (parseInt(container.childNodes[i].style.left) + RB_speedDistance) + 'px';
		}

		if(parseInt(firstBan.style.left) > 0) {
			lastBan = container.removeChild(lastBan);
			container.insertBefore(lastBan, firstBan);
			lastBan.style.left = (parseInt(firstBan.style.left) - RB_bannerWidth) + 'px';
			if(RB_autoScroll)
				isEnd = true; //doslo na konec automatickeho popojezdu;
		}
	}

	if(direction == -1) { //doleva
		for(i = 0; i < container.childNodes.length; i++) {
			if(!container.childNodes[i].tagName) continue;
			if((container.childNodes[i].className != 'banner') && (container.childNodes[i].getAttribute('class') != 'banner')) continue;
			container.childNodes[i].style.left = (parseInt(container.childNodes[i].style.left) - RB_speedDistance) + 'px';
		}

		if(parseInt(firstBan.style.left) < (RB_bannerWidth * -1)) {
			firstBan = container.removeChild(firstBan);
			container.appendChild(firstBan);
			firstBan.style.left = (parseInt(lastBan.style.left) + RB_bannerWidth) + 'px';
			if(RB_autoScroll)
				isEnd = true; //doslo na konec automatickeho popojezdu;
		}
	}

	if(isEnd)
		period = RB_autoScrollDelay;
	else
		period = RB_speedPeriod;

	window.setTimeout('RB_rollByStep(' + direction + ', \'' + runBy + '\')', period);
}

RB_init();



















