﻿function FlashWriter(args) {
    this.params = {};
    this.variables = {};
    this.properties = { url: '', width: 300, height: 225, id: '' };
    for (var i in args)
        this.properties[i] = args[i];
}
FlashWriter.prototype = {
    render: function() {
        var html = '<object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + this.properties.width + '" height="' + this.properties.height + '"  id="' + this.properties.id + '"  name="' + this.properties.id + '">';
        html += '<param name="movie" value="' + this.properties.url + '">';
        html += '<param name="FlashVars" value="' + this.getVariableString() + '">';
        //html += '<param name="wmode" value="opaque">';
        html += this.getParamString(true);
        html += '<embed src="' + this.properties.url + '" width="' + this.properties.width + '" height="' + this.properties.height + '"  id="' + this.properties.id + '" name="' + this.properties.id + '"' + this.getParamString(false) + ' FlashVars="' + this.getVariableString() + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        html += '</object>';

        return html;
    },
    addParam: function(name, value) {
        this.params[name] = value;
    },
    addVariable: function(name, value) {
        this.variables[name] = value;
    },
    getVariableString: function() {
        var arr = [];
        for (var i in this.variables)
            arr.push(i + "=" + this.variables[i])
        return arr.join('&');
    },
    getParamString: function(isIE) {
        var arr = [];
        for (var i in this.params)
            if (isIE)
            arr.push('<param name="' + i + '" value="' + this.params[i] + '">');
        else
            arr.push(i + "=" + this.params[i]);
        return arr.join(' ');
    },
    write: function(el) {
        var o = document.getElementById(el);
        if (o == null) return;
        var ref = location.href;

        /*
        var rindex=ref.indexOf("#");
		
		if(rindex!=-1)
        {
        ref=ref.substring(0, rindex);
        alert(ref);
        }
        */
        if (ref.length > 0)
            this.addVariable('pageurl', ref);
        else
            this.addVariable('pageurl', '');

        fo.addVariable("from", "free");
        fo.addVariable("adcpid", 1210);

        o.innerHTML = this.render();
    }
}
