function initLevel () {
	levelWidth = 3000;
	levelHeight = 1000;
	imgData = ['tariacuri.png', 'cielo.jpg', 'Cuitzeo/sand.png', 'Cuitzeo/waves.png', 'Cuitzeo/waves_big.png', 'Cuitzeo/bubble.png', 'Minas/animacion.png'];
	var cielo = [[0, false], [1, 0, 0]];
	var nubes = [[0.2, false], new Clouds(0,0,7000,1000)];
	var sand = [[1, true], [0, 600, 3000, 200]];
	var objetos = [[1, false], new Material(500, false), new Wave(3, 0, 700, 2000, 1000, 0.5)];
	var wave3 = [[0.6, false]];
	var wave2 = [[0.8, false]];
	var wave1 = [[1.2, false]];
	var wave0 = [[1.4, false]];
	audioData = ["Venusi"];
	
	levelData = [cielo, nubes, wave3, wave2, wave1, sand, objetos, wave0];
	respawn = [[0, 200]];
	levelData.wave1 = new Waves (2);
	levelData.init = function () {
		levelData[2] = levelData[2].concat(insertTiles(3, 0, 700, 12, 1, 0, 0));
		player = new Player (0, [1, 1, 10, 10, 1, 1, 1, 1], 111, 160, 0, 0);
		//player.jump_speed = 0;
		camera = new Camera ([[-10, 1/3]]);
		ivan = new Ivan (0, 300);
		levelData[6] = levelData[6].concat(player, ivan);
		/*this.waves1 = new this.Waves(2);
		this.waves2 = new this.Waves(3);
		this.waves3 = new this.Waves(4);
		this.waves4 = new this.Waves(6);
		this.waves5 = new this.Waves(1);
		this.material1 = new this.Material('Cuitzeo/alga.png', 800, 880, false);
		this.material2 = new this.Material('Cuitzeo/basura.png', 1800, 880, true);
		this.image = new Image();
		this.image.src = 'Cuitzeo/counter_image.png';
		this.counter=0;
		this.cielo = new Image();
		this.cielo.src = 'cielo.jpg';*/
	}
	levelData.logic = function () {

		//this.wave1.move();
		/*if(!paused){
			this.waves1.move();
			this.waves2.move();
			this.waves3.move();
			this.waves4.move();
			this.waves5.move();
		}*/
	}
	levelData.draw = function (i, displacementRatio) {
		/*if(i==1){
			context.drawImage(this.cielo, 0, 0);
			this.clouds.draw();
			this.clouds1.draw();
		}
		if(i==4){
			player.draw();
			ivan.draw();
			context.save();
			context.globalAlpha = 0.7;
		}
		if(i==5){
			context.restore();
			this.material1.draw_bubbles();
			this.material2.draw_bubbles();
		}
		if(i==6){
			context.save();
			context.globalAlpha = 0.7;
		}
		if(i==7){
			context.restore();
			this.material1.draw();
			this.material2.draw();
			this.material1.cutscene();
			this.material2.cutscene();
			context.save();
			context.font= "normal 30px Verdana";
			context.fillStyle = "#FFFFFF";
			context.fillText("x "+this.counter, 45, 27);
			context.restore();
			context.drawImage(this.image, 5, 0);
		}*/
	}
}
function Material (x_pos, tule) {
	this.x_pos = x_pos;
	this.y_pos = 500;
	this.width = 50;
	this.height = 1000;
	var bubbles = new Array();
	var mensaje;
	if(!tule)
		mensaje = "¡Correcto!|Esto es basura, hay que sacarla de aqui para|mantener el lago limpio";
	else
		mensaje = "¡Correcto!|Esta planta nos ayudará a hacer las canastas";
	var exists = true;
	var alpha =1;
	for(var i=0; i<4; i++){
		bubbles[i] = new Bubbles(this.x_pos, 1000);
	}
	/*this.cutscene = function () {
		if(cutscene.started&&alpha>0){
			cutscene.move();
			cutscene.textBox.draw();
			if(cutscene.finished){
				alpha-= 0.1;
			}
			else
				context.drawImage(boxes, 0, 200);
		}else if(player.isColliding(x_pos, y_pos-canvas.height, image.width, canvas.height)&&lastPress==1&&!cutscene.started){
			on_cutscene = true;
			if(player.y_pos+player.height<y_pos){
				player.y_pos+=5;
				player.cutscene_animation(swimming_down, 4);
				camera.move();	

			}else{
				cutscene.move();
				player.state='idle';
				if(!is_trash)
				levelData.counter++;
			}
		}
		if(player.y_pos>420&&!finished&&cutscene.finished){
			on_cutscene = true;
				player.y_pos-=5;
				player.cutscene_animation(swimming_up, 4);
				camera.move();			
		}
		else if(cutscene.finished) {
			on_cutscene=false;
			finished = true;
		}
		
	}*/
	this.draw = function () {
		this.draw_bubbles();
		if(!exists)
			return;
		if(player.isColliding(this.x_pos, this.y_pos, this.width, this.height)){
			if((pressed_control&&!on_cutscene)||(player.state == 'cutscene'))
				player.cutscene_animation(6, 2, 3);
			if(player.state=='finished'){
				player.state = 'idle';
				cutscene = new Cutscene([[player.x_pos+(player.width-canvas.width)/2, player.y_pos+(player.height-canvas.height)/2]], [["¡Has conseguido un trozo de cobre!"]]);
				exists = false;
			}
		}
		/*if(cutscene.started&&alpha>0){
			context.save();
			context.globalAlpha = alpha;
			context.drawImage(image, x_pos-camera.x_pos-image.width/2+50, y_pos-200-camera.y_pos-image.height/2);
			context.restore();
		}*/
	}
	this.draw_bubbles = function(){
		context.save();
		for(var i=0; i<bubbles.length; i++){
			bubbles[i].draw(exists);
		}
		context.restore();
	}
}
function Bubbles (init_x, init_y) {
	var x_pos;
	var y_pos;
	var y_speed;
	var y_accel;
	var x_disp;
	var x_speed;
	var alpha =0;
	this.init = function () {
		x_pos = init_x + Math.floor(Math.random()*25);
		y_pos = init_y;
		y_speed = 0;
		y_accel = Math.random()/15 + 0.07;
		x_speed = 0.15;
		x_disp = 0;
		alpha = 1;
	}
	this.draw = function (exists) {
		if(alpha<=0&&exists)
			this.init();
		x_disp = Math.sin(Math.PI*x_speed)*6;
		x_speed+=0.15;
		y_speed+=y_accel;
		y_pos-=y_speed;
		context.globalAlpha = alpha;
		drawOnCanvas(imgData[5], x_pos+x_disp-camera.x_pos, y_pos-camera.y_pos);
		if(y_pos<=600)
			alpha-=0.2;
	}
}
function Waves (layer_ind) {
	var x_disp=0;
	var y_disp=0;
	var x_speed=0;
	var y_speed=0;
	var displacementRatio = levelData[layer_ind][0][0];
	this.move = function () {
		x_disp = Math.sin(x_speed*Math.PI)*2*displacementRatio - x_disp;
		y_disp = Math.sin(y_speed*Math.PI)*displacementRatio - y_disp;
		x_speed+= 0.005*displacementRatio;
		y_speed+= 0.03*displacementRatio;
		if(x_speed>2)
			x_speed-=2;
		if(y_speed>2)
			y_speed-=2;
		for(var i=1; i<levelData[layer_ind].length; i++) {
			levelData[layer_ind][i][1]+=x_disp;
			levelData[layer_ind][i][2]+=y_disp;
		}
	}
}