
var scrollSpeed = 1;
var scrollDelay = 20;

var myregexp = /^http:\/\/(.*?)\/.*$/;
var tickdat = myregexp.exec(location.href);
var tickurl = 'www.bleskovky.sk'
if (tickdat != null) {
	tickurl = tickdat[1];
}

if (window.navigator.appName != 'Microsoft Internet Explorer') {
	scrollSpeed = 5;
	scrollDelay = 200;
}

var run = 1;
var refreshDelay = '300000';
var tickdata;

var ticker = document.getElementById('tickContainer');

function initScroll(container, object) {
	var contObj = document.getElementById(container);
	if (contObj){
		var obj = document.getElementById(object);
		obj.innerHTML = tickdata;
		contObj.style.visibility = "visible";
		contObj.scrollSpeed = scrollSpeed;
		widthContainer = contObj.offsetWidth;
		obj.style.position = "absolute";
		obj.style.top = "0px";
		obj.style.left = parseInt(widthContainer - 300) + "px";
		widthObject = obj.offsetWidth;

		setInterval("objScroll('" + container + "','" + object + "'," + widthContainer + ")", scrollDelay);

		contObj.onmouseover = function() { contObj.scrollSpeed = 0 };
		contObj.onmouseout = function() { contObj.scrollSpeed = scrollSpeed };
	}
}

function objScroll(container, object, widthContainer) {
	var contObj = document.getElementById(container);
	var obj = document.getElementById(object);

	widthObject = obj.offsetWidth;

	if (parseInt(obj.style.left) > (widthObject * (-1))) {
		obj.style.left = (parseInt(obj.style.left) - contObj.scrollSpeed) + "px";
	}
	else {
		obj.innerHTML = tickdata;
		obj.style.left = parseInt(widthContainer) + "px";
	}
}

function GetTicker() {
	var uri = 'http://'+tickurl+'/ticker/ticker.fcgi';
	AjaxRequest.get({
		'url': uri,
		'onSuccess' : function(req) { UpdateTicker(req.responseText) }
	});
	setTimeout("GetTicker()", refreshDelay);
}

function UpdateTicker(arg) {
	tickdata = arg;
	if (run == 1){
		initScroll("tickContainer", "tickContent");
		run++;
	}
}

GetTicker();

var iMax = 35;
var song;
var contJemne;
var counterJemne = 0;
var timerJemne = 0;	

function GetJemne() {
	var uri = '/jemne/jemne.txt';
	AjaxRequest.get({
		'url': uri,
		'onSuccess' : function(req) { printJemne(req.responseText) }
	});
	setTimeout("GetJemne()", 10000);
}
	
function tickerJemne(){
    var start = 0;
    if(counterJemne > iMax){
	start = counterJemne - iMax
    }
    if(timerJemne)
	window.clearTimeout(timerJemne);
    if(song && counterJemne < song.length){
	counterJemne+=1;
	contJemne.innerHTML = song.substring(start,counterJemne);
	timerJemne = window.setTimeout("tickerJemne()",110);
    }
    else if(song){
	timerJemne = window.setTimeout("tickerJemne()",1000);
	counterJemne = 0;
//	song = '::' + song + ' :: ' + song;
    }
    else{
	timerJemne = window.setTimeout("tickerJemne()",110);
    }
    

    
}
function printJemne(arg){
    contJemne = document.getElementById('song');
//    song = arg + ' :: ' + arg + ' :: ' + arg + ' :: ' + arg + ' :: '  ;
    if(song != arg){
	song = arg;
	counterJemne = 0;
	if(timerJemne){
	    window.clearTimeout(timerJemne);
	    tickerJemne();
	}
    }
}

GetJemne();
tickerJemne();