﻿if(typeof MakinHey == "undefined" || !MakinHey) { var MakinHey = {}; }

MakinHey.Marquee = function(viewport, view, content, width, height, delay, startLeft) {
    var vp = document.getElementById(viewport);
    var v = document.getElementById(view);
    if(vp && v) {
        if(!height) {
            height = vp.offsetHeight;
        }
        if(!width) {
            width = vp.offsetWidth;
        }
        if(content) {
            v.innerHTML = content;
        }

        vp.style.height = height + "px";
        vp.style.margin = "0px";
        vp.style.overflow = "hidden";
        vp.style.padding = "0px";
        vp.style.position = "relative";
        vp.style.width = width + "px";

        v.style.left = "0px";
        v.style.margin = "0px";
        v.style.overflow = "visible";
        v.style.padding = "0px";
        v.style.position = "absolute";
        v.style.top = "0px";
        v.style.whiteSpace = "nowrap";

        var vpW = vp.offsetWidth;
        var vW = v.offsetWidth;
        var pause = false;
        v.onmouseover = function() {
            pause = true;
        };
        v.onmouseout = function() {
            pause = false;
        };
    
        var vLeft = startLeft ? 0 : vpW;
        v.style.left = vLeft;
        var restart = 0 - vW;
        var scroll = function() {
            if(!pause) {
                vLeft -= 1;
                if(restart > vLeft) {
                    vLeft = vpW;
                }
                v.style.left = vLeft + "px";
            }
            if(v.onmouseover) {
                setTimeout(scroll, 10);
            }
        };
        
        if(delay > 0) {
            setTimeout(scroll, delay);
        }
        else {
            scroll();
        }
    }
}