﻿szybkosc = 100
kierunek = 'left'
plik = '/i/news/news.xml'
okres = 1000000

d = document; d.g = d.getElementById
Ob = []
function noCache(uri) {
    return uri.concat(/\?/.test(uri) ? "&" : "?", "noCache=", (new Date).getTime(), ".", Math.random() * 1234567)
}
function laduj() {
    with (d.g('NEWS').style) {
        position = 'fixed'
        bottom = '0px'
        top = 'auto'
    }
    pozycjonuj()
    if (window.addEventListener) {
        window.addEventListener("resize", pozycjonuj, 0)
        window.addEventListener("scroll", pozycjonuj, 0)
    } else {
        window.attachEvent("onresize", pozycjonuj)
        window.attachEvent("onscroll", pozycjonuj)
    }
    ID = 'news'
    if (!Ob[ID]) {
        OB = d.g(ID + '_ramka')
        for (i = 1; i < 3; i++) {
            var div = null
            div = document.createElement("div")
            div.id = ID + '_' + i
            div.className = 'news'
            OB.appendChild(div)
        }
        ID1 = 'news_1'; ID2 = 'news_2'
        Ob[ID] = { id: ID1, id2: ID2 }
    }
    TEXT = ''
    request_mod = 0
    make_request(plik)
    XMLReq = setInterval("make_request(plik)", okres)
}
function pozycjonuj(dn) {
    dn = {}
    dn.W = d.g('prob').offsetWidth
    GL = d.g('NEWS')
    d.g('NEWS2').style.width = dn.W - 40 + 'px'
    d.g('news_ramka').style.width = dn.W - 140 + 'px'
    GL.style.width = dn.W + 'px'
    if (d.all) {
        if (!window.XMLHttpRequest && (dn.H = d.documentElement.clientHeight)) {
            GL.style.position = 'absolute'
            GL.style.top = dn.H + d.documentElement.scrollTop - GL.offsetHeight - 2 + 'px'
            GL.style.left = d.documentElement.scrollLeft + 'px'
        }
    }
}
function make_request(xml_url) {
    var xml_request = false;
    if (typeof XMLHttpRequest == "undefined") XMLHttpRequest = function() {
        try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch (e) { }
        try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch (e) { }
        try { return new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { }
        try { return new ActiveXObject("Microsoft.XMLHTTP") } catch (e) { }
        throw new Error("This browser does not support XMLHttpRequest.")
    }
    xml_request = new XMLHttpRequest();
    if (xml_request.overrideMimeType) {
        xml_request.overrideMimeType('text/xml');
    }
    if (!xml_request) {
        return false;
    }
    xml_request.open('GET', xml_url, true);
    xml_request.setRequestHeader('Content-Type', 'application/xml');
    request_mod = (request_mod) ? request_mod : new Date(0)
    xml_request.setRequestHeader("If-Modified-Since", request_mod);
    xml_request.onreadystatechange = function() { dane(xml_request); }
    xml_request.send(null)
}
function dane(xml_request) {
    if (xml_request.readyState == 4) {
        if (xml_request.status == 304) {
            return
        }
        if (xml_request.status == 200) {
            request_mod = xml_request.getResponseHeader("Last-Modified")
        }
        if (xml_request.responseXML.xml == '') {
            xml_request.responseXML.loadXML(xml_request.responseText);
        }
        xml_content = xml_request.responseXML;
        info_xml = xml_content.getElementsByTagName('info');
        text = ''
        important = 0
        for (var i = 0; i < info_xml.length; i++) {
            if (info_xml[i].getAttribute("important") == 1) {
                important = 1
            }
            text += '      |      ' + info_xml[i].firstChild.data
        }
        if (TEXT == text) {
            return
        }
        TEXT = text
        while (text.length < 400) {
            text += text
        }
        ob = d.g('news_1')
        ob2 = d.g('news_2')
        ob.innerHTML = text
        ob2.innerHTML = text
        ob.style.left = '0px'
        ob2.style.left = (-1 * ob2.offsetWidth - 5) + 'px'
        if (important) {
            d.g('NEWS').style.backgroundImage = 'url(/Content/i/news_tlo2.gif)'
            d.g('NEWS2').style.backgroundImage = 'url(/Content/i/logo_news2.gif)'
        }
        else {
            d.g('NEWS').style.backgroundImage = 'url(/Content/i/news_tlo.gif)'
            d.g('NEWS2').style.backgroundImage = 'url(/Content/i/logo_news.gif)'
        }
        ustaw(kierunek, 'news')
    }
}
function przewin(ob) {
    ob.l += ob.k * 4
    ob.l2 += ob.k * 4
    if (ob.l * ob.k > ob.w - ob.pw && ob.k < 0) {
        ob.l2 = ob.w + ob.l
    }
    if (ob.l > 5 && ob.l < 20) {
        ob.l2 = -(ob.w - ob.l)
    }
    if (-ob.l > ob.w || ob.l > ob.pw) {
        var tempId = ob.id
        ob.id = ob.id2
        ob.l = ob.l2
        ob.id2 = tempId
        ob.l2 = -ob.k * ob.w + ob.l
    }
    d.g(ob.id).style.left = ob.l + 'px'
    d.g(ob.id2).style.left = ob.l2 + 'px'
}
function ustaw(kier, ID, ob) {
    ob = d.g(Ob[ID].id)
    ob2 = d.g(Ob[ID].id2)
    if (Ob[ID].xset) {
        clearInterval(Ob[ID].xset)
    }
    if (kier == 'stop') {
        return
    }
    Ob[ID].k = kier == 'right' ? 1 : -1
    Ob[ID].l = ob.offsetLeft
    Ob[ID].l2 = ob2.offsetLeft
    Ob[ID].w = ob.offsetWidth
    Ob[ID].pw = ob.offsetParent.offsetWidth
    Ob[ID].xset = setInterval("przewin(Ob['" + ID + "'])", szybkosc)
}


if (window.addEventListener) {
    window.addEventListener("load", laduj, 0)
} else {
    window.attachEvent("onload", laduj)
}
