
/*
Glenn O Larsen - glenn@europlan.no
*/

// Make sure Firebug functions does'nt fail
try {
	console.info('Initialisation...');
} catch(e) {
	console = {
		log: function(){},
		info: function(){},
		debug: function(){},
		warn: function(){},
		error: function(){},
		dir: function(){},
		assert: function(){}
	}
}

var MP3Player = {

	id:"mp3player",
	object:null,
	error:0,

	running:false,
	
	init:function() {
	
		// Display mp3 player
    	var mp3box = document.getElementById('mp3box');
		if (mp3box) {
			mp3box.style.display = 'block';
			console.log('A');			
		}
		
			
		if (document.getElementById(this.id)) {
			this.object = document.getElementById(this.id);
			return; 
		};
		alert('Problemer med MP3 spiller.\nVennligst, last ned istedenfor.');
	},
	
	play2:function() {
	 this.object.SetVariable("player:jsPlay", "");
	},
	
    play:function(url, text) {    
    	if (!this.object) { this.init(); }

		try {    	
    		this.object.SetVariable("player:jsUrl", "/download/" + url + "/embeded.mp3");
    		this.object.SetVariable("player:jsPlay", "");
    		//setTimeout('MP3Player.play2();', 2000);
			if (document.getElementById('nowplaying')) {
				document.getElementById('nowplaying').innerHTML = text;
			}
			
		} catch(e) {
			// box is not ready, lets try again
			if (this.error > 5) {
				alert('Beklager det er problemed med MP3 spilleren.');
				return;
			} 
			this.error++;
			setTimeout('MP3Player.play(' + url + ', "' + text + '");', 1000);
		}    	    	    	
    },
    
    // Stop active song
    stop:function() {
    	if (!this.object) { this.init(); }
    	this.object.SetVariable("player:jsStop", "");    	
    },
    
    // Pause the active song
    pause:function() {
    	if (!this.object) { this.init(); }
    	this.object.SetVariable("player:jsPause", "");
    }
    	
};