(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,1259,638);


(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: '13291',
			title: 'Kliknij na magiczną kulę, na której pojawiają się liczby od 5 do 25 i przesuń swój pionek po planszy o tyle pól, jaką pokazała kula liczbę. Jeśli stajesz na polu z bałwankiem – tracisz dwie kolejki. Jeśli stajesz na polu z  limbą – przesuwasz się o 2 pola do przodu. Jeśli stajesz na polu z liczbą, odejmij od niej ilość oczek o które się przesuwałeś i zapisz działanie w zeszycie oraz oblicz je.',
			type: 'magicball',
			container: this,
			container: this,
			prefix: 'drag_',
			prefix2: 'drop_',	
			players: {min: 2, max: 4},
			numbers: {min: 5, max: 25},
			alert: 'Wpisz liczbę graczy. Gra przeznaczone jest dla 2 - 4 graczy',
			alpha: 0,
			alpha2: 0,	
			range: 20,
			results: {meta: 61, shift: 0},
				
			endsound: 'ssBrawa', exerciseAfterInit: function (config) {		
			},
			exerciseBeforeFinish: function (config) {	
			},
			exerciseExtraCheck: function (config) {		
			},
			/*
			exerciseCustomPosition: function(obj) {
				return obj.position + 9 - obj.parent.num;
			},
			*/
			exerciseExtraCondition: function (obj) {		
				if(
					obj.position === 4 ||
					obj.position === 13 ||
					obj.position === 21 ||
					obj.position === 30 ||
					obj.position === 38 ||
					obj.position === 46 ||
					obj.position === 54
				) {
					moveSkip(this, obj, 2, 'Tracisz 2 kolejki!')
				}	
						
				if(
					obj.position === 8 ||
					obj.position === 17 ||
					obj.position === 26 ||
					obj.position === 34 ||
					obj.position === 43 ||
					obj.position === 50 ||
					obj.position === 58
				) {
					moveForward(this, obj, 2, 'Przesuwasz się o 2 pola do przodu!')
				}
				
			
			},
			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.drop_61 = new lib.dropMc();
	this.drop_61.setTransform(400,145,1,1,0,0,0,30,30);

	this.drop_60 = new lib.dropMc();
	this.drop_60.setTransform(460,148,1,1,0,0,0,30,30);

	this.drop_59 = new lib.dropMc();
	this.drop_59.setTransform(519,148,1,1,0,0,0,30,30);

	this.drop_58 = new lib.dropMc();
	this.drop_58.setTransform(579,150,1,1,0,0,0,30,30);

	this.drop_57 = new lib.dropMc();
	this.drop_57.setTransform(620,105,1,1,0,0,0,30,30);

	this.drop_56 = new lib.dropMc();
	this.drop_56.setTransform(679,88,1,1,0,0,0,30,30);

	this.drop_55 = new lib.dropMc();
	this.drop_55.setTransform(737,79,1,1,0,0,0,30,30);

	this.drop_54 = new lib.dropMc();
	this.drop_54.setTransform(789,112,1,1,0,0,0,30,30);

	this.drop_53 = new lib.dropMc();
	this.drop_53.setTransform(847,94,1,1,0,0,0,30,30);

	this.drop_52 = new lib.dropMc();
	this.drop_52.setTransform(907,94,1,1,0,0,0,30,30);

	this.drop_51 = new lib.dropMc();
	this.drop_51.setTransform(967,94,1,1,0,0,0,30,30);

	this.drop_50 = new lib.dropMc();
	this.drop_50.setTransform(1028,100,1,1,0,0,0,30,30);

	this.drop_49 = new lib.dropMc();
	this.drop_49.setTransform(1088,100,1,1,0,0,0,30,30);

	this.drop_48 = new lib.dropMc();
	this.drop_48.setTransform(1139,130,1,1,0,0,0,30,30);

	this.drop_47 = new lib.dropMc();
	this.drop_47.setTransform(1168,184,1,1,0,0,0,30,30);

	this.drop_46 = new lib.dropMc();
	this.drop_46.setTransform(1148,240,1,1,0,0,0,30,30);

	this.drop_45 = new lib.dropMc();
	this.drop_45.setTransform(1094,271,1,1,0,0,0,30,30);

	this.drop_44 = new lib.dropMc();
	this.drop_44.setTransform(1036,262,1,1,0,0,0,30,30);

	this.drop_43 = new lib.dropMc();
	this.drop_43.setTransform(987,227,1,1,0,0,0,30,30);

	this.drop_42 = new lib.dropMc();
	this.drop_42.setTransform(926,232,1,1,0,0,0,30,30);

	this.drop_41 = new lib.dropMc();
	this.drop_41.setTransform(898,286,1,1,0,0,0,30,30);

	this.drop_40 = new lib.dropMc();
	this.drop_40.setTransform(845,311,1,1,0,0,0,30,30);

	this.drop_39 = new lib.dropMc();
	this.drop_39.setTransform(785,301,1,1,0,0,0,30,30);

	this.drop_38 = new lib.dropMc();
	this.drop_38.setTransform(737,264,1,1,0,0,0,30,30);

	this.drop_37 = new lib.dropMc();
	this.drop_37.setTransform(680,245,1,1,0,0,0,30,30);

	this.drop_36 = new lib.dropMc();
	this.drop_36.setTransform(620,242,1,1,0,0,0,30,30);

	this.drop_35 = new lib.dropMc();
	this.drop_35.setTransform(565,266,1,1,0,0,0,30,30);

	this.drop_34 = new lib.dropMc();
	this.drop_34.setTransform(549,324,1,1,0,0,0,30,30);

	this.drop_33 = new lib.dropMc();
	this.drop_33.setTransform(489,340,1,1,0,0,0,30,30);

	this.drop_32 = new lib.dropMc();
	this.drop_32.setTransform(429,332,1,1,0,0,0,30,30);

	this.drop_31 = new lib.dropMc();
	this.drop_31.setTransform(380,297,1,1,0,0,0,30,30);

	this.drop_30 = new lib.dropMc();
	this.drop_30.setTransform(347,246,1,1,0,0,0,30,30);

	this.drop_29 = new lib.dropMc();
	this.drop_29.setTransform(287,226,1,1,0,0,0,30,30);

	this.drop_28 = new lib.dropMc();
	this.drop_28.setTransform(226,233,1,1,0,0,0,30,30);

	this.drop_27 = new lib.dropMc();
	this.drop_27.setTransform(184,275,1,1,0,0,0,30,30);

	this.drop_26 = new lib.dropMc();
	this.drop_26.setTransform(143,323,1,1,0,0,0,30,30);

	this.drop_25 = new lib.dropMc();
	this.drop_25.setTransform(154,384,1,1,0,0,0,30,30);

	this.drop_24 = new lib.dropMc();
	this.drop_24.setTransform(183,442,1,1,0,0,0,30,30);

	this.drop_23 = new lib.dropMc();
	this.drop_23.setTransform(236,472,1,1,0,0,0,30,30);

	this.drop_22 = new lib.dropMc();
	this.drop_22.setTransform(289,501,1,1,0,0,0,30,30);

	this.drop_21 = new lib.dropMc();
	this.drop_21.setTransform(350,504,1,1,0,0,0,30,30);

	this.drop_20 = new lib.dropMc();
	this.drop_20.setTransform(379,448,1,1,0,0,0,30,30);

	this.drop_19 = new lib.dropMc();
	this.drop_19.setTransform(439,452,1,1,0,0,0,30,30);

	this.drop_18 = new lib.dropMc();
	this.drop_18.setTransform(494,479,1,1,0,0,0,30,30);

	this.drop_17 = new lib.dropMc();
	this.drop_17.setTransform(553,496,1,1,0,0,0,30,30);

	this.drop_16 = new lib.dropMc();
	this.drop_16.setTransform(549,556,1,1,0,0,0,30,30);

	this.drop_15 = new lib.dropMc();
	this.drop_15.setTransform(599,593,1,1,0,0,0,30,30);

	this.drop_14 = new lib.dropMc();
	this.drop_14.setTransform(659,585,1,1,0,0,0,30,30);

	this.drop_13 = new lib.dropMc();
	this.drop_13.setTransform(719,565,1,1,0,0,0,30,30);

	this.drop_12 = new lib.dropMc();
	this.drop_12.setTransform(754,515,1,1,0,0,0,30,30);

	this.drop_11 = new lib.dropMc();
	this.drop_11.setTransform(797,472,1,1,0,0,0,30,30);

	this.drop_10 = new lib.dropMc();
	this.drop_10.setTransform(848,441,1,1,0,0,0,30,30);

	this.drop_9 = new lib.dropMc();
	this.drop_9.setTransform(905,421,1,1,0,0,0,30,30);

	this.drop_8 = new lib.dropMc();
	this.drop_8.setTransform(958,392,1,1,0,0,0,30,30);

	this.drop_7 = new lib.dropMc();
	this.drop_7.setTransform(1021,388,1,1,0,0,0,30,30);

	this.drop_6 = new lib.dropMc();
	this.drop_6.setTransform(1078,411,1,1,0,0,0,30,30);

	this.drop_5 = new lib.dropMc();
	this.drop_5.setTransform(1094,470,1,1,0,0,0,30,30);

	this.drop_4 = new lib.dropMc();
	this.drop_4.setTransform(1084,530,1,1,0,0,0,30,30);

	this.drop_3 = new lib.dropMc();
	this.drop_3.setTransform(1040,572,1,1,0,0,0,30,30);

	this.drop_2 = new lib.dropMc();
	this.drop_2.setTransform(992,607,1,1,0,0,0,30,30);

	this.drop_1 = new lib.dropMc();
	this.drop_1.setTransform(935,626,1,1,0,0,0,30,30);

	this.drag_4 = new lib.p4();
	this.drag_4.setTransform(885.6,635,1,1,0,0,0,18.6,50);

	this.drag_3 = new lib.p3();
	this.drag_3.setTransform(860.4,635,1,1,0,0,0,18.6,50);

	this.drag_2 = new lib.p2();
	this.drag_2.setTransform(876.6,620.5,1,1,0,0,0,18.6,50);

	this.drag_1 = new lib.p1();
	this.drag_1.setTransform(851.4,621.5,1,1,0,0,0,18.6,50);

	this.magicball = new lib.ballMc();
	this.magicball.setTransform(666.1,388.9);

	this.timeline.addTween(cjs.Tween.get({}).to({state:[{t:this.magicball},{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.drop_40},{t:this.drop_41},{t:this.drop_42},{t:this.drop_43},{t:this.drop_44},{t:this.drop_45},{t:this.drop_46},{t:this.drop_47},{t:this.drop_48},{t:this.drop_49},{t:this.drop_50},{t:this.drop_51},{t:this.drop_52},{t:this.drop_53},{t:this.drop_54},{t:this.drop_55},{t:this.drop_56},{t:this.drop_57},{t:this.drop_58},{t:this.drop_59},{t:this.drop_60},{t:this.drop_61}]}).wait(1));

	// bg
	this.instance = new lib.Bitmap1();
	this.instance.setTransform(10.4,37.4);

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

}).prototype = p = new cjs.MovieClip();
p.nominalBounds = rect = new cjs.Rectangle(10.4,37.4,1259,638);
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(650.4,397.4,1259,638);
p.frameBounds = [rect];

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