//<![CDATA[

/* Version 1.0.3
 * Copyright (c) 2008 True Partners, LLC (wearetrue.com)
 *
 * 3 mar 2008 18:34
 * 
 * requires True core v1.1
 * cannot be compresed and cannot use $().html
 */
 
if(window.True.SWF == undefined)
{
    Type.register("True.SWF",
        function(src, id, c){
	        this.id = id;
	        this.src = src;
			c = c || {};
	        this.params = c.params || {};
	        this.variables = c.variables || {};
	        this.attributes = c.attributes || {};
	        this.params.quality = this.params.quality || "high";
	        this.attributes.width = this.attributes.width || "100%";
	        this.attributes.height = this.attributes.height || "100%";
			True.SWF[this.id] = this;
        }
     );
     
    True.SWF.prototype = {
	    setVariable: function(name, value){
	        if(!this.getMovie()){
		        this.variables[name] = value;
		    }
		    else{
		        this.getMovie().SetVariable(name, value);
		    }
	    },
	    getVariablePairs: function(){
		    var vps = [];
		    for(var key in this.variables){
			    vps.push(key +"="+ this.variables[key]);
		    }
		    return vps;
	    },
	    getSWFHTML: function() {
		    var swfNode = "";
		    var pairs = this.getVariablePairs().join("&");
		    if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
		        swfNode = "<embed type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" src=\""+ this.src + "\" width=\"" + this.attributes.width + "\" height=\"" + this.attributes.height + "\"";
			    swfNode += " id=\"" + this.id +"\" name=\"" + this.id + "\" ";
			    for(var key in this.params){ swfNode += key + "=\"" + this.params[key] + "\" "; }
			    if (pairs.length > 0){ swfNode += "flashvars=\""+ pairs + "\""; }
			    swfNode += "/>";
		    } else { // PC IE
			    swfNode = "<object id=\""+ this.id + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+ this.attributes.width + "\" height=\"" + this.attributes.height +"\">";
			    swfNode += "<param name=\"movie\" value=\""+ this.src + "\" />";
			    for(var key in this.params) {swfNode += "<param name=\"" + key + "\" value=\"" + this.params[key] + "\" />";}
			    if(pairs.length > 0) {swfNode += "<param name=\"flashvars\" value=\"" + pairs + "\" />";}
			    swfNode += "</object>";
		    }
		    return swfNode;  
	    },
	    create: function(target, fsCommand){
		    var t = (typeof target == 'string') ? $("#" + target).get(0) : target;
		    var fs = "";
			if(fsCommand){
				this.params.allowScriptAccess = "always";
				fs = this.generateFsCommand();
		    }
		    t.innerHTML = this.getSWFHTML() + fs;
		    return true;
	    },
	    getMovie : function(){
	        if(!this.movie){this.movie = document.getElementById(this.id); }
	        return this.movie;
	    },
	    setJSON : function(data){
	        if((data instanceof Object)){this.setVariable("JSONData", Object.toJSON(data));}
	    },
	    _onFSCommand : function(command, args){
			if(command == "JSON"){
				args = args.parseJSON();
			}
			if(this[command]){
				this[command](args);
			}
			this.onFSCommand(command, args);
			this.dispatchEvent("fsCommand", {command: command, args: args});
	    },
	    onFSCommand : function(command, args){
	    },
	    generateFsCommand: function(){
			var js = '<script type="text/javascript">\n\tfunction ' + this.id + '_DoFSCommand(command, args) {\n';
			js += '\t\tTrue.SWF.' + this.id + '._onFSCommand(command, args);\n}\n</script>';
			$("head").append(js);
			// Win.IE
			if ($.browser.msie && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
				return '<script event=FSCommand(command,args) for=' + this.id + '>True.SWF.' + this.id + '._onFSCommand(command, args);</script>';
			}
			return "";
	    }
    }
	True.EventDispatcher.decorate(True.SWF.prototype);
}
//]]>