(function (lib, img, cjs) {

var p; // shortcut to reference prototypes
var rect; // used to reference frame bounds

// library properties:
lib.properties = {
	width: 1280,
	height: 720,
	fps: 30,
	color: "#FFFFFF",
	manifest: [
		{src:"images/Bitmap1.png", id:"Bitmap1"},
		{src:"images/Bitmap2.png", id:"Bitmap2"},
		{src:"images/Bitmap3.png", id:"Bitmap3"},
		{src:"images/Bitmap4.png", id:"Bitmap4"},
		{src:"images/Bitmap5.png", id:"Bitmap5"},
		{src:"images/Bitmap6.png", id:"Bitmap6"},
		{src:"images/gfx_ball.png", id:"gfx_ball"},
		{src:"images/gfx_ball_sh.png", id:"gfx_ball_sh"}
	]
};



// symbols:



(lib.Bitmap1 = function() {
	this.initialize(img.Bitmap1);
}).prototype = p = new cjs.Bitmap();
p.nominalBounds = new cjs.Rectangle(0,0,1182,533);


(lib.Bitmap2 = function() {
	this.initialize(img.Bitmap2);
}).prototype = p = new cjs.Bitmap();
p.nominalBounds = new cjs.Rectangle(0,0,38,71);


(lib.Bitmap3 = function() {
	this.initialize(img.Bitmap3);
}).prototype = p = new cjs.Bitmap();
p.nominalBounds = new cjs.Rectangle(0,0,38,71);


(lib.Bitmap4 = function() {
	this.initialize(img.Bitmap4);
}).prototype = p = new cjs.Bitmap();
p.nominalBounds = new cjs.Rectangle(0,0,38,71);


(lib.Bitmap5 = function() {
	this.initialize(img.Bitmap5);
}).prototype = p = new cjs.Bitmap();
p.nominalBounds = new cjs.Rectangle(0,0,38,71);


(lib.Bitmap6 = function() {
	this.initialize(img.Bitmap6);
}).prototype = p = new cjs.Bitmap();
p.nominalBounds = new cjs.Rectangle(0,0,60,60);


(lib.gfx_ball = function() {
	this.initialize(img.gfx_ball);
}).prototype = p = new cjs.Bitmap();
p.nominalBounds = new cjs.Rectangle(0,0,135,135);


(lib.gfx_ball_sh = function() {
	this.initialize(img.gfx_ball_sh);
}).prototype = p = new cjs.Bitmap();
p.nominalBounds = new cjs.Rectangle(0,0,135,29);


(lib.p4 = function() {
	this.initialize();

	// Layer 2
	this.instance = new lib.Bitmap5();

	this.addChild(this.instance);
}).prototype = p = new cjs.Container();
p.nominalBounds = rect = new cjs.Rectangle(0,0,38,71);
p.frameBounds = [rect];


(lib.p3 = function() {
	this.initialize();

	// Layer 2
	this.instance = new lib.Bitmap4();

	this.addChild(this.instance);
}).prototype = p = new cjs.Container();
p.nominalBounds = rect = new cjs.Rectangle(0,0,38,71);
p.frameBounds = [rect];


(lib.p2 = function() {
	this.initialize();

	// Layer 2
	this.instance = new lib.Bitmap3();

	this.addChild(this.instance);
}).prototype = p = new cjs.Container();
p.nominalBounds = rect = new cjs.Rectangle(0,0,38,71);
p.frameBounds = [rect];


(lib.p1 = function() {
	this.initialize();

	// Layer 2
	this.instance = new lib.Bitmap2();

	this.addChild(this.instance);
}).prototype = p = new cjs.Container();
p.nominalBounds = rect = new cjs.Rectangle(0,0,38,71);
p.frameBounds = [rect];


(lib.dropIn = function() {
	this.initialize();

	// Layer 1
	this.instance = new lib.Bitmap6();

	this.addChild(this.instance);
}).prototype = p = new cjs.Container();
p.nominalBounds = rect = new cjs.Rectangle(0,0,60,60);
p.frameBounds = [rect];


(lib.ballSh = function() {
	this.initialize();

	// Layer 1
	this.instance = new lib.gfx_ball_sh();

	this.addChild(this.instance);
}).prototype = p = new cjs.Container();
p.nominalBounds = rect = new cjs.Rectangle(0,0,135,29);
p.frameBounds = [rect];


(lib.ball = function() {
	this.initialize();

	// Layer 2
	this.num = new cjs.Text("", "bold 48px 'Comic Sans MS'");
	this.num.name = "num";
	this.num.textAlign = "center";
	this.num.lineHeight = 50;
	this.num.lineWidth = 100;
	this.num.setTransform(65.5,30.6);

	// Layer 1
	this.instance = new lib.gfx_ball();

	this.addChild(this.instance,this.num);
}).prototype = p = new cjs.Container();
p.nominalBounds = rect = new cjs.Rectangle(0,0,135,135);
p.frameBounds = [rect];


(lib.dropMc = function() {
	this.initialize();

	// Layer 1
	this.instance = new lib.dropIn();
	this.instance.setTransform(30,30,1,1,0,0,0,30,30);
	this.instance.alpha = 0.5;

	this.addChild(this.instance);
}).prototype = p = new cjs.Container();
p.nominalBounds = rect = new cjs.Rectangle(0,0,60,60);
p.frameBounds = [rect];


(lib.ballMc = function() {
	this.initialize();

	// ball
	this.ball = new lib.ball();
	this.ball.setTransform(-0.1,0.3,1,1,0,0,0,67.5,69);

	// sh
	this.sh = new lib.ballSh();
	this.sh.setTransform(0,62.5,1,1,0,0,0,67.5,14.5);

	this.addChild(this.sh,this.ball);
}).prototype = p = new cjs.Container();
p.nominalBounds = rect = new cjs.Rectangle(-67.6,-68.7,135.2,145.8);
p.frameBounds = [rect];


(lib.exerciseContainer = function(mode,startPosition,loop) {
if (loop == null) { loop = false; }	this.initialize(mode,startPosition,loop,{});

	// timeline functions:
	this.frame_0 = function() {
		/* Magic Ball */
		var config = {
			id: '33486',
			title: 'Kliknij obrazki magicznych kul. Teraz przesuń pionek o tyle pól ile razy mniejsza liczba wypadła na kuli drugiej niż na kuli pierwszej. Jeśli wynik jest dwucyfrowy przesuwasz się tylko o liczbę pól równą liczbie dziesiątek. Kto pierwszy dotrze do komputera wygrywa.',
			type: 'magicball',
			container: this,
			container: this,
			prefix: 'drag_',
			prefix2: 'drop_',	
			players: {min: 2, max: 4},
			numbers: {min: 5, max: 25},
			results: {meta: 39, shift: 0},
			alert: 'Wpisz liczbę graczy. Gra przeznaczone jest dla 2 - 4 graczy',
			alpha: 0,
			alpha2: 0,	
			range: 20,
				
			endsound: 'ssBrawa', exerciseAfterInit: function (container) {
				container['magicball1'].randoms = [30,60,90];
				container['magicball2'].randoms = [2,3,5,6,10,15,30];
			},
			exerciseBeforeFinish: function (container) {
				
			},
			exerciseExtraCheck: function (config) {		
			},
			
			exerciseCustomPosition: function(obj) {
				var nextPos = parseInt(obj.parent.num1) / parseInt(obj.parent.num2);
				if(nextPos > 9) {
					nextPos = parseInt(nextPos.toString()[0]);
				}
				//console.log(nextPos);
				return obj.position + nextPos;
			},
			/*
			exerciseExtraCondition: function (obj) {		
				
				if(obj.position === num) {
					moveSkip(this, obj, 2, '')
				}		
						
				if(obj.position === num) {
					moveForward(this, obj, 1, '')
				}
				
				if(obj.position === num) {
					moveBack(this, obj, 2, '')
				}
			
			},
			exerciseExtraCurrentPlayer: function () {
				//Check extra draw		
				//extraDraw(this);	
				
				
				return skipPlayer (this);		
				
			}
			*/
		}
		
		exerciseOnInit(config);
		
		
		/* Custom functions */
		
		function moveBack(config, obj, backMove, msg) {
			var dropIndex = obj.position - backMove;
			var dropNext = config.container[config.prefix2+dropIndex];
			obj.position = obj.position - backMove;
			obj.orgy = dropNext.y;
			showMessage(msg);
			TweenMax.to(obj, 0.5, {x:dropNext.x, y: dropNext.y, ease: Quad.easeOut,
				onComplete: function() {
					this.target.orgx = dropNext.x;
					this.target.orgy = dropNext.y;
				}
			});	
		}
		
		function moveForward(config, obj, forwardMove, msg) {
			var dropIndex = obj.position + forwardMove;
			var dropNext = config.container[config.prefix2+dropIndex];
			obj.position = obj.position + forwardMove;
			obj.orgx = dropNext.x;
			obj.orgy = dropNext.y;
			showMessage(msg);
			TweenMax.to(obj, 0.5, {x:dropNext.x, y: dropNext.y, ease: Quad.easeOut,
				onComplete: function() {
					this.target.orgx = dropNext.x;
					this.target.orgy = dropNext.y;
				}
			});	
		}
		
		function moveSkip(config, obj, skipNum, msg) {
			obj.skip = skipNum;
			showMessage(msg);		
		}
		
		function extraDraw(config) {
			for (var playerName in config.container) {
				if (playerName.indexOf(config.prefix) > -1) {
					var playerPawn = config.container[playerName];
					if (playerPawn.player === config.container.currentPlayer) {
						if (playerPawn.extradraw === true) {
							playerPawn.extradraw = false;
							isExtraDraw = true;
							return config.container.currentPlayer;
							break;
						}
					}
				}
			}
		}
		
		function skipPlayer (config) {	
			config.container.currentPlayer++;
				
			if (config.container.currentPlayer > config.container.playerNum)
				config.container.currentPlayer = 1;
		
			for (var playerName in config.container) {
				if (playerName.indexOf(config.prefix) > -1) {
					var playerPawn = config.container[playerName];
					if (playerPawn.player === config.container.currentPlayer) {
						if(typeof playerPawn.skip === 'number' && parseInt(playerPawn.skip) > 0) {						
							playerPawn.skip = playerPawn.skip - 1;
							return config.container.currentPlayer+1;
						}
						else {						
							playerPawn.skip = 0;						
						}
						
					}
				}
			}
			
			return config.container.currentPlayer;
			
		}
		
		this.stop();
		
		/* Help */
		
		/* 
		id - Id cwiczenia
		title - Tytul cwiczenia
		type - Typ Cwiczenia
		contanier - Kontener cwiczenia
		groups - Lista grup oraz przypisane do nich identyfikatory (unikatowa liczba) obiektow bez prefixow
		prefix - Prefixy w nazwach obiektow
		results - Rozwiazanie jako tablica identyfikatorow. Znak '|' definuje alternatywe, a '&' oznacza sume.	
		Przyklad:
		Cwiczenie typu sort.
		Odpowiedzi: [5,2,1,4,5] - tablica z ulozonymi w odpowiedniej kolejnisci identyfikatorami obiektow sortowanych.
		Cwiczenie typu drag.
		Odpowiedzi: [5,1|3,2&4] - tablica z id obiektow przeciaganych lub grup. W tym wariancie kazdy kolejny element z indexem 'i' w tablicy odpowiada targetowi o nazwie 'prefix+i'.
		np. prawidlowa odpowiedzia dla drop_1 jest obiekt drag_5, dla drop_2 obiekt drag_1 lub drag_3, dla drop_3 obiekt drag_2 oraz drag_4.
		range - Zakres dociagania
		alpha - Przezroczystosc targetu
		alpha2 - Przezroczystosc targetu po najechaniu
		scale - Skalowanie obiektu po upuszczeniu
		zindex - Warstwa obiektu
		*/
	}

	// actions tween:
	this.timeline.addTween(cjs.Tween.get(this).call(this.frame_0).wait(1));

	// content
	this.magicball1 = new lib.ballMc();
	this.magicball1.setTransform(515.1,569.9);

	this.drop_39 = new lib.dropMc();
	this.drop_39.setTransform(947.4,550.9,1,1,0,0,0,30,30);

	this.drop_38 = new lib.dropMc();
	this.drop_38.setTransform(1042.4,522.9,1,1,0,0,0,30,30);

	this.drop_37 = new lib.dropMc();
	this.drop_37.setTransform(1091.4,501.9,1,1,0,0,0,30,30);

	this.drop_36 = new lib.dropMc();
	this.drop_36.setTransform(1131.4,470.9,1,1,0,0,0,30,30);

	this.drop_35 = new lib.dropMc();
	this.drop_35.setTransform(1164.3,437.9,1,1,0,0,0,30,30);

	this.drop_34 = new lib.dropMc();
	this.drop_34.setTransform(1186.3,398.9,1,1,0,0,0,30,30);

	this.drop_33 = new lib.dropMc();
	this.drop_33.setTransform(1195.3,352.9,1,1,0,0,0,30,30);

	this.drop_32 = new lib.dropMc();
	this.drop_32.setTransform(1190.3,306.9,1,1,0,0,0,30,30);

	this.drop_31 = new lib.dropMc();
	this.drop_31.setTransform(1176.3,259.9,1,1,0,0,0,30,30);

	this.drop_30 = new lib.dropMc();
	this.drop_30.setTransform(1148.3,216.9,1,1,0,0,0,30,30);

	this.drop_29 = new lib.dropMc();
	this.drop_29.setTransform(1112.3,181.9,1,1,0,0,0,30,30);

	this.drop_28 = new lib.dropMc();
	this.drop_28.setTransform(1079.3,164.9,1,1,0,0,0,30,30);

	this.drop_27 = new lib.dropMc();
	this.drop_27.setTransform(1053.3,149.9,1,1,0,0,0,30,30);

	this.drop_26 = new lib.dropMc();
	this.drop_26.setTransform(1028.3,137.9,1,1,0,0,0,30,30);

	this.drop_25 = new lib.dropMc();
	this.drop_25.setTransform(1001.3,128.9,1,1,0,0,0,30,30);

	this.drop_24 = new lib.dropMc();
	this.drop_24.setTransform(970.3,116.9,1,1,0,0,0,30,30);

	this.drop_23 = new lib.dropMc();
	this.drop_23.setTransform(940.3,116.9,1,1,0,0,0,30,30);

	this.drop_22 = new lib.dropMc();
	this.drop_22.setTransform(899.8,116.9,1,1,0,0,0,30,30);

	this.drop_21 = new lib.dropMc();
	this.drop_21.setTransform(869.3,120.9,1,1,0,0,0,30,30);

	this.drop_20 = new lib.dropMc();
	this.drop_20.setTransform(826.4,125.9,1,1,0,0,0,30,30);

	this.drop_19 = new lib.dropMc();
	this.drop_19.setTransform(785.4,141,1,1,0,0,0,30,30);

	this.drop_18 = new lib.dropMc();
	this.drop_18.setTransform(753.6,160.9,1,1,0,0,0,30,30);

	this.drop_17 = new lib.dropMc();
	this.drop_17.setTransform(724.4,180.9,1,1,0,0,0,30,30);

	this.drop_16 = new lib.dropMc();
	this.drop_16.setTransform(703.4,201,1,1,0,0,0,30,30);

	this.drop_15 = new lib.dropMc();
	this.drop_15.setTransform(684.4,224.9,1,1,0,0,0,30,30);

	this.drop_14 = new lib.dropMc();
	this.drop_14.setTransform(657.4,245,1,1,0,0,0,30,30);

	this.drop_13 = new lib.dropMc();
	this.drop_13.setTransform(627.4,270,1,1,0,0,0,30,30);

	this.drop_12 = new lib.dropMc();
	this.drop_12.setTransform(586.4,284.9,1,1,0,0,0,30,30);

	this.drop_11 = new lib.dropMc();
	this.drop_11.setTransform(533,296,1,1,0,0,0,30,30);

	this.drop_10 = new lib.dropMc();
	this.drop_10.setTransform(477,301,1,1,0,0,0,30,30);

	this.drop_9 = new lib.dropMc();
	this.drop_9.setTransform(433,305,1,1,0,0,0,30,30);

	this.drop_8 = new lib.dropMc();
	this.drop_8.setTransform(395,313,1,1,0,0,0,30,30);

	this.drop_7 = new lib.dropMc();
	this.drop_7.setTransform(358,325,1,1,0,0,0,30,30);

	this.drop_6 = new lib.dropMc();
	this.drop_6.setTransform(318,338,1,1,0,0,0,30,30);

	this.drop_5 = new lib.dropMc();
	this.drop_5.setTransform(281,353,1,1,0,0,0,30,30);

	this.drop_4 = new lib.dropMc();
	this.drop_4.setTransform(243,372,1,1,0,0,0,30,30);

	this.drop_3 = new lib.dropMc();
	this.drop_3.setTransform(212,398,1,1,0,0,0,30,30);

	this.drop_2 = new lib.dropMc();
	this.drop_2.setTransform(182,428,1,1,0,0,0,30,30);

	this.drop_1 = new lib.dropMc();
	this.drop_1.setTransform(152,458,1,1,0,0,0,30,30);

	this.drag_4 = new lib.p4();
	this.drag_4.setTransform(122.6,584,1,1,0,0,0,26.6,49);

	this.drag_3 = new lib.p3();
	this.drag_3.setTransform(79.6,558,1,1,0,0,0,8.6,49);

	this.drag_2 = new lib.p2();
	this.drag_2.setTransform(70.5,529,1,1,0,0,0,22.6,50);

	this.drag_1 = new lib.p1();
	this.drag_1.setTransform(38.5,498,1,1,0,0,0,13.6,49);

	this.magicball2 = new lib.ballMc();
	this.magicball2.setTransform(675.1,569.9);

	this.timeline.addTween(cjs.Tween.get({}).to({state:[{t:this.magicball2},{t:this.drag_1},{t:this.drag_2},{t:this.drag_3},{t:this.drag_4},{t:this.drop_1},{t:this.drop_2},{t:this.drop_3},{t:this.drop_4},{t:this.drop_5},{t:this.drop_6},{t:this.drop_7},{t:this.drop_8},{t:this.drop_9},{t:this.drop_10},{t:this.drop_11},{t:this.drop_12},{t:this.drop_13},{t:this.drop_14},{t:this.drop_15},{t:this.drop_16},{t:this.drop_17},{t:this.drop_18},{t:this.drop_19},{t:this.drop_20},{t:this.drop_21},{t:this.drop_22},{t:this.drop_23},{t:this.drop_24},{t:this.drop_25},{t:this.drop_26},{t:this.drop_27},{t:this.drop_28},{t:this.drop_29},{t:this.drop_30},{t:this.drop_31},{t:this.drop_32},{t:this.drop_33},{t:this.drop_34},{t:this.drop_35},{t:this.drop_36},{t:this.drop_37},{t:this.drop_38},{t:this.drop_39},{t:this.magicball1}]}).wait(1));

	// bg
	this.instance = new lib.Bitmap1();
	this.instance.setTransform(60.4,67.4);

	this.timeline.addTween(cjs.Tween.get(this.instance).wait(1));

}).prototype = p = new cjs.MovieClip();
p.nominalBounds = rect = new cjs.Rectangle(24.9,67.4,1217.5,579.5);
p.frameBounds = [rect];


// stage content:
(lib.index = function() {
	this.initialize();

	// exercise
	this.container = new lib.exerciseContainer();
	this.container.setTransform(916.5,389,1,1,0,0,0,916.5,389);

	this.addChild(this.container);
}).prototype = p = new cjs.Container();
p.nominalBounds = rect = new cjs.Rectangle(664.9,427.4,1217.5,579.5);
p.frameBounds = [rect];

})(lib = lib||{}, images = images||{}, createjs = createjs||{});
var lib, images, createjs;