var onLoad;
BackgroundLoader = Class.create();
BackgroundLoader.prototype = {
    initialize: function(image, config) {
        this.image = image;
        this.namespace = "BackgroundLoader";
        this.config = config || {}
        this.construct();

        if (config.onLoad) onLoad = config.onLoad;
    },
    construct: function() {

        var container = document.createElement('DIV');
        container.id  = this.config.containerID || 'bgcontainer';
        if (this.config.className) {
            container.className = this.config.className;
        } else {
            container.style.position    = 'fixed';
            container.style.top         = '0';
            container.style.left        = '0';
            container.style.width       = '100%';
            container.style.height      = '100%';
            container.style.overflow    = 'hidden';
        }
        document.body.insertBefore(container, document.body.firstChild);

        var innercontainer = document.createElement('DIV');
        innercontainer.id = 'innercontainer';

        container.appendChild(innercontainer);

        var flashvars = {
            background: this.image,
            loadingInterval: this.config.loadingInterval || 1,
            onLoad: this.onLoad || Prototype.emptyFunction,
            onError: this.config.onError || Prototype.emptyFunction,
            onInitialize: this.config.onInitialize || Prototype.emptyFunction,
            onComplete: this.config.onComplete || Prototype.emptyFunction
        };

        var params = {
          menu: this.config.menu || "false",
          allowScriptAccess: "always",
          bgcolor: this.config.bgColor || '#ffffff',
          wmode: 'transparent'
        };
        
        var attributes = {
            id: this.config.id || "bgobject"
        };

        swfobject.embedSWF(this.config.swfLocation || "BackgroundLoader.swf", "innercontainer", '100%', '100%', "9.0.0","js/expressInstall.swf", flashvars, params, attributes);
    },
    
    inner: function() {
        var dE = document.documentElement || document.body;
        var innerWidth = dE.clientWidth || window.innerWidth;
        var innerHeight = dE.clientHeight || window.innerHeight;
        if (window.innerWidth) innerWidth = window.innerWidth;
        if (window.innerHeight) innerHeight = window.innerHeight;
        return { width: innerWidth, height: innerHeight };
    },

    onLoad: function(e) {
        if (onLoad) {
            json = e.evalJSON();
            json.prettyPercentage = [json.percentLoaded, '%25'].join('');
            onLoad(json);
        }
    }
}