var sonidoAnterior;

Onda = function(game){
	this.game = game;
}

Onda.prototype = {

	AddEmitter:function(){
	   	this.Do_sound = this.game.add.audio('Do');
		this.Mi_sound = this.game.add.audio('Mi');
		this.Sol_sound = this.game.add.audio('Sol');
		
		//  Here we create 2 new groups
    	this.ondasAmarillas = game.add.group();
    	this.ondasAzules = game.add.group();
    	this.ondasRojas = game.add.group();

		game.time.events.loop(800, this.updateOndasLow, this);
    	game.time.events.loop(500, this.updateOndasMed, this);
    	game.time.events.loop(300, this.updateOndasHigh, this);
		
		this.sounds = [];
	},
	updateOndasLow: function(){
		if(HErz == 10){
			//this.createOnda(this.ondasAmarillas,'burbujaLow');

			this.sound = this.Do_sound;
			this.sound.play();
			this.sounds.push(this.sound);
		}
	},
	updateOndasMed: function(){
		if(HErz == 40){
			//this.createOnda(this.ondasAzules,'burbujaMed');
			this.sound = this.Mi_sound;
			this.sound.play();
			this.sounds.push(this.sound);
		}
	},
	updateOndasHigh:function(){
		if(HErz == 80){
			//this.createOnda(this.ondasRojas,'burbujaHigh');
			this.sound = this.Sol_sound;
			this.sound.play();
			this.sounds.push(this.sound);
		}
	},
	createOnda: function(group, sprite){

			var onda = game.add.sprite(200-30, 200-65, sprite);
			onda.angle += 120;
			onda.anchor.setTo(0.5, 0.5);
			onda.scale.x = 0.1;
			onda.scale.y = 0.1;

			onda.alpha = 0.5;


			group.add(onda);
	},
	updateOndas: function(group){

		if(group.children.length > 0){
			for(var i = 0; i<group.children.length; i++){
				group.children[i].x += 3;
				group.children[i].y -= 1;	

				if(group.children[i].scale.x < 1)	{
					group.children[i].scale.x += 0.01;
					group.children[i].scale.y += 0.01;
				}
			}
		}
	},
	Update: function(){

		this.updateOndas(this.ondasAmarillas);
		this.updateOndas(this.ondasAzules);
		this.updateOndas(this.ondasRojas);

	},
	showOnda: function(){
		
	},

	stfu: function()
	{
		for (i = 0; i < this.sounds.length; i++)
		{
			//this.sounds[i].stop(); // ALTISIMO BUG, no funca!!!
			this.sounds[i].volume = 0;
		}
	}
}



