
LI.Tooltip = {
    /**
     * Add new tool tips content. Content in array will overwrite default qtip
     * settings for our tool tips.
     */
    tips: {
        'click_to_expand': { content: 'Click to expand'},
        'click_to_close': { content: 'Click to close'},

        'index_freetest_url': {
            content: 'Website URL to analyze and load test'
        },
        'index_freetest_run_test': {
            content: 'Automatically creates a ramp-up load test (0 to 50 '
                     + 'concurrent users during 15min) from specified website URL'
        },

        'config_list_table_title': {
            content: 'Name of configuration'
        },
        'config_list_table_url': {
            content: 'Target site URL'
        },
        'config_list_table_credits': {
            content: 'Number of credits needed to run this configuration'
        },
        'config_list_table_created': {
            content: 'When this configuration was created'
        },
        'config_list_table_updated': {
            content: 'When this configuration was last changed'
        },
     
        'user_scenario_list_table_title': {
            content: 'Name of user scenario'
        },
        'user_scenario_list_table_created': {
            content: 'When this user scenario was created'
        },
        'user_scenario_list_table_updated': {
            content: 'When this user scenario was last changed'
        },
        'user_scenario_data_stores_info_link': {
            content: 'Data stores enables you to upload existing parameterization data.'
        },
        
        'test_schedule_list_table_name': {
            content: 'Name of scheduled test configuration'
        },
        'test_schedule_list_table_target': {
            content: 'Target URL for scheduled test'
        },
        'test_schedule_list_table_next': {
            content: 'When is the next test scheduled to run'
        },
        'test_schedule_list_table_last': {
            content: 'When did the latest scheduled test run'
        },
        'test_schedule_list_table_repeated': {
            content: 'How often should the test be repeated'
        },
        'test_schedule_list_table_delete_button': {
            content: 'Delete scheduled test'
        },
        'test_schedule_list_table_edit_button': {
            content: 'Change scheduled test'
        },
     
      
        'test_list_table_title': {
            content: 'Name of test'
        },
        'test_list_table_url': {
            content: 'Target site URL'
        },
        'test_list_table_status': {
            content: 'Status of test'
        },
        'test_list_table_started': {
            content: 'Date and time when the test was started'
        },
        'test_list_table_ended': {
            content: 'Date and time when the test was ended'
        },

        'test_view_config_deleted': {
            content: 'The test configuration has been deleted since this test was run'
        },
        'test_view_config_modified': {
            content: 'The test configuration has been modified since this test was run'
        },
        'test_view_url_result_table_url': {
            content: 'URL of resource that was loaded'
        },
        'test_view_url_result_table_loadzone': {
            content: 'Load zone where results were measured'
        },
        'test_view_url_result_table_user_scenario': {
            content: 'User scenario that was executed'
        },
        'test_view_url_result_table_successful': {
            content: 'Number of successful transactions (response code 200)'
        },
        'test_view_url_result_table_failed': {
            content: 'Number of unsuccessful transactions'
        },
        'test_view_url_result_table_min': {
            content: 'Minimum response time seen during test'
        },
        'test_view_url_result_table_last': {
            content: 'Last response time seen'
        },
        'test_view_url_result_table_max': {
            content: 'Maximum response time seen during test'
        },
     
        'user_scenario_editor_lile': {
            content: 'Our menu-based script editor'
        },
     
        'user_scenario_editor_text': {
            content: 'Our standard, text-based script editor'
        },


        'config_create': {
            content: 'Create new test configuration'
        },

        'config_delete': {
            content: 'Delete selected test configurations'
        },

        'config_start_test': {
            content: 'Start load test based on this test configuration'
        },

        'test_auto_create_start': {
            content: 'Automatically creates a ramp-up load test (0 to 50 '
                     + 'concurrent users during 15min) from specified website URL'
        },

        'test_auto_url': {
            content: 'Website URL to analyze and load test'
        },

        'test_export': {
            content: 'Export test results as a CSV file'
        },
        'test_delete': {
            content: 'Delete selected tests and associated results'
        },

        'test_result_rename_button': {
            content: 'Click to rename this test result'
        },

        'analyze': {
            content: 'Analyze your page to create a user scenario'
        },

        'page_analyzer_analyze': {
            content: 'Analyze specified website URL emulating selected browser'
        },

        'page_analyzer_browser_emulation': {
            content: 'Web browser to emulate during analysis'
        },

        'page_analyzer_url': {
            content: 'Website URL to analyze and collect performance metrics for'
        },

        'page_analyzer_settings': {
            content: 'Specify detailed settings for page analysis such as HTTP '
                     + 'authentication and client bandwidth limitation.'
        },

        'proxy_recorder': {
            content: 'Use the proxy recorder to record a user scenario'
        },

        'user_scenario_copy': {
            content: 'Duplicate this user scenario'
        },

        'user_scenario_create': {
            content: 'Create a new user scenario'
        },

        'user_scenario_delete': {
            content: 'Delete selected user scenarios'
        },

        'validation': {
            content: 'Run a validation to verify the functionality of your script'
        },

        'editor_save_script': {
            content: 'Save your user scenario.'
        },

        'pricing_vu_sbu_info_links': {
            content: 'Click to find out the difference between SBUs and VUs.'
        }
    },

    // ---- Helper functions below ------------
    
    tip: function(element, key, args) {
        var t = this.tips[key];

        if (t == undefined)
            return;

        var standard = {
            content: {
                text: t.text
            },
            position: {
                adjust: {
                    x: 12,
                    y: 12
                },
                effect: false,
                target: 'mouse'
            },
            show: {
                delay: 100,
                solo: false
            },
            style: {
                classes: 'ui-tooltip-tipsy ui-tooltip-shadow'
            }
        };

        var options = $.extend({}, standard, t);

        // Format strings if needed
        if (typeof args != 'undefined')
        {
            if (typeof options.content == 'string')
                options.content = options.content.format(args);
            else if (typeof options.content.text == 'string')
                options.content.text = options.content.text.format(args);
        }
        
        return $(element).qtip(options);
    },

    error: function(element, options, sel) {
        var standard = {
            content: {
                text: 'Error'
            },
            position: {
                my: 'center left',
                at: 'center right',
                target: $(sel),
                container: $(sel).parent()
            },
            show: {
                event: false,
                ready: true,
                solo: false
            },
            hide: false,
            style: {
                classes: 'ui-tooltip-red ui-tooltip-rounded ui-tooltip-shadow'
            }
        };
        var o = $.extend(true, {}, standard, options);

        return $(element).qtip(o);
    }
};

(function($) {
    /**
     * jQuery plugin to add regular tool tips
     * 
     * @param string   Key in LI.Tooltip.tips
     */
    $.fn.tooltip = function(tooltip_key, args) {
        return this.each(function() {
            LI.Tooltip.tip(this, tooltip_key, args);
        });
    };

    /**
     * Error tool tip displayed behind an input box
     * @param {}   Options for Qtip
     */
    $.fn.errortip = function(options) {
        var sel = $(this).selector;
        return this.each(function() {
            LI.Tooltip.error(this, options, sel);
        });
    };

    $.fn.errortip_top = function(options) {
        var sel = $(this).selector;
        var def = {
            position: {
                at: 'top center',
                my: 'bottom center'
            }
        };
        var o = $.extend({}, options, def);

        return this.each(function() {
            LI.Tooltip.error(this, o, sel);
        });
    };

})(jQuery);

