﻿var Chart = {
    swfFile: 'amline/amline.swf'
    , dataFile: 'amline/amline_data.txt'
    , settingsFile: 'amline/amline_settings.xml'
    , paintPanel: null
    , libraryPath: 'amline'
    , _rootDir: ''

    , init: function(rootDir) {
        this._rootDir = rootDir;
    }
    , Draw: function(panel, file, moreSettings) {
        var so = new SWFObject(this._rootDir + 'amline/amline.swf', 'amline', '400', '250', '8', '#FFFFFF');
        so.addVariable('path', this._rootDir + 'amline/');
        so.addVariable('settings_file', this._rootDir + 'amline/amline_settings.xml');
        so.addVariable('data_file', this._rootDir + escape(file));
        so.addVariable('additional_chart_settings', '<settings>' + moreSettings + '</settings>');
        so.addVariable('loading_settings', 'LOADING SETTINGS');
        so.addVariable('loading_data', 'LOADING DATA');
        so.addVariable('preloader_color', '#999999');
        so.write(panel);
    }

    , DrawRT: function(panel, file, moreSettings, reloadPeriod) {
        moreSettings += '<reload_data_interval>'
                        + reloadPeriod
                        + '</reload_data_interval>';
        Chart.Draw(panel, file, moreSettings);
    }

    , DrawLine: function(file, panel, title, color, bullet) {
        var settingStr = Chart.GetGraphsSettingStr(Chart.GetGraphSettingStr(title, color, bullet, 'left'));
        Chart.Draw(panel, file, settingStr);
    }
    
    , DrawLineRT: function (file, panel, title, color, bullet, reloadPeriod) {
        var settingStr = Chart.GetGraphsSettingStr(Chart.GetGraphSettingStr(title, color, bullet, 'left'));
        Chart.DrawRT(panel, file, settingStr, reloadPeriod);
    }
    
    , GetGraphsSettingStr: function(graphsStr) {
        var output = '<graphs>';
        output += graphsStr;
        output += '</graphs>';
        return output;
    }
    
    , GetGraphSettingStr: function(title, color, bullet, axis) {
        var output = '<graph>';
        output += '<title>' + title + '</title>';
        output += '<color>' + color + '</color>';
        output += '<bullet>' + bullet + '</bullet>';
        output += '<axis>' + axis + '</axis>';
        //output += '<balloon_text>' + '<![CDATA[{title}:{value}]]>' + '</balloon_text>';
        output += '</graph>';
        return output;
    }
};