function phpBBGoogleWave() {}

phpBBGoogleWave.prototype.setup = function(bgcolour,colour,font,fontsize) {
    this.waves = [];
    this.wavePanels = [];
    this.bgcolour = bgcolour;
    this.colour = colour;
    this.font = font;
    this.fontsize = fontsize;
    this.debug = false;
};

phpBBGoogleWave.prototype.turnDebugOn = function() {
    this.debug = true;
};

phpBBGoogleWave.prototype.turnDebugOff = function() {
    this.debug = false;
};

phpBBGoogleWave.prototype.randomDivId = function() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 16;
	var divId = 'google_wave_bbcode_embed_';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		divId += chars.substring(rnum,rnum+1);
	}
	return divId;
};

phpBBGoogleWave.prototype.addWave = function(waveId) {
        if(this.debug){
            var debugMessage = '';
        }
        var div = this.randomDivId();
        tempWaveId = waveId.split("#restored:wave:");
        if(tempWaveId[1]) {
            if(this.debug){
                debugMessage += 'WaveId seems to be an URL, trying to remove all extras from the string and extract the waveId: ' + waveId + '\r\n';
            }
            prePreRealWaveId = tempWaveId[1].replace("%252B","+");
            if(this.debug){
                debugMessage += '%252B replace with +\r\n';
            }
            preRealWaveId = prePreRealWaveId.split("-");
            preRealWaveId = preRealWaveId[0];
            if(this.debug){
                debugMessage += 'splitted on "-" result: ' + preRealWaveId + '\r\n';
            }
            tmp = preRealWaveId.split("+");
            tmp[1] = tmp[1].split(".");
            tmp[1] = tmp[1][0];
            preRealWaveId = tmp[0] + "+" + tmp[1];
            if(this.debug){
                debugMessage += 'splitted on "." result: ' + preRealWaveId + '\r\n';
            }
        } else {
            if(this.debug){
                debugMessage += 'WaveId seems just a waveId\r\n';
            }
            preRealWaveId = waveId;
        }
        realWaveId = preRealWaveId.replace(" ","");
	phpBBGoogleWave.waves.push({div: div, waveId: realWaveId});
        if(this.debug){
            debugMessage += 'WaveId: ' + realWaveId;
            alert(debugMessage);
        }
        return div;
};

phpBBGoogleWave.prototype.applyWaves = function() {
        if(this.debug){
            var debugMessage = '';
        }
        for( var i in phpBBGoogleWave.waves ) {
            if(phpBBGoogleWave.waves[i].div){
                var div = phpBBGoogleWave.waves[i].div;
                var waveId = phpBBGoogleWave.waves[i].waveId;
                phpBBGoogleWave.wavePanels[div] = new WavePanel('http://wave.google.com/wave/');
                phpBBGoogleWave.wavePanels[div].setUIConfig(this.bgcolour,this.colour,this.font,this.fontsize);
                phpBBGoogleWave.wavePanels[div].loadWave(waveId);
                phpBBGoogleWave.wavePanels[div].init(document.getElementById(div));
            }
        }
        if(this.debug){
            debugMessage += 'Waves applied they should start loading now';
            alert(debugMessage);
        }
};