﻿// News

window.onload = function() { new newsscroller(document.getElementById("latestnews")); };

function newsscroller(o) {
    var self = this;

    this.canvas = o;
    this.news = o.getElementsByTagName("DIV")[0];

    this.canvaswidth = this.canvas.offsetWidth;
    this.canvasleft = this.canvas.offsetLeft;
    this.newswidth = this.news.offsetWidth;

    this.news.style.left = this.canvaswidth + "px";

    this.interval = null;

    this.scroll = function() {
        self.news.style.left = (parseInt(self.news.style.left.replace("px", "")) - 2) + "px";
        // If off the screen start again
        if (parseInt(self.news.style.left.replace("px", "")) + self.newswidth < (self.canvasleft - 10)) {
            self.news.style.left = self.canvaswidth + "px";
        }
    }

    // Add pause on hover
    if (this.news.attachEvent) {
        this.news.attachEvent("onmouseover", function() { clearInterval(self.interval) });
        this.news.attachEvent("onmouseout", function() { self.interval = setInterval(self.scroll, 40) });
    }
    else {
        this.news.addEventListener("mouseover", function() { clearInterval(self.interval) }, false);
        this.news.addEventListener("mouseout", function() { self.interval = setInterval(self.scroll, 40) }, false);
    }

    // Start scrolling
    this.interval = setInterval(this.scroll, 40);
 
}
