/* --------------------------------------------------
Author: Anastasios Pallas / tcpallas@gmail.com
Version 1.0
Last Update: 2024-07-08
-------------------------------------------------- */

// Initialize Canvas
var canvas = document.getElementById("canvas");
var context = canvas.getContext('2d');
var stage = new createjs.Stage("canvas");
var childIndex = -1;

// Enable Mouseover on stage
stage.enableMouseOver();

// Enable Drag and Drop on mobile
createjs.Touch.enable(stage);

// Orthostatis (8 frames)
var orthostatis_img = new Array();
var orthostatis = new Array();
for (let i=0; i <= 7; i++) {
	orthostatis_img[i] = new Image();
	orthostatis_img[i].src = 'images/izima/base-and-tube-' + i + '.png';

	orthostatis[i] = new createjs.Bitmap(orthostatis_img[i]);
	orthostatis[i].scaleX = orthostatis[i].scaleY = 1;
	orthostatis[i].x = config.center_x + 150;
	orthostatis[i].y = config.center_y - 70;

	orthostatis_img[i].onload = function () {
		stage.addChild(orthostatis[i]);
		stage.setChildIndex(orthostatis[i], childIndex++);
		stage.update();
	}
}


// beaker KI (3 frames)
var beaker_ki_img = new Array();
var beaker_ki = new Array();
for (let i=0; i <= 2; i++) {
	beaker_ki_img[i] = new Image();
	beaker_ki_img[i].src = 'images/izima/beaker-' + i + '.png';

	beaker_ki[i] = new createjs.Bitmap(beaker_ki_img[i]);
	beaker_ki[i].scaleX = beaker_ki[i].scaleY = 1;
	beaker_ki[i].width = 61;
	beaker_ki[i].height = 84;
	beaker_ki[i].regX = 30;
	beaker_ki[i].regY = 42;
	beaker_ki[i].rotation = 0;
	beaker_ki[i].x = config.center_x - 190;
	beaker_ki[i].y = config.center_y + 142;

	beaker_ki_img[i].onload = function () {
		stage.addChild(beaker_ki[i]);
		stage.setChildIndex(beaker_ki[i], childIndex++);
		stage.update();
	}
}


// beaker Pb(NO3)2 (3 frames)
var beaker_pb_img = new Array();
var beaker_pb = new Array();
for (let i=0; i <= 2; i++) {
	beaker_pb_img[i] = new Image();
	beaker_pb_img[i].src = 'images/izima/beaker-' + i + '.png';

	beaker_pb[i] = new createjs.Bitmap(beaker_pb_img[i]);
	beaker_pb[i].scaleX = beaker_pb[i].scaleY = 1;
	beaker_pb[i].width = 61;
	beaker_pb[i].height = 84;
	beaker_pb[i].regX = 30;
	beaker_pb[i].regY = 42;
	beaker_pb[i].rotation = 0;
	beaker_pb[i].x = config.center_x - 50;
	beaker_pb[i].y = config.center_y + 142;

	beaker_pb_img[i].onload = function () {
		stage.addChild(beaker_pb[i]);
		stage.setChildIndex(beaker_pb[i], childIndex++);
		stage.update();
	}
}

// Tube area for beakers
tube_area = new createjs.Shape();
tube_area.graphics.beginFill(config.click_area_color).drawRect(0, 0, 60, 80);
tube_area.x = config.center_x + 140;
tube_area.y = config.center_y - 120;
tube_area.width = 80;
tube_area.height = 80;
stage.addChild(tube_area);
stage.setChildIndex(tube_area, childIndex++);
stage.update();


// Labels
var labels_img = new Image();
labels_img.src = 'images/izima/labels.png';

var labels = new createjs.Bitmap(labels_img);
labels.scaleX = labels.scaleY = 1;
labels.x = config.center_x - 230;
labels.y = config.center_y - 0;

labels_img.onload = function () {
	stage.addChild(labels);
	stage.setChildIndex(labels, childIndex++);
	stage.update();
}

