
var UaPlayer = function(config) {
	
	//this.player = null;
	this.config = {
		swf				: '/js/player/player.swf',
		version			: 9,
		color			: '#FFFFFF',
		params			: {
			displayclick	: 'play',
			backcolor		: '#000000',
			frontcolor		: '#af9fe8',
			lightcolor		: '#af9fe8',
			screencolor		: '#000000'
		}
	};

	this.copyConfig(this.config, config);
	this.initialize();
}

UaPlayer.prototype.copyConfig = function(t, s) {
	for (var p in s) {
		if (typeof s[p] == 'object') {
			this.copyConfig(t[p], s[p]);
		}
		else {
			t[p] = s[p];
		}
	}
}

UaPlayer.prototype.initialize = function() {
    var oSWF = new SWFObject(
    	    this.config.swf, 
    	    this.config.id, 
    	    this.config.width, 
    	    this.config.height, 
    	    this.config.version, 
    	    this.config.color
   	);
    oSWF.addParam("allowfullscreen", "true");
    oSWF.addParam("allowscriptaccess", "always");
    oSWF.addParam("flashvars", this.getParameters());
    oSWF.addParam("wmode", "transparent");
    oSWF.write(this.config.screen);
}

UaPlayer.prototype.getParameters = function() {
	var s = "";
	for (var p in this.config.params) {
		if (s != "")
			s += "&";
		s += p + "=" + this.config.params[p];
	}
	
	return s;
}

UaPlayer.prototype.play = function() {
	this.player.sendEvent('PLAY');
}
UaPlayer.prototype.seek = function(pos) {
	this.player.sendEvent('PLAY');
	this.player.sendEvent('SEEK', pos);
}
UaPlayer.prototype.stop = function() {
	this.player.sendEvent('STOP');
}
