function initLevel () {
	var levelWidth = 5000;
	var levelHeight = 1000;
	var levelData;
	var respawn;
	var imgData = ['Cuitzeo/waves.png', 'Cuitzeo/waves_big.png', 'Cuitzeo/mask.png', 'Cuitzeo/wood_floor.png', 'Cuitzeo/wood_back.png', 'Cuitzeo/wood_front.png', 'Tacambaro/dirtpath.png','casita.png'];
	var wave3 = [[0.6, false]];
	var wave2 = [[0.8, false]];
	var wood_back = [[0.8, false], [7, 300, -200]];
	var wood_floor =[[1, true]];
	var wood_front =[[1, false]];
	var wave1 = [[1, false]];
	var wave0 = [[1.2, false]];
	var dirt = [[1, true]];
	var mask = [[0, false], [2,0,0]];
	dirt = dirt.concat(insertTiles(imgData, 6, 0, 526, 7, 1, 0, 0));
	wave3 = wave3.concat(insertTiles(imgData, 0, -400, 510, 3, 1, 0, 0));
	wave2 = wave2.concat(insertTiles(imgData, 0, -400, 565, 4, 1, 0, 0));
	wave1 = wave1.concat(insertTiles(imgData, 1, -400, 630, 5, 1, 0, 0));
	wave0 = wave0.concat(insertTiles(imgData, 1, -400, 695, 5, 1, 0, 0));
	wood_floor = wood_floor.concat(insertTiles(imgData, 3, 1554, 526, 4, 1, 0, 0));
	wood_front = wood_front.concat(insertTiles(imgData, 5, 1573, 480, 4, 1, 0, 0));
	wood_back = wood_back.concat(insertTiles(imgData, 4, 1350, 450, 4, 1, 0, 0));
	levelData = [imgData, wave3, wood_back, wave2, wood_floor,wave1, wood_front, wave0, dirt, mask];
	respawn = [[0, 200]];

	levelData.clouds = new Clouds ('01.png', 0.3, 0, 0);
	levelData.clouds1 = new Clouds ('03.png', 0.4, 0, 0);
	levelData.waves1;
	levelData.waves2;
	levelData.waves3;
	levelData.waves4;
	levelData.image;
	levelData.counter;
	levelData.cielo;
	levelData.init = function () {
		player = new Player ([[['tari/ir.png'],['tari/il.png']],[['tari/rr1.png', 'tari/rr2.png'],['tari/rl1.png', 'tari/rl2.png']],[['tari/jr1.png', 'tari/rr2.png'],['tari/jl1.png', 'tari/rl2.png']]], 1554, canvas.height/2-200);
		player.jump_speed = 35;
		camera = new Camera ([[-10, 3/4],[950, 1/2]]);
		ivan = new Ivan (0, 300);
		this.waves1 = new this.Waves(3);
		this.waves2 = new this.Waves(5);
		this.waves3 = new this.Waves(7);
		this.waves4 = new this.Waves(1);
		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 () {
		if(!paused){
			this.waves1.move();
			this.waves2.move();
			this.waves3.move();
			this.waves4.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();
		}
		if(i==6){
			
			context.save();
			//context.globalAlpha = 0.7;
		}
		if(i==7){
			context.restore();
			context.save();
			context.font= "normal 30px Verdana";
			context.fillStyle = "#FFFFFF";
			context.fillText("x "+this.counter, 45, 27);
			context.restore();
			context.drawImage(this.image, 0, 0);
		}
	}
	levelData.Waves = function (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;
			}
		}
	}
	return [levelData, levelWidth, levelHeight, respawn];
}

function insertTiles (imgData, imageCode, x, y, horTiles, verTiles, horSpace, verSpace) {
	var tempData = new Array (horTiles*verTiles);
	var i=0;
	var image = new Image ();
	image.src = imgData[imageCode];
	var width = image.width + horSpace;
	var height = image.height + verSpace;
	for(var j=0; j<verTiles; j++) {
		for(var k=0; k<horTiles; k++) {
			tempData[i] = new Array (3);
			tempData[i][0] = imageCode;
			tempData[i][1] = x + width*k;
			tempData[i][2] = y;
			i++;
		}
		y+= height;

	}
	return tempData;
}
function ParallaxBackground (imagePath, displacementRatio) {
	var image = new Image ();
	image.src = imagePath;
	this.x_pos = 0;
	this.y_pos = 0;
	this.draw = function () {
		context.drawImage (image, this.x_pos, this.y_pos);
		context.drawImage (image, this.x_pos - image.width, this.y_pos);
		context.drawImage (image, this.x_pos + image.width, this.y_pos);
		this.x_pos = -camera.x_pos*displacementRatio;
		this.y_pos = -camera.y_pos*displacementRatio;
		if(this.x_pos < 0) {
			this.x_pos += image.width;
		} else if (this.x_pos > image.width) {
			this.x_pos -= image.width;
		}
	}
}
function Clouds (imagePath, displacementRatio, x_pos, y_pos) {
	var image = new Image();
	image.src = imagePath;
	var x_disp =0;
	this.draw = function () {
		x_disp += 2*displacementRatio;
		x_pos = -camera.x_pos*displacementRatio + x_disp;
		y_pos = -camera.y_pos*displacementRatio;
		if(x_pos < 0) {
			x_pos += image.width;
		} else if (x_pos > image.width) {
			x_pos -= image.width;
		}
		context.drawImage (image, x_pos, y_pos);
		context.drawImage (image, x_pos - image.width, y_pos);
		context.drawImage (image, x_pos + image.width, y_pos);
	}
}