
if (typeof haywaa == "undefined") var haywaa = new Object();

haywaa.flashControl = function(swf, id, w, h, ver)
{
	this.params = new Object();
    this.variables = new Object();
    this.attributes = new Array();
    if(swf) { this.setAttribute('swf', swf); }
    if(id) { this.setAttribute('id', id); }
    if(w) { this.setAttribute('width', w); }
    if(h) { this.setAttribute('height', h); }
}

haywaa.flashControl.prototype =
{
    setAttribute: function(name, value)
    {
        this.attributes[name] = value;
    },
    getAttribute: function(name)
    {
        return this.attributes[name];
    },
    addParam: function(name, value)
    {
        this.params[name] = value;
    },
    getParams: function()
    {
        return this.params;
    },
    addVariable: function(name, value)
    {
        this.variables[name] = value;
    },
    getVariable: function(name)
    {
        return this.variables[name];
    },
    getVariables: function()
    {
        return this.variables;
    },
    getVariablePairs: function()
    {
        var variablePairs = new Array();
        var key;
        var variables = this.getVariables();

        for(key in variables)
        {
			variablePairs[variablePairs.length] = key +"="+ variables[key];
        }
        return variablePairs;
    },
    getHTML: function()
    {
        var swfNode = "";
        if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length)
        {
            swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
            swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
            var params = this.getParams();
            for (var key in params)
            {
                swfNode += [key] +'="'+ params[key] +'" ';
            }
            var pairs = this.getVariablePairs().join("&");
            if (pairs.length > 0)
            {
                swfNode += 'flashvars="'+ pairs +'"';
            }
            swfNode += '/>';
        }
        else
        {
            swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height')+'" style="'+ this.getAttribute('style')+"border='5'" +'">';
            swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
            var params = this.getParams();
            for (var key in params)
            {
                swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
            }
            var pairs = this.getVariablePairs().join("&");
            if (pairs.length > 0)
            {
                swfNode += '<param name="flashvars" value="'+ pairs +'" />';
            }
            swfNode += "</object>";
        }
        return swfNode;
    },
    write: function(elementId)
    {
        var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;

        n.innerHTML = this.getHTML();
    }
}