
var brwOpera = 0;
var gekso = 0;

var Scrollers   = new Array();
var ScrollersNr = 0;

function hScrollersInit()
{
    if (navigator.product && navigator.product == "Gecko")
    {
        var agt = navigator.userAgent.toLowerCase();
        var rvStart = agt.indexOf('rv:');
        var rvEnd = agt.indexOf(')', rvStart);
        var check15 = agt.substring(rvStart+3, rvEnd);
        if(parseFloat(check15)<1.8) gekso = 1;
    }

    brwOpera = navigator.userAgent.toLowerCase().indexOf('opera');
}


function hScroller( sWidth, sHeight, sBk, sSpeed, sPause, sText, sName )
{
        this.width  = sWidth;
        this.height = sHeight;
        this.background = sBk;
        this.pause = sPause;
        this.name = sName;
        this.speed = sSpeed;
        this.srestart = sSpeed;
        this.rSpeed = sSpeed;
        this.text = new Array();
        this.text[0] = '<nobr>' + sText + '</nobr>';
        this.itext = 0;
        this.nextstep = 0;
		this.brwType = 0; // 0 - ns4 1 -ns6  2 - ie
		
        this.afterLoad =  hScroller_afterLoad;
        this.restart =    hScroller_restart;
		this.nextText =   hScroller_nextText;
        this.scrollStep = hScroller_scrollStep;
        this.stamp =      hScroller_stamp;
       
        Scrollers[ScrollersNr] = this; ScrollersNr++;
        
        return true;
}


function hScroller_afterLoad()
{
        if (document.getElementById)
        {
            this.slayer = document.getElementById('div_' + this.name);
            if (brwOpera != -1)
                    this.operdiv = document.getElementById('operaslider' + this.name);
			this.brwType = 1;
        }
		else 
		if (document.layers)
	 	{
			var ns4div = document.getElementById('div_' + this.name);
	 		this.slayer = ns4div.document.getElemenyById('div1_' + this.name);
		    this.brwType = 0;
	 	}    
		else
		if (document.all)
		{
            this.slayer = document.getElementById('div_' + this.name);
			this.brwType = 2;
		}
		this.restart(this.text[0]);
}


function hScroller_restart(txt)
{
		if (this.brwType == 1)	
		{
			this.slayer.style.left = this.width + "px";
        	this.slayer.innerHTML = txt;
        	this.sizeup = this.slayer.offsetWidth;
        	if (brwOpera != -1 && this.sizeup == this.width)
        	{
            	this.operdiv.innerHTML = txt;
            	this.sizeup = this.operdiv.offsetWidth;
        	}
		}
		else
		if (this.brwType == 0)
		{
     		this.slayer.left = this.width;
     		this.slayer.document.write(txt);
		    this.slayer.document.close();
		    this.sizeup = this.slayer.document.width;
		}
		else
		if (this.brwType == 2)
		{
			this.slayer.style.pixelLeft = this.width + "px";
        	this.slayer.innerHTML = txt;
        	this.sizeup = this.slayer.offsetWidth;
		}
}


function hScroller_nextText()
{
	if (this.itext == this.text.length-1)
    	this.itext = 0;
   	else
       	this.itext++;
   	this.restart(this.text[this.itext]);
}


function hScroller_scrollStep()
{
		if (this.brwType == 1)
		{
			if (parseInt(this.slayer.style.left) > 0 && parseInt(this.slayer.style.left) <= this.speed)
            	this.slayer.style.left = 0;
        	else
        	if (parseInt(this.slayer.style.left) >= -this.sizeup)
            	this.slayer.style.left = parseInt(this.slayer.style.left) - this.speed + "px";
        	else
				this.nextText();
		}
		else
		if (this.brwType == 0)
		{
			if (this.slayer.left > 0 && this.slayer.left <= this.speed)
				this.slayer.left = 0;
			else 
			if (this.slayer.left >= -this.sizeup)
				this.slayer.left -= this.speed;
			else
				this.nextText();	
		}
		if (this.brwType == 2)
		{
			if (parseInt(this.slayer.style.pixelLeft) > 0 && parseInt(this.slayer.style.pixelLeft) <= this.speed)
            	this.slayer.style.pixelLeft = 0;
        	else
        	if (parseInt(this.slayer.style.pixelLeft) >= -this.sizeup)
            	this.slayer.style.pixelLeft = parseInt(this.slayer.style.pixelLeft) - this.speed + "px";
        	else
				this.nextText();
		}
}


function hScroller_stamp()
{
        document.write('<tr>');
        document.write('<td width="' + this.width + 'px">');

        if (document.layers)
        {
            document.write('<ilayer id="div_' + this.name + '"' +
                           ' width="' + this.width + '"' +
                           ' height="'+ this.height + '"' +
                           ' bgcolor=' + this.background + '>' +
                           '<layer id="div1_' + this.name + '"' +
                           ' width="' + this.width + '"' +
                           ' height="'+ this.height + '"' +
/*                           ' onmouseover="sspeed=0;" onmouseout="sspeed=restart">' + */
                           '</layer></ilayer>'
                          );
        }
        if (document.getElementById||document.all)
        {
            document.write('<div style="position:relative;overflow:hidden;' +
                           'width:' + this.width + 'px;height:' + this.height + 'px;' +
                           'clip:rect(0 ' + this.width + 'px ' + this.height + 'px 0);' +
                           'background-color:' + this.background + ';"' +
                           ' onmouseover="' + this.name + '.speed=0;" onmouseout="' + this.name + '.speed=' + this.name + '.srestart">'
                          );
            if (gekso == 0 && brwOpera == -1)
                document.write('<div id="div_' + this.name + '"' +
                               ' style="position:absolute;height:' + this.height + 'px;">' +
                               '</div></div>');
            else
                document.write('<div id="div_' + this.name + '"' +
                               ' style="position:relative;height:' + this.height + 'px;">' +
                               '</div><div id="operaslider_' + this.name + '"' +
                               ' style="position:absolute;visibility:hidden;"></div></div>');
        }

        document.write('</td');
        document.write('</tr>');
}


function scrollersStep()
{
    var tm = new Date;

    for (var i = 0; i < ScrollersNr; i++) 
        if (Scrollers[i].nextstep < tm.getTime())
        {
            Scrollers[i].nextstep = tm.getTime() + Scrollers[i].pause;
            Scrollers[i].scrollStep();
        }
    
    delete tm;
    
    setTimeout("scrollersStep()", 5);
}

function scrollersRun()
{
	for (var i = 0; i < ScrollersNr; i++) 
        Scrollers[i].afterLoad();
    scrollersStep();
}


