function initMinas () {
	levelWidth = 9000;
	levelHeight = 8000;
	/*imgData = ['Minas/8.png', 'Minas/fondo.jpg', 'Minas/2.png', 'Minas/3.png', 'Minas/4.png', 'Minas/5.png', 'Minas/6.png', 'Minas/9.png', 'tariacuri.png','Minas/Luz.png',
		'Minas/ore_particle.png', 'Minas/ore.png', 'Minas/animacion.png', 'Minas/ore_halo.png', 'Minas/portalRays.png', 'Minas/portalBase1.png', 'Minas/portalBase2.png', 'Minas/pilar.png', 'Minas/ivan_mask.png', 'Minas/ivan_particles_mask.png',
		'Minas/tari_mask.png', 'Minas/ore_mask.png', 'Minas/viejito.png', 'Minas/oreSmall.png'];*/
	//audioData = [audioData[1], audioData[0]];
	var temp = audioData[0];
	audioData[0] = audioData[1];
	audioData[1] = temp;
	var background = [[0.05, false]];
	var stones = [[1, false], [4, 350, 350], [5, 900, 380], [6, 1000, 100], [4, 1600, 350], [5, 1900, 380], [4, 2600, 350], new Ore(4, 1030, 7150), new Ore(5, 700, 1750), new Ore(6, 916, 1170), new Ore(4, 0, 1450), new Ore(4, 4000, 7500),  new Ore(6, 5200, 4980), new Ore(6, 4000, 5950), new Ore(5, 5700, 7150), new Ore(5, 4004, 6650), new Ore(6, 7500, 7500)];
	var ground = [[1, true], [-100, 0, 100, 8000], [9000, 0, 100, 8000], [0, 7000, 200, 1000], [7, 2000, 7500], [7, 1600, 7400], [7, 1200, 7400], [7, 1000, 7400], [7, 3000, 7500], [7, 3400, 7400], [17, 4000, 1650], [17, 8800, 7400],
		[7, 3100, 1780], [7, 2800, 1680], [7, 2500, 1580], [7, 2200, 1480], [7, 1900, 1380], [7, 246, 1680], [7, 0, 1680], [7, 6800, 7500], [7, 5150, 7300], [7, 4700, 7100], [7, 4250, 6900], [7, 4004, 6900],];
	var objetos = [[1, false], new Viejito(100, 7526), new Transporte(3450, 7270, 0, 1840), new Transporte(3700, 1870, 3450, 7240), new Transporte(5000, 7600, 5000, 5000)];
	var mask = [[0,false]];
	var foreground = [[1.2, false], [2, 0, 0], [3, -80, 9050]]
	levelData = [background, stones, ground, objetos, mask, foreground];
	respawn = [[0, 200]];


	levelData.init = function () {
		contador = new Counter(10, 10, 23);
		//contador.counter = 5;
		player = new Player (8, [1, 1, 10, 10, 1, 1, 1, 1], 111, 160, 700, 7566);
		audioData[0].loop = true;
		audioData[0].play();
		player.facing = 'left';
		cutscene = undefined;
		ivan = new Ivan (500, 7500);
		levelData[3] = levelData[3].concat(player, ivan);
		levelData[2] = levelData[2].concat(insertTiles(0, 0, 7726, 40, 1, 0, 0));
		levelData[2] = levelData[2].concat(insertTiles(0, 0, 2000, 20, 1, 0, 0));
		levelData[2] = levelData[2].concat(insertTiles(7, 916, 1380, 4, 1, 0, 0));
		levelData[2] = levelData[2].concat(insertTiles(7, 5000, 5160, 4, 1, 0, 0));
		levelData[2] = levelData[2].concat(insertTiles(7, 4000, 6160, 4, 1, 0, 0));
		levelData[2] = levelData[2].concat(insertTiles(7, 5600, 7400, 4, 1, 0, 0));
		levelData[0] = levelData[0].concat(insertTiles(1, 0, 0, 2, 3, 0, 0));
		camera = new Camera ();

	}
	levelData.logic = function () {
		if(cutscene==undefined&&fade.state=='idle'){
			cutscene = new Cutscene([[00, 7300]], [["¡Bienvenido a la mina!", "Este oscuro y viejo lugar está lleno de secretos, abre muy bien los ojos|entre la oscuridad se pueden ver pequeños destellos, acércate a ellos y|presiona la tecla SHIFT para sacar oro.", 
			"¡La mina no es un lugar para niños! Encuentra 5 piezas de oro y ven|a verme… a menos de que te gusten los retos… ", "En ese caso tráeme 10 piezas de oro y te daré un reconocimiento|especial.|Buena suerte, la necesitarás."]]);
		}
	}
	levelData.draw = function (i, displacementRatio) {
		lightning();
		contador.draw();
		//context.fillText(player.x_pos+"/"+player.y_pos, 0, 500);
		//context.drawImage(imgData[11], 0, 0);
	}
}
var contador;
var light_canvas = document.createElement('canvas');
var light_ctx = light_canvas.getContext('2d');
light_canvas.width = 960;
light_canvas.height = 540;
function Transporte (x, y, x2, y2) {
	this.x_pos = x;
	this.y_pos = y;
	this.imageCode = 14;
	var started = false;
	var raysAlpha = 0;
	var baseAlpha = 0;
	this.draw = function () {
		raysAlpha += dt*0.5;
		baseAlpha += dt*0.8;
		if(raysAlpha>=1)
			raysAlpha-=1;
		if(baseAlpha>=1)
			baseAlpha-=1;
		light_ctx.globalAlpha = 1;
		light_ctx.drawImage(imgData[20], this.x_pos-camera.x_pos-80, this.y_pos-camera.y_pos-70);
		context.save();
		context.globalAlpha = 0.4*Math.sin(raysAlpha*Math.PI)+0.6;
		drawOnCanvas (imgData[14], this.x_pos-camera.x_pos, this.y_pos-camera.y_pos);
		context.globalAlpha = Math.sin(baseAlpha*Math.PI);
		drawOnCanvas (imgData[15], this.x_pos-camera.x_pos, this.y_pos-camera.y_pos);
		context.globalAlpha = 1 - Math.sin(baseAlpha*Math.PI);
		drawOnCanvas (imgData[16], this.x_pos-camera.x_pos, this.y_pos-camera.y_pos);
		context.restore();
		if(player.isColliding(this.x_pos+61, this.y_pos, 1, 150)&&pressed_control&&fade.state=='idle'){
			fade.out();
			started = true;
		} else if(started&&fade.state=='idle'){
			player.x_pos = x2;
			player.y_pos = y2;
			ivan.x_pos = x2;
			ivan.y_pos = y2;
			camera.move();
			fade.in();
			started = false;
		}
	}
}
function Ore (imageCode, x_pos, y_pos) {
	this.x_pos = x_pos;
	this.y_pos = y_pos;
	this.imageCode = imageCode;
	var exists = true;
	var ore = false;
	var particles = new Array();
	var mask_alpha = 0;
	var rotation_degree = 0;
	var rotated_halo;
	for(var i=0;i<3;i++)
		particles[i] = new particle1(x_pos+150, y_pos+100);
	this.draw = function () {
		drawOnCanvas(imgData[this.imageCode], this.x_pos-camera.x_pos, this.y_pos-camera.y_pos);
		if(!exists)
			return;
		
		if(player.isColliding(this.x_pos + getWidth(this.imageCode)/2 - 25, this.y_pos+ getHeight(this.imageCode)/2 - 25, 50, 50)&&!ore){
			if((pressed_control&&!on_cutscene)||(player.state == 'cutscene'))
				player.cutscene_animation(12, 2, 3);
			if(player.state=='finished'){
				player.state = 'idle';
				contador.add();
				cutscene = new Cutscene([[this.x_pos-canvas.width/2+getWidth(this.imageCode)/2, this.y_pos-canvas.height/2+getHeight(this.imageCode)/2]], [["¡Has conseguido un trozo de oro!"]]);
				ore = true;
			}
		}
		if(ore) {
			rotation_degree+=120*dt;
			light_ctx.globalAlpha = mask_alpha;
			light_ctx.drawImage(imgData[21],this.x_pos+getWidth(this.imageCode)/2-230-camera.x_pos, this.y_pos-camera.y_pos-250);
			if(rotation_degree>360)
				rotation_degree-=360;
			rotated_halo = rotate(imgData[13], rotation_degree);
			if(cutscene.finished&&mask_alpha>0){
				on_cutscene = false;
				mask_alpha-=dt;
			}
			else if(cutscene.started&&mask_alpha<1){
				on_cutscene = true;
				mask_alpha+=dt;
			}
				
			if(mask_alpha<0)
				mask_alpha=0;
			else if(mask_alpha>1)
				mask_alpha=1;
			if(cutscene.finished&&mask_alpha==0){
				exists = false;
			}
			context.save();
			context.globalAlpha=mask_alpha;
			drawOnCanvas(rotated_halo, this.x_pos+getWidth(this.imageCode)/2-185-camera.x_pos, this.y_pos-camera.y_pos-175);
			drawOnCanvas(imgData[11], this.x_pos+getWidth(this.imageCode)/2-22-camera.x_pos, this.y_pos-camera.y_pos-24);
			context.restore();
		} else {
			this.draw_particles();
		}
	}
	this.draw_particles = function () {
		for(var i=0;i<particles.length;i++)
			particles[i].draw();
	}
}
function particle1 (x, y) {
	var alpha =0;
	var alpha_increment = -0.05;
	var x_pos;
	var y_pos;
	this.init = function () {
		x_pos = x + Math.floor(Math.random()*50);
		y_pos = y + Math.floor(Math.random()*50);
		alpha = 0;
		alpha_increment = Math.ceil(Math.random()*5+5)/200;
	}
	this.draw = function () {
		alpha+=alpha_increment;
		if(alpha_increment<0&&alpha<=0)
			this.init();
		else if(alpha_increment>0&&alpha>=1){
			alpha=1;
			alpha_increment*= -1;
		}
		light_ctx.globalAlpha = alpha;
		light_ctx.drawImage(imgData[10], x_pos-camera.x_pos, y_pos-camera.y_pos);
	}
}
var lamp = true;
function lightning () {
	//init
	
	//ivan
	light_ctx.globalAlpha = 1;
	light_ctx.drawImage(imgData[18], ivan.x_pos+27-getWidth(18)/2-camera.x_pos, ivan.y_pos+27+ivan.flutter_disp-getHeight(18)/2-camera.y_pos);
	light_ctx.save();
	for(var i=0; i<ivan.particles.length; i++) {
		light_ctx.globalAlpha=ivan.particles[i].alpha;
		light_ctx.drawImage(imgData[19], ivan.particles[i].x_pos-17.5-camera.x_pos, ivan.particles[i].y_pos-17.5-camera.y_pos);
	}
	light_ctx.restore();
	//tari
	if(player.facing=='right'&&lamp)
		light_ctx.drawImage(imgData[20], player.x_pos+player.width-144-camera.x_pos, player.y_pos+player.height/2-144-camera.y_pos);
	else if(lamp)
		light_ctx.drawImage(imgData[20], player.x_pos-144-camera.x_pos, player.y_pos+player.height/2-144-camera.y_pos);
	//ore
	//this.ore.draw_mask();
	//this.ore2.draw_mask();
	//this.ore3.draw_mask();
	//mask
	light_ctx.save();
	light_ctx.globalCompositeOperation='source-out';
	light_ctx.globalAlpha = 0.95;
	
	light_ctx.fillRect(0,0,canvas.width,canvas.height);
	light_ctx.globalCompositeOperation='source-atop';
	/*this.ore.draw_particles();
	this.ore2.draw_particles();
	this.ore3.draw_particles();*/
	light_ctx.restore();
	context.drawImage(light_canvas,0,0);
	light_ctx.clearRect(0,0,960,540);
}
function Viejito (x_pos, y_pos) {
	this.imageCode = 22;
	this.x_pos = x_pos;
	this.y_pos = y_pos;
	var talked = false;
	var finished = false;
	this.draw = function (){
		light_ctx.globalAlpha = 1;
		light_ctx.drawImage(imgData[20], 60 - camera.x_pos, 7480 - camera.y_pos);
		drawOnCanvas(imgData[22], this.x_pos-camera.x_pos, this.y_pos-camera.y_pos);
		if(player.isColliding(this.x_pos, this.y_pos, 1010, 788)&&pressed_control&&!on_cutscene){
			var string = ["¿Qué tal va la recolección muchachito?"];
			if(contador.counter==10){
				string = string.concat("¡Impresionante! Conseguiste 10 piezas de oro en esa mina tan oscura|y llena de secretos, debes ser todo un experto en el arte de la minería.|¡Buen trabajo!",
				"Espera mientras voy a mi taller, que voy a hacer la herramienta|más maciza de la que jamás se haya escrito.");
				talked = true;
			}
			else if(contador.counter>=5){
				string = string.concat("¡Excelente! Con estas " + contador.counter + " piezas de oro es suficiente para hacer una|herramienta, espera mientras voy a mi taller.");
				talked = true;
			}
			else
				string = string.concat("¡Que! ¿Solo " + contador.counter + " piezas de oro…? Con esto no es suficiente para hacer|una herramienta. Ve a buscar un rato más y cuando tengas|por lo menos 5 vuelve a verme.");
			cutscene = new Cutscene([[0, 7300]], [string]);
		}
		if(talked&&contador.counter>=5) {
			if(cutscene.finished){
				fade.out();
				if(fade.state=='idle'){
					audioData[2].play();
					talked=false;
				}
			}
		}
		if(audioData[2].ended){
			fade.in();
			if(fade.state=='idle'&&!finished){
				cutscene = new Cutscene([[0, 7200]], [["El viejo Jiarú te ha entregado un pico de oro."]]);
				finished = true;
			}
			if(cutscene.finished&&finished){
				if(contador.counter==10)
					ending.init("Tlalpujahua", ["Has encontrado todas las piezas de oro", "¡Eres un prodigio de la minería!"]);
				else
					ending.init("Tlalpujahua");
			}
		}
	}
}