function zbuduj_ajaxowy_url() {
	var identyfikatory = $("cms_page_id").value.split("-");
	var ten_url = identyfikatory[0] + "-" + identyfikatory[1];
	return "/" + ten_url + "-async-" + $("cms_sector_id").value + ".htm";
}

var ajax_url = zbuduj_ajaxowy_url();

function pobierz_liste_newsow() {
	var args = $("cms_args").value;
	if(args == undefined || args == null) {
		args = '';
	}

	async_invoke({ "module": "newsline", "args": args }, pobierz_liste_newsow_callback, ajax_url);
}

function pobierz_liste_newsow_callback(odpowiedz) {
	var newsy = odpowiedz.responseText.split("\n");
	if(newsy.length > 0) {
		// ...
	} else {
		newsy = new Array();
		newsy.push("(brak newsów)");
	}

	renderuj_newsline(newsy);
}

function renderuj_newsline(newsy) {
	var newsline = $("newsline");
	var pp;

	var html = '<div id="scrollParent" style="overflow: hidden; position: relative; height: 50px">';
	html += '<div id="scrollContainer" style="left: 9000px; position: absolute"><nobr>';

	var parzysty = false;
	
	for(var i = 0, len = newsy.length; i < len; i++) {
		if(i == 0) {
			pp = newsy[i];
			continue;
		}

		if(newsy[i] == undefined) continue;

		var tekst_newsa = newsy[i].split("\t")[1];
		var id_newsa = newsy[i].split("\t")[0];
		var link = "<a href='/" + pp + "-" + id_newsa + ".htm'>" + tekst_newsa + "</a>";

		if(tekst_newsa == undefined || id_newsa == undefined) continue;

		var klasa_przy_parzystym;
		if(parzysty) {
			klasa_przy_parzystym = 'nlmiParzysty';
		} else {
			klasa_przy_parzystym = 'nlmiNieparzysty';
		}

		parzysty = !parzysty;

		html += '<span class="' + klasa_przy_parzystym + '" id="newsItem" style="margin-right: 10px; background-color: red; border: 1px solid black;">' + link + '</span>';
	}

	newsline.innerHTML = html + "</div></nobr></div>";

	var sc = $("scrollContainer");
	ofs = $("scrollParent").clientWidth + 10;
	setInterval(animuj, 80);
}

var ofs = 200;
function animuj() {
	var sc = $("scrollContainer");
	ofs -= 4;
	sc.style.left = ofs + "px";

	if(ofs + sc.clientWidth < 0) {
		ofs = $("scrollParent").clientWidth + 100;
	}
}

function inicjuj_newsline() {
	var news_list = pobierz_liste_newsow();
}

addEvent("load", inicjuj_newsline);

