(function()
{
    //
    // this fix makes FusionCharts work in Mozilla Firefox.
    //
    // it is required because of firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=733698
    //
    // the fix will:
    // (-) explicitly re-render charts when they become visible
    // (-) turn off repaints when a chart becomes invisible
    //
    "use strict";

    if (!FusionCharts)
        return;

    var moz = navigator.userAgent.indexOf("Gecko") > -1 && navigator.userAgent.indexOf("KHTML") == -1;
    if (!moz)
        return;

    var iframe = window.frameElement;
    if (!iframe)
        return;

    var charts = [];

    // monitor the visibility of the <iframe/>
    function _isVisible() { return !!iframe.offsetParent; }
    var wasVisible = _isVisible();
    var interval = setInterval(function()
    {
        var isVisible = _isVisible();
        if (wasVisible == isVisible)
            return;
        wasVisible = isVisible;
        charts.forEach(isVisible ? render : lockResize);
    }, 250);

    // hook into FusionCharts
    FusionCharts.addEventListener("Initialized", function(ev)
    {
        charts.push(ev.sender);
    });
    FusionCharts.addEventListener("Disposed", function(ev)
    {
        var index = charts.indexOf(ev.sender);
        if (index >= 0)
            charts.splice(index, 1);
    });

    function render(chart)     { chart.render(); }
    function lockResize(chart) { chart.jsVars.resizeLocked = true; }
})();