var player = {

	playerId: 'mp3Player',

	buttonId: 'playerButton',

	file: 'http://vk.oa-server.de/wp-content/themes/seherin/img/sound.mp3',

	playerObj: null,

	buttonNode: null,

	isPlaying: false,

	position: 0,

	init: function(){

		this.playerObj = document.getElementById(this.playerId);
		this.buttonNode = document.getElementById(this.buttonId);

		var autoPlay = true;
		if(localStorage && localStorage.getItem('playerState') == "false"){
			autoPlay = false;
		}
		autoPlay && this.play();
	},

	onInit: function(){
		this.init();
	},

	onUpdate: function(){
		
	},

	pause: function(){
		this.playerObj.SetVariable("method:stop", "");
		this.updateState(false);
	},

	play: function(){
		if (this.position == 0) {
			this.playerObj.SetVariable("method:setUrl", this.file);
		}
		this.playerObj.SetVariable("method:play", "");
		this.playerObj.SetVariable("enabled", "true");
		this.updateState(true);
	},

	saveState: function(isPlaying){
		localStorage && localStorage.setItem('playerState', isPlaying);
	},

	toggle: function(){
		this[this.isPlaying == "true" ? "pause" : "play"]();
	},

	updateButton: function(isPlaying){
		this.buttonNode.className = isPlaying ? 'playing' : 'paused';
	},

	updateState: function(isPlaying){
		this.updateButton(isPlaying);
		this.saveState(isPlaying);
	}
};

