﻿var ad_ctx = null;
    var count = screen.width;
    var settings = null;
    var px_count = 3;
    var tick_count = 75;
    function initSettings() {
        if ($('adScroller').getAttribute("rel") != null) {
            settings = $('adScroller').getAttribute("rel").replace("{", "").replace("}", "");
        }
    }
    function AreSettingsSet() {
        return settings!=null;
    }
    function getSettings(i) {
        try {
            if (settings != null) {
                if ((settings.split(",") != null)&&(settings.split(",").length > i)) {
                    return settings.split(",")[i];
                }
            }
            return 0;
        } catch(ex) {
            return 0;
        }
    }
    function runConfig() {
        initSettings();
        
        if (AreSettingsSet()) {
            px_count = getSettings(0);
            tick_count = getSettings(1);
        }
        
        $('adScroller').setStyle({"width": $('adScroller').getStyle("width")});
    }
    function adScroll(count) {
        if (count < ($('adScroller').getStyle("width").replace('px','') - 2*$('adScroller').getStyle("width").replace('px',''))) {
            count = screen.width;
        }
        
        ad_ctx = setTimeout(function() {
            count = count - px_count;

            $('adScroller').style.marginLeft = count+'px';

            adScroll(count);
        }, tick_count);
    }
    
    function RunAdScroll() {
        AddOnload(function() {
            runConfig();
            adScroll(count);
        });
    }