// Harbuger menu
$("#hmenu a").on('click', function() {
	$('.bar').toggleClass('animate');
	if ( $("#oer_sidebar").hasClass("hide") ) {
		$("#oer_sidebar").removeClass("hide");
	} else {
		$("#oer_sidebar").addClass("hide");
	}
});


// Controls Show / Hide
$("#p1_toggle").on('click', function() {
	if ( $("#p1").hasClass("show") ) {
		$("#p1").removeClass("down");
		$("#p1_toggle i").removeClass("fa-chevron-circle-down");
		$("#p1_toggle i").addClass("fa-chevron-circle-up");
	} else {
		$("#p1").addClass("down");
		$("#p1_toggle i").removeClass("fa-chevron-circle-up");
		$("#p1_toggle i").addClass("fa-chevron-circle-down");
	}
});


$("#p2_toggle").on('click', function() {
	if ( $("#p2").hasClass("down") ) {
		$("#p2").removeClass("down");
		$("#p2_toggle i").removeClass("fa-chevron-circle-down");
		$("#p2_toggle i").addClass("fa-chevron-circle-up");
	} else {
		$("#p2").addClass("down");
		$("#p2_toggle i").removeClass("fa-chevron-circle-up");
		$("#p2_toggle i").addClass("fa-chevron-circle-down");
	}
});


// Theory Button
$("#btn_theory").on('click', function() {
	if ( $("#oer_theory").hasClass("hide") ) {
		$("#oer_theory").removeClass("hide");
		$("#btn_theory").addClass("active");
		$("#oer_application").addClass("hide");
		$("#btn_application").removeClass("active");
		$("#oer_investigation").addClass("hide");
		$("#btn_investigation").removeClass("active");
	} else {
		$("#oer_theory").addClass("hide");
		$("#btn_theory").removeClass("active");
	}
});


// Application Button
$("#btn_application").on('click', function() {
	if ( $("#oer_application").hasClass("hide") ) {
		$("#oer_theory").addClass("hide");
		$("#btn_theory").removeClass("active");
		$("#oer_application").removeClass("hide");
		$("#btn_application").addClass("active");
		$("#oer_investigation").addClass("hide");
		$("#btn_investigation").removeClass("active");
	} else {
		$("#oer_application").addClass("hide");
		$("#btn_application").removeClass("active");
	}
});


// Investigation Button
$("#btn_investigation").on('click', function() {
	if ( $("#oer_investigation").hasClass("hide") ) {
		$("#oer_theory").addClass("hide");
		$("#btn_theory").removeClass("active");
		$("#oer_application").addClass("hide");
		$("#btn_application").removeClass("active");
		$("#oer_investigation").removeClass("hide");
		$("#btn_investigation").addClass("active");
	} else {
		$("#oer_investigation").addClass("hide");
		$("#btn_investigation").removeClass("active");
	}
});



// Navigation to prev/next applications
$("#oer_app_next").on('click', function() {

});


$("#oer_app_prev").on('click', function() {

});


// Navigation to prev/next investigation
$("#oer_inv_next").on('click', function() {

});

$("#oer_inv_prev").on('click', function() {

});


// Label On/Off
$("#label_switch").on('change', function() {
	if ( $("#label_switch").prop("checked") ) {
		labels.visible = true;
	} else {
		labels.visible = false;
	}
	stage.update();
});


// Empty pipette to beaker A and beaker B
pipette[0].addEventListener("mousedown", function(event) {
    var sX = Math.floor(event.stageX);
    var sY = Math.floor(event.stageY);
    pipette[0].dX = sX - pipette[0].x;
    pipette[0].dY = sY - pipette[0].y;
    pipette[0].cursor = "pointer";
});

pipette[0].addEventListener("pressmove", function(event) {
    var sX = Math.floor(event.stageX);
    var sY = Math.floor(event.stageY);
    pipette[0].x = sX - pipette[0].dX;
    pipette[0].y = sY - pipette[0].dY;
    pipette[0].cursor = "pointer";

    // Go to beaker A
    if (config.current_step == 3) {
    	if (pipette[0].x > beaker1_area.x-config.sticky_px && pipette[0].x < beaker1_area.x+beaker1_area.width+config.sticky_px && pipette[0].y > beaker1_area.y-config.sticky_px && pipette[0].y < beaker1_area.y+beaker1_area.height+config.sticky_px) {
			anim_step = 3.1;
    	}
    }

    // Go to beaker B (dilution)
    if (exercise <= 2 && config.current_step == 3) {
    	if (pipette[0].x > beaker2_area.x-config.sticky_px && pipette[0].x < beaker2_area.x+beaker2_area.width+config.sticky_px && pipette[0].y > beaker2_area.y-config.sticky_px && pipette[0].y < beaker2_area.y+beaker2_area.height+config.sticky_px) {
			anim_step = 3.2;
    	}
    }

    // Go to beaker B (mixure)
    if (exercise >= 3 && config.current_step == 4) {
    	if (pipette[0].x > beaker2_area.x-config.sticky_px && pipette[0].x < beaker2_area.x+beaker2_area.width+config.sticky_px && pipette[0].y > beaker2_area.y-config.sticky_px && pipette[0].y < beaker2_area.y+beaker2_area.height+config.sticky_px) {
			anim_step = 4.4;
    	}
    }

    stage.update();
});



// Full pipette to bottle
pipette[1].addEventListener("mousedown", function(event) {
    var sX = Math.floor(event.stageX);
    var sY = Math.floor(event.stageY);
    pipette[1].dX = sX - pipette[1].x;
    pipette[1].dY = sY - pipette[1].y;
    pipette[1].cursor = "pointer";
});

pipette[1].addEventListener("pressmove", function(event) {
    var sX = Math.floor(event.stageX);
    var sY = Math.floor(event.stageY);
    pipette[1].x = sX - pipette[1].dX;
    pipette[1].y = sY - pipette[1].dY;
    pipette[1].cursor = "pointer";

    // Go to bottle
    if (config.current_step == 3) {
    	if (pipette[1].x > bottle_area.x-config.sticky_px && pipette[1].x < bottle_area.x+bottle_area.width+config.sticky_px && pipette[1].y > bottle_area.y-config.sticky_px && pipette[1].y < bottle_area.y+bottle_area.height+config.sticky_px) {
			anim_step = 3.3;
    	}
    }

    // Go to bottle
    if (config.current_step == 4) {
    	if (pipette[1].x > bottle_area.x-config.sticky_px && pipette[1].x < bottle_area.x+bottle_area.width+config.sticky_px && pipette[1].y > bottle_area.y-config.sticky_px && pipette[1].y < bottle_area.y+bottle_area.height+config.sticky_px) {
			anim_step = 4.5;
    	}
    }

    stage.update();
});




// Full dropper (with water) to bottle
dropper[1].addEventListener("mousedown", function(event) {
    var sX = Math.floor(event.stageX);
    var sY = Math.floor(event.stageY);
    dropper[1].dX = sX - dropper[1].x;
    dropper[1].dY = sY - dropper[1].y;
    dropper[1].cursor = "pointer";
});

dropper[1].addEventListener("pressmove", function(event) {
    var sX = Math.floor(event.stageX);
    var sY = Math.floor(event.stageY);
    dropper[1].x = sX - dropper[1].dX;
    dropper[1].y = sY - dropper[1].dY;
    dropper[1].cursor = "pointer";

    // Go to bottle
    if (config.current_step == 5) {
    	if (dropper[1].x > bottle_area.x-config.sticky_px && dropper[1].x < bottle_area.x+bottle_area.width+config.sticky_px && dropper[1].y > bottle_area.y-config.sticky_px && dropper[1].y < bottle_area.y+bottle_area.height+config.sticky_px) {
			anim_step = 5.1;
    	}
    }

    stage.update();
});


// Water to bottle
water[0].addEventListener("mousedown", function(event) {
    var sX = Math.floor(event.stageX);
    var sY = Math.floor(event.stageY);
    water[0].dX = sX - water[0].x;
    water[0].dY = sY - water[0].y;
    water[0].cursor = "pointer";
});

water[0].addEventListener("pressmove", function(event) {
    var sX = Math.floor(event.stageX);
    var sY = Math.floor(event.stageY);
    water[0].x = sX - water[0].dX;
    water[0].y = sY - water[0].dY;
    water[0].cursor = "pointer";

    // Go to bottle
    if (config.current_step == 4) {
    	if (water[0].x > bottle_area.x-config.sticky_px && water[0].x < bottle_area.x+bottle_area.width+config.sticky_px && water[0].y > bottle_area.y-config.sticky_px && water[0].y < bottle_area.y+bottle_area.height+config.sticky_px) {
			anim_step = 4.1;
    	}
    }

    stage.update();
});




