/** Klasa wyprowadzająca flasha na podanego elementu */

Flash.prototype.setVisible;
Flash.prototype.toString;
Flash.prototype.insert;
Flash.prototype.dispose;

Flash.prototype.setId;
Flash.prototype.addFlashParam;
Flash.prototype.addFlashVar;

/**
 * Sktyptowe ładowanie i wyświetlanie flasha
 * @version 1.1
 */
function Flash(file, width, height, targetId) {

    this.memTop = null;

    if (!Flash._created){

//        Flash.prototype.setVisible = function(visible){
//            if (!this._target) return;
//            var top = '-3000px';
//            if (visible == false) {
//                this.memTopp = this._target.style.top;
//                top = '-3000px';
//            }
//            else if (visible == true || this._target.style.top == '-3000px')
//                top = this.memTop;
//
//            this._target.style.top = top;
//        };


        Flash.prototype.setVisible = function(visible){
            if (!this._target) return;
            var display = 'none';
            if (visible == false) display = 'none';
            else if (visible == true || this._target.style.display == 'none')
                display = 'block';

            this._target.style.display = display;
        };

        Flash.prototype.insert = function(position, top, left, right, bottom){
            if (this._isInserted) return;

            this._target = document.getElementById(this._targetIdName);
            if (!this._target) {
                /* utworzenie nowego elementu do wrzucenia */
//                this._myTarget = true;
                this._target = document.createElement('div');
                this._target.id = this._targetIdName;
//                this._target.style.display = 'none';

                document.body.appendChild(this._target);
            }  else {
                this._targetInner = this._target.innerHTML;
            }

            if (top || left || right || bottom) {
                if (!position) position = 'absolute';
                this._target.style.position = position;
                if (top) {
                    this._target.style.top = top + 'px';
                    this.top = top;
                }
                if (left) this._target.style.top = left + 'px';
                if (right) this._target.style.top = right + 'px';
                if (bottom) this._target.style.top = bottom + 'px';
            }

            this._target.innerHTML = this.toString();
            this._isInserted = true;
        };

        Flash.prototype.toString = function(file){
            return AC_FL_CreateContent(this._flashParams, this._flashVars);
        };

        Flash.prototype.dispose = function(){
            if (this._targetInner) {
                this._target.innerHTML = this._targetInner;
            } else
                if (this._target) document.body.removeChild(this._target);
            this._isInserted = false;
        };

        Flash.prototype.addFlashParam = function(name, value){
            this._flashParams.push(name, value);
        };

        Flash.prototype.addFlashVar = function(name, value){
            this._flashVars[name] = value;
        };

        Flash.prototype.setId = function(id){
            this._flashParams['id'] = id;
        };

    }

    this._targetIdName = targetId;
    this._flashParams = new Array();
    this._flashVars = new Array();
    this._isInserted = false;

    this.addFlashParam('codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab');
    this.addFlashParam('pluginspage', 'http://www.adobe.com/go/getflashplayer');
    this.addFlashParam('type', 'application/x-shockwave-flash');
    this.addFlashParam('src', file);
    this.addFlashParam('width', width);
    this.addFlashParam('height', height);

}

Flash.open = function(file, width, height, targetId){

    var flash = new Flash(file, width, height, targetId);
    if (!targetId) return flash.toString();
    else {
        flash.insert();
        flash.setVisible(true);
        return flash;
    }

}

