var level;
var mouseX=0,mouseY=0,timeTicker=0,pauseAnim1=8,pauseAnim2=36,markerAnimPtr=0;
var levels=[0xe0,0xe0,0xe0,0x00,0x07,0x07,0x07,0x3c,0xe7,0xe7,0xe7,0x00,0xe7,0xe7,0xe7,0x3c,0x00,0x00,0x24,0x24,0x24,0x00,0x00,0x3c,0xc3,0xc3,0xe7,0xe7,0xe7,0xc3,0xc3,0x3c,0xe7,0xe7,0x00,0xe7,0x00,0xe7,0xe7,0x3c,0x00,0x24,0x24,0x00,0x24,0x24,0x00,0x3c,0xc3,0xc3,0xe7,0x24,0xe7,0xc3,0xc3,0x3c,0xe7,0x00,0xa5,0xa5,0xa5,0x00,0xe7,0x3c,0xc3,0xc3,0x24,0xc3,0x24,0xc3,0xc3,0x3c,0x00,0x7e,0x5a,0x24,0x5a,0x7e,0x00,0x3c,0xe0,0x90,0x90,0x7e,0x09,0x09,0x07,0x32,0x7e,0x7e,0xc3,0xc3,0xc3,0xe7,0xe7,0x32,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0x32,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x32,0x7e,0x7e,0xbd,0xc3,0xbd,0x7e,0x7e,0x32,0x7e,0x7e,0x99,0xe7,0x99,0x7e,0x7e,0x32,0x07,0x07,0x23,0x24,0xc4,0xe0,0xe0,0x32,0x00,0x70,0x97,0x99,0xe9,0x0e,0x00,0x32,0x6b,0x6b,0xab,0xdc,0xab,0x6b,0x6b,0x32,0xab,0xab,0x00,0x00,0x00,0xd5,0xd5,0x32,0x24,0x24,0xe7,0x00,0xe7,0x24,0x24,0x28,0xc0,0xc0,0x99,0x99,0x99,0x03,0x03,0x28,0x23,0x23,0xc4,0x24,0x23,0xc4,0xc4,0x28,0xc3,0xbd,0x7e,0x00,0x7e,0xbd,0xc3,0x28,0x24,0x24,0xc3,0x24,0xc3,0x24,0x24,0x28,0xe4,0xe4,0x38,0x00,0x1c,0x27,0x27,0x28,0x24,0x24,0x99,0x7e,0x99,0x24,0x24,0x28,0xc3,0xc3,0x24,0xe7,0x24,0xc3,0xc3,0x28,0x23,0x23,0x9e,0x7e,0x79,0xc4,0xc4,0x28,0x1c,0x1c,0x3b,0xdb,0xdc,0x38,0x38,0x28,0xff,0x81,0xbd,0xe7,0xbd,0x81,0xff,0x50,0x23,0x53,0xa8,0x54,0xca,0xf5,0xe9,0x50,0x24,0x5a,0x5a,0x5a,0x5a,0x5a,0xbd,0x50,0x24,0x5a,0x99,0x00,0x99,0x5a,0x24,0x50,0xe7,0xe7,0xbd,0x00,0xbd,0xe7,0xe7,0x50,0x24,0x5a,0x7e,0x5a,0xc3,0x5a,0x99,0x50,0x7e,0x42,0x3c,0x42,0x7e,0x00,0x7e,0x50,0x29,0x59,0x9e,0x7e,0x79,0x9a,0x94,0x50,0x99,0xbd,0x5a,0x00,0x5a,0xbd,0x99,0x50,0x7e,0x5a,0x7e,0x5a,0x7e,0x5a,0x7e,0x46,0x24,0x5a,0xbd,0x24,0xbd,0x5a,0x24,0x46,0x5a,0x24,0x5a,0x5a,0x5a,0x24,0x5a,0x46,0x24,0x5a,0xbd,0x7e,0x7e,0xbd,0x99,0x46,0xc3,0xbd,0x7e,0x5a,0x24,0xc3,0xe7,0x46,0x73,0x4b,0x24,0x2a,0xf2,0xee,0xe0,0x46,0xc3,0xbd,0xc3,0xbd,0xc3,0xbd,0xc3,0x46,0xc3,0xbd,0x7e,0xbd,0xc3,0xbd,0x7e,0x46,0xc3,0xc3,0xbd,0x7e,0xbd,0xc3,0xc3,0x46,0xe7,0xe7,0x99,0x5a,0x99,0xe7,0xe7,0x46,0xb3,0xfb,0xfc,0x7e,0x3f,0xdf,0xcd,0x46,0x5a,0x7e,0x24,0x7e,0x24,0x7e,0x5a,0x46,0x5a,0x5a,0x99,0xc3,0x99,0x5a,0x5a,0x46,0x24,0xc3,0xe7,0xc3,0x24,0xe7,0xc3,0x46,0xe7,0x99,0x7e,0xe7,0xc3,0x24,0x5a,0x46,0xdc,0xdf,0x7d,0xbd,0xbe,0xb7,0x77,0x46,0x7e,0x00,0x5a,0x5a,0x24,0x00,0x7e,0x46,0x24,0x99,0xbd,0xe7,0xbd,0x99,0x24,0x46,0x70,0xa8,0x74,0x09,0xd6,0x0a,0x07,0x46,0x18,0x66,0x66,0xed,0x7d,0x7d,0x11,0x46,0x7e,0x5a,0x99,0xe7,0x99,0x5a,0x7e,0x50,0xc3,0xbd,0x24,0x5a,0x24,0xbd,0xc3,0x50,0xe7,0x00,0xa5,0x42,0xa5,0x00,0xe7,0x50,0xe7,0x18,0xc3,0xdb,0xc3,0x18,0xe7,0x50,0xe7,0xe7,0xff,0x3c,0xff,0xe7,0xe7,0x50,0x24,0xdb,0x00,0xff,0x00,0xdb,0x24,0x50,0xe7,0x00,0x99,0x7e,0x99,0x00,0xe7,0x50,0x42,0x3c,0xdb,0xa5,0xdb,0x3c,0x42,0x50,0xe7,0xc3,0x00,0x24,0x00,0xc3,0xe7,0x50,0x66,0x81,0xff,0x18,0xff,0x81,0x66,0x50,0x99,0x5a,0xbd,0xbd,0x99,0x5a,0x24,0x5a,0x00,0x81,0xbd,0x3c,0xbd,0x81,0x00,0x5a,0xce,0xdb,0x35,0x6b,0xd6,0xaf,0xfb,0x5a,0x7e,0x5a,0x7e,0x00,0x7e,0x5a,0x7e,0x5a,0x7e,0x00,0x5a,0x7e,0x5a,0x00,0x7e,0x5a,0xe7,0x99,0x5a,0x7e,0x7e,0x99,0x99,0x5a,0x24,0x00,0x24,0x7e,0x5a,0x5a,0x24,0x5a,0x24,0x5a,0x5a,0x24,0x7e,0x24,0x5a,0x5a,0x7e,0x5a,0xc3,0xe7,0xc3,0x5a,0x7e,0x5a,0x24,0x00,0xe7,0x24,0xe7,0x00,0x24,0x5a,0x7e,0xbd,0xe7,0x5a,0xe7,0xbd,0x7e,0x5a,0x24,0x24,0x99,0x5a,0xbd,0x24,0x24,0x5a,0x24,0xc3,0xe7,0x24,0xe7,0xc3,0x24,0x5a,0x24,0xc3,0xe7,0xe7,0xe7,0xc3,0x24,0x5a,0x24,0x5a,0x24,0xe7,0x99,0x24,0xc3,0x5a,0x7e,0xc3,0x00,0xc3,0x7e,0xbd,0x7e,0x5a,0x99,0x5a,0x5a,0x5a,0x5a,0x24,0xc3,0x5a,0xe7,0xe7,0x5a,0x24,0x5a,0xe7,0xe7,0x5a,0xe7,0x99,0x99,0xbd,0xe7,0xc3,0x24,0x5a,0x7e,0x99,0x5a,0x24,0xbd,0x5a,0x5a,0x5a,0xc3,0xe7,0x24,0xc3,0xe7,0xc3,0x24,0x5a,0x24,0xc3,0x7e,0x7e,0xe7,0x5a,0x24,0x5a,0x3c,0x3c,0x42,0xa5,0x42,0x3c,0x3c,0x5a,0xe7,0x99,0x99,0xe7,0x5a,0xbd,0xc3,0x5a,0x5a,0x24,0x7e,0x7e,0x00,0x7e,0x5a,0x5a,0x7e,0xbd,0xe7,0xe7,0x5a,0x5a,0x5a,0x5a,0xe7,0x99,0x7e,0xbd,0xc3,0xbd,0x7e,0x5a,0x5a,0x5a,0x00,0x5a,0x00,0x5a,0x5a,0x5a,0x5a,0x5a,0xbd,0xc3,0xbd,0x5a,0x5a,0x5a,0xe3,0x8f,0x8c,0x5a,0x31,0xf1,0xc7,0x5a];
var setupPattern=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,36,37,38,39,47,55,54,53,52,44,45,46,19,18,17,16,8,0,1,2,3,11,10,9,35,34,33,32,40,48,49,50,51,43,42,41,20,21,22,23,15,7,6,5,4,12,13,14,31,30,29,28,27,26,25,24,55,54,46,47,39,38,30,31,23,22,14,15,7,6,5,4,12,13,21,20,28,29,37,36,44,45,53,52,51,50,42,43,35,34,26,27,19,18,10,11,3,2,1,0,8,9,17,16,24,25,33,32,40,41,49,48,0,1,2,3,4,5,6,7,15,23,31,39,47,55,54,53,52,51,50,49,48,40,32,24,16,8,9,10,11,12,13,14,22,30,38,46,45,44,43,42,41,33,25,17,18,19,20,21,29,37,36,35,34,26,27,28,7,6,5,4,3,2,1,0,8,16,24,32,40,48,49,50,51,52,53,54,55,47,46,45,44,43,42,41,33,25,17,9,10,11,12,13,14,15,23,22,21,20,19,18,26,34,35,36,37,38,39,31,30,29,28,27,0,1,2,3,4,5,6,7,15,14,13,12,11,10,9,8,16,17,18,19,20,21,22,23,31,30,29,28,27,26,25,24,32,33,34,35,36,37,38,39,47,46,45,44,43,42,41,40,48,49,50,51,52,53,54,55,48,40,32,33,34,26,18,17,25,24,16,8,0,1,9,10,2,3,4,12,11,19,27,35,43,42,41,49,50,51,52,44,36,28,20,21,13,5,6,7,15,14,22,23,31,39,47,55,54,53,45,46,38,30,29,37];
var pausePattern=[0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,15,15,23,23,31,31,39,39,47,47,55,55,54,54,53,53,52,52,51,51,50,50,49,49,48,48,40,40,32,32,24,24,16,16,8,8,0,0,1,1,2,2,3,3];
var pulseAnim=[0,0,0,0,0,1,1,1,2,2,2,3,3,3,3,3,3,3,3,3,3,3,2,2,2,1,1,1];
var cursorAnim=[0,1,2,3,4,5,6,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,6,5,4,3,2,1];
var	droneAnim=[0,1,2,3,4,5,6,6,5,4,3,2,1,0];
var plasmaSine=[0,12,25,37,50,62,75,87,100,112,125,137,150,162,175,187,199,212,224,236,248,260,273,285,297,309,321,333,344,356,368,380,391,403,414,426,437,449,460,471,482,493,504,515,526,537,547,558,568,579,589,599,609,620,629,639,649,659,668,678,687,696,706,715,724,732,741,750,758,767,775,783,791,799,807,814,822,829,837,844,851,858,865,871,878,884,890,897,903,908,914,920,925,930,936,941,946,950,955,959,964,968,972,976,979,983,986,990,993,996,999,1001,1004,1006,1008,1010,1012,1014,1016,1017,1019,1020,1021,1022,1022,1023,1023,1023,1023,1023,1023,1023,1022,1022,1021,1020,1019,1017,1016,1014,1012,1010,1008,1006,1004,1001,999,996,993,990,986,983,979,976,972,968,964,959,955,950,946,941,936,930,925,920,914,908,903,897,890,884,878,871,865,858,851,844,837,829,822,814,807,799,791,783,775,767,758,750,741,732,724,715,706,696,687,678,668,659,649,639,629,620,609,599,589,579,568,558,547,537,526,515,504,493,482,471,460,449,437,426,414,403,391,380,368,356,344,333,321,309,297,285,273,260,248,236,224,212,199,187,175,162,150,137,125,112,100,87,75,62,50,37,25,12,0,-13,-26,-38,-51,-63,-76,-88,-101,-113,-126,-138,-151,-163,-176,-188,-200,-213,-225,-237,-249,-261,-274,-286,-298,-310,-322,-334,-345,-357,-369,-381,-392,-404,-415,-427,-438,-450,-461,-472,-483,-494,-505,-516,-527,-538,-548,-559,-569,-580,-590,-600,-610,-621,-630,-640,-650,-660,-669,-679,-688,-697,-707,-716,-725,-733,-742,-751,-759,-768,-776,-784,-792,-800,-808,-815,-823,-830,-838,-845,-852,-859,-866,-872,-879,-885,-891,-898,-904,-909,-915,-921,-926,-931,-937,-942,-947,-951,-956,-960,-965,-969,-973,-977,-980,-984,-987,-991,-994,-997,-1000,-1002,-1005,-1007,-1009,-1011,-1013,-1015,-1017,-1018,-1020,-1021,-1022,-1023,-1023,-1024,-1024,-1024,-1024,-1024,-1024,-1024,-1023,-1023,-1022,-1021,-1020,-1018,-1017,-1015,-1013,-1011,-1009,-1007,-1005,-1002,-1000,-997,-994,-991,-987,-984,-980,-977,-973,-969,-965,-960,-956,-951,-947,-942,-937,-931,-926,-921,-915,-909,-904,-898,-891,-885,-879,-872,-866,-859,-852,-845,-838,-830,-823,-815,-808,-800,-792,-784,-776,-768,-759,-751,-742,-733,-725,-716,-707,-697,-688,-679,-669,-660,-650,-640,-630,-621,-610,-600,-590,-580,-569,-559,-548,-538,-527,-516,-505,-494,-483,-472,-461,-450,-438,-427,-415,-404,-392,-381,-369,-357,-345,-334,-322,-310,-298,-286,-274,-261,-249,-237,-225,-213,-200,-188,-176,-163,-151,-138,-126,-113,-101,-88,-76,-63,-51,-38,-26,-13];
var plasmaColors=[0x5000,0x5400,0x5400,0x5420,0x5420,0x5421,0x5421,0x5441,0x5442,0x5442,0x5462,0x5462,0x5463,0x5863,0x5883,0x5884,0x58a4,0x58a4,0x58a5,0x58c5,0x58c6,0x5cc6,0x5ce6,0x5ce7,0x5ce7,0x5d08,0x5d08,0x5d28,0x6129,0x6149,0x614a,0x614a,0x616b,0x616b,0x658c,0x658c,0x65ac,0x65ad,0x65cd,0x65ce,0x65ee,0x69ef,0x6a0f,0x6a10,0x6a10,0x6a31,0x6a31,0x6e52,0x6e52,0x6e72,0x6e73,0x6e93,0x6e94,0x72b4,0x72b5,0x72b5,0x72d6,0x72d6,0x72f7,0x76f7,0x7717,0x7718,0x7718,0x7739,0x7739,0x7759,0x7b5a,0x7b5a,0x7b7b,0x7b7b,0x7b7b,0x7b9c,0x7b9c,0x7b9c,0x7bbd,0x7fbd,0x7fbd,0x7fde,0x7fde,0x7fde,0x7fde,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7bdf,0x7bdf,0x7bdf,0x77df,0x77bf,0x77bf,0x77be,0x73be,0x739e,0x739e,0x6f7e,0x6f7e,0x6f7e,0x6b5e,0x6b5d,0x675d,0x673d,0x673d,0x633d,0x631d,0x5f1d,0x5efd,0x5efc,0x5afc,0x5adc,0x56dc,0x56bc,0x52bc,0x529b,0x4e9b,0x4e9b,0x4e7b,0x4a7b,0x4a5b,0x465b,0x463a,0x423a,0x421a,0x3e1a,0x3e1a,0x39fa,0x39f9,0x35d9,0x35d9,0x31b9,0x31b9,0x3199,0x2d98,0x2d98,0x2978,0x2978,0x2558,0x2558,0x2158,0x2137,0x2137,0x1d17,0x1d17,0x1917,0x18f7,0x18f6,0x14d6,0x14d6,0x10d6,0x10b6,0x10b6,0x0cb6,0x0c96,0x0c96,0x0895,0x0875,0x0875,0x0475,0x0475,0x0455,0x0455,0x0055,0x0055,0x0035,0x0035,0x0034,0x0034,0x0034,0x0034,0x0034,0x0034,0x0034,0x0433,0x0433,0x0433,0x0433,0x0433,0x0832,0x0832,0x0832,0x0832,0x0c31,0x0c31,0x0c31,0x0c31,0x0c31,0x1030,0x1030,0x1030,0x1430,0x142f,0x142f,0x142f,0x182e,0x182e,0x182e,0x1c2d,0x1c2d,0x1c2d,0x1c2d,0x202c,0x202c,0x202c,0x242b,0x242b,0x242b,0x282a,0x282a,0x282a,0x2829,0x2c29,0x2c09,0x2c09,0x3028,0x3008,0x3008,0x3407,0x3407,0x3407,0x3406,0x3806,0x3806,0x3806,0x3c05,0x3c05,0x3c05,0x3c05,0x4004,0x4004,0x4004,0x4004,0x4403,0x4403,0x4403,0x4803,0x4802,0x4802,0x4802,0x4802,0x4c01,0x4c01,0x4c01,0x4c01,0x4c01,0x5001,0x5000,0x5000,0x5000,0x5000,0x5000,0x5000];
var charWidth=[24,32,32,32,32,30,32,32,32,16,32,32,18,32,32,32,32,32,32,32,18,32,32,32,32,32,32,16,16,16,16,32,32];
var smallWidth=[8,16,16,16,16,15,16,16,16,8,16,16,9,16,16,16,16,16,16,16,9,16,16,16,16,16,16,];
var diagonalMove=[1,1,0,1,1,0,1,1,0,1];
var markerAnim=[0,0,1,1,2,2,3,3,4,4];
var tileBlinkX=[2,2,1,1,0,0,1,1,2,2];
var tileBlinkY=[0,0,0,0,0,1,1,1,1,1];
var okAlpha=[0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.6,0.6,0.6,0.6,0.6,0.55,0.5,0.45,0.4,0.35,0.3,0.25,0.2,0.15,0.1,0.1,0.1,0.1];
var droneAlpha=[1.0,0.95,0.9,0.85,0.8,0.75,0.7,0.65,0.6,0.55,0.5,0.45,0.4,0.35,0.3,0.25,0.2,0.15,0.1,0.05,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1.0,1.0];
var droneSize=[52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,90,88,86,84,82,80,78,76,74,72,70,68,66,64,62,60,58,56,54,52,52];
var scrolltext = " deep in the heart of the hills of wenley something is amiss - the wenley moor nuclear power plant buried five hundred feet below ground level is at risk. the control computer has been infected by a virus from an unknown source which has caused the complete shutdown of all computer systems and a total randomisation of the core settings. fortunately the computer is now offline but there#s a catch - all ninety nine cores are now dangerously unstable and, although all shields are in place for now, they will soon be unable to contain the entropy. it#s up to you to straighten this mess out! you have at your disposal a core monitor unit to enter each core and edit the rod states, but there is a further problem. when you toggle a rod, a chain reaction occurs in the surrounding eight causing them to flip states too and worse still the core#s shields must be disabled to allow the monitor unit access to a core so each has a time limit until meltdown. succeed and you save the entire planet from a gigantic nuclear explosion - fail and that#s it... good luck operator!      * ";
var charMap0=["q","w","e","r","t","y","u","i","o","p","0"];
var charMap1=["a","s","d","f","g","h","j","k","l","-","-"];
var charMap2=["z","x","c","v","b","n","m",".","-","-","-"];
var currentLevelMap=[];
var setupLevelMap=[];
var paletteR=[];
var paletteG=[];
var paletteB=[];
var scrollPos=[];
var scrollBuffer=[];
var hiscoreNames=[];
var hiscoreScores=[];
var i, j, k, l, bitPattern, lF, currentTime, currentX, currentY, targetX, targetY, targetTileX, targetTileY, digit0, digit1, digit2, digit3, digit4, digit5, score, targetScore, droneActive;
var drawLevelPtr, currentPattern, pulsePtr1, pulsePtr2, droneAnimPtr, showGameOver, pauseAlpha, gameOverBlink, showMessage, pauseActive, showIntro, introTicker, okPtr, onOK, selectedLevel;
var logoPos, raster1Pos, raster2Pos, add, r, g, b, color1, color2, currentColor, plasmaBuffer, plasmaPix, scrollTextPtr, charData, lastPos, diagPtr, wipePos, maxlevel, selectLevel, loaderror;
var onLeft, onRight, playername, playfieldWidth, playfieldHeight, nameEntry, markerZoomPtr, keyChar, musicLoaded, music, audioEnabled, currentKeyChar, tmpName, gameInit;

function makeRequest(ajaxAction) {
	var ajaxFile = "http://www.widdy.de/hiscores.php?action="+ajaxAction+"&score="+score+"&username="+playername;
 	http_request = false;
 	
 	if (window.XMLHttpRequest) {
	  http_request = new XMLHttpRequest();
  	if (http_request.overrideMimeType) {
   		http_request.overrideMimeType('text/xml');
  	}
 	} else if (window.ActiveXObject) {
  	try {
   		http_request = new ActiveXObject("Msxml2.XMLHTTP");
  	} catch (e) {
   		try {
    		http_request = new ActiveXObject("Microsoft.XMLHTTP");
   		} catch (e) {}
  	}
 	}
 	if (!http_request) {
	  alert("ERROR: Can't create XMLHTTP request!");
	  return false;
 	}
 	http_request.onreadystatechange = function() {processRequest();};
 	http_request.open('GET', ajaxFile, true);
 	http_request.send(null);
}

function processRequest() {
	if (http_request.readyState == 4) {
		var scoreData = http_request.responseText.substr(7, 287);
		j = 0;
		var dbgText = "";
		for (i = 0; i < 16; i++) {
			hiscoreScores[i] = scoreData.substr(j, 6);
			hiscoreNames[i] = scoreData.substr((j + 7), 10);
			j += 18;
		}
		if (http_request.responseText.substr(294) != "</entry>") {
			loaderror = 1;
		} else {
			loaderror = 0;
		}
	}
}

function getSize() {
	var elem = document.getElementById("playfield");
	if (elem.currentStyle) {
		playfieldWidth = parseInt(elem.currentStyle["width"]);
		playfieldHeight = parseInt(elem.currentStyle["height"]);
	} else if (window.getComputedStyle) {
		playfieldWidth = parseInt(document.defaultView.getComputedStyle(elem, null).getPropertyValue("width"));
		playfieldHeight = parseInt(document.defaultView.getComputedStyle(elem, null).getPropertyValue("height"));
	}
}

function resizeGame(size) {
	if (size == "small") {
		document.getElementById("btnsml").innerHTML = '<img src="images/btn.gif" width="31" height="23" border="0" alt="Small">';
		document.getElementById("btnmed").innerHTML = '<a href="#" onClick="resizeGame(\'medium\');" onFocus="this.blur();"><img src="images/btn.gif" width="31" height="23" border="0" alt="Medium"></a>';
		document.getElementById("btnbig").innerHTML = '<a href="#" onClick="resizeGame(\'big\');" onFocus="this.blur();"><img src="images/btn.gif" width="31" height="23" border="0" alt="Big"></a>';
		document.getElementById("playfield").style.width = "320px";
		document.getElementById("playfield").style.height = "240px";
		playfieldWidth = 320;
		playfieldHeight = 240;
	} else if (size == "big") {
		document.getElementById("btnsml").innerHTML = '<a href="#" onClick="resizeGame(\'small\');" onFocus="this.blur();"><img src="images/btn.gif" width="31" height="23" border="0" alt="Small"></a>';
		document.getElementById("btnmed").innerHTML = '<a href="#" onClick="resizeGame(\'medium\');" onFocus="this.blur();"><img src="images/btn.gif" width="31" height="23" border="0" alt="Medium"></a>';
		document.getElementById("btnbig").innerHTML = '<img src="images/btn.gif" width="31" height="23" border="0" alt="Big">';
		document.getElementById("playfield").style.width = "800px";
		document.getElementById("playfield").style.height = "600px";
		playfieldWidth = 800;
		playfieldHeight = 600;
	} else {
		document.getElementById("btnsml").innerHTML = '<a href="#" onClick="resizeGame(\'small\');" onFocus="this.blur();"><img src="images/btn.gif" width="31" height="23" border="0" alt="Small"></a>';
		document.getElementById("btnmed").innerHTML = '<img src="images/btn.gif" width="31" height="23" border="0" alt="Medium">';
		document.getElementById("btnbig").innerHTML = '<a href="#" onClick="resizeGame(\'big\');" onFocus="this.blur();"><img src="images/btn.gif" width="31" height="23" border="0" alt="Big"></a>';
		document.getElementById("playfield").style.width = "640px";
		document.getElementById("playfield").style.height = "480px";
		playfieldWidth = 640;
		playfieldHeight = 480;
	}
}

function toggleAudio() { 
	if (audioEnabled == 1) {
		audioEnabled = 0;
		document.getElementById("btnaudio").style.display = "none";
		document.getElementById("btnnoaudio").style.display = "block";
		music.pause();
		music.currentTime = 0;
	} else {
		audioEnabled = 1;
		document.getElementById("btnaudio").style.display = "block";
		document.getElementById("btnnoaudio").style.display = "none";
		music.play();
	}
}

function init() {
	username = "          ";
	playername = username;
	startlevel = 1;
	maxlevel = startlevel;
	selectedLevel = maxlevel;
	lF = 0;
	score = 0;
	targetScore = 0;
	currentX = 221;
	currentY = 57;
	droneActive = 0;
	drawLevelPtr = 0;
	currentSetupPattern = 0;
	currentTime = 60;
	pulsePtr1 = 0;
	pulsePtr2 = 14;
	droneAnimPtr = 0;
	showGameOver = 0;
	pauseAlpha = 0.0;
	gameOverBlink = 0;
	showMessage = 0;
	pauseActive = 0;
	showIntro = 1;
	logoPos = -640;
	raster1Pos = 396;
	raster2Pos = 460;
	scrollTextPtr = 0;
	introTicker = 0;
	diagPtr = 0;
	add = 0;
	r = 0;
	g = 0;
	b = 0;
	lastPos = 0;
	wipePos = -20;
	selectLevel = 0;
	okPtr = 0;
	nameEntry = 0;
	musicLoaded = 0;
	audioEnabled = 1;
	currentKeyChar = 0;
	gameInit = 1;
	for (i = 0; i < 32; i++) {
		scrollPos[i] = lastPos;
		scrollBuffer[i] = 0;
		lastPos += charWidth[scrollBuffer[i]];
	}
	for (i = 0; i < 256; i++) {
		currentColor = plasmaColors[i];
		r = 0;
		g = 0;
		b = 0;
		while (currentColor >= 1024) {
			b++;
			currentColor -= 1024;
		}
		while (currentColor >= 32) {
			g++;
			currentColor -= 32;
		}
		r = currentColor;
		paletteR[i] = r * 8;
		paletteG[i] = g * 8;
		paletteB[i] = b * 8;
	}
	for (i = 0; i < 56; i++) {
		currentLevelMap[i] = 0;
	}
	loaderror = 1;
	makeRequest("load");
	canvas = document.getElementById('playfield');
	if (canvas.getContext) {
		getSize();
		ctx = canvas.getContext('2d');
		plasmaBuffer = ctx.createImageData(640, 192);
		plasmaPix = plasmaBuffer.data;
		document.onmousemove = updateMouse;
		document.onmousedown = mouseClick;
		document.ontouchend = mouseTouch;
		pl0 = new Image();
		pl0.onload = function() {
			lF++;
		}
		pl0.src = "images/pl0.png";
		pl1 = new Image();
		pl1.onload = function() {
			lF++;
		}
		pl1.src = "images/pl1.gif";
		tile0 = new Image();
		tile0.onload = function() {
			lF++;
		}
		tile0.src = "images/tile0.gif";
		tile1 = new Image();
		tile1.onload = function() {
			lF++;
		}
		tile1.src = "images/tile1.gif";
		drone = new Image();
		drone.onload = function() {
			lF++;
		}
		drone.src = "images/drone.png";
		gamenums = new Image();
		gamenums.onload = function() {
			lF++;
		}
		gamenums.src = "images/gamenums.gif";
		bg = new Image();
		bg.onload = function() {
			lF++;
		}
		bg.src = "images/bg.png";
		schatten = new Image();
		schatten.onload = function() {
			lF++;
		}
		schatten.src = "images/schatten.png";
		hitiles = new Image();
		hitiles.onload = function() {
			lF++;
		}
		hitiles.src = "images/hltiles.png";
		pulse = new Image();
		pulse.onload = function() {
			lF++;
		}
		pulse.src = "images/pulse.gif";
		pausetiles = new Image();
		pausetiles.onload = function() {
			lF++;
		}
		pausetiles.src = "images/pausetiles.png";
		gameovertext = new Image();
		gameovertext.onload = function() {
			lF++;
		}
		gameovertext.src = "images/gameover.png";
		pausetext = new Image();
		pausetext.onload = function() {
			lF++;
		}
		pausetext.src = "images/pause.png";
		clicktext = new Image();
		clicktext.onload = function() {
			lF++;
		}
		clicktext.src = "images/click.png";
		hipause = new Image();
		hipause.onload = function() {
			lF++;
		}
		hipause.src = "images/hlpause.png";
		hibutton = new Image();
		hibutton.onload = function() {
			lF++;
		}
		hibutton.src = "images/hlbutton.png";
		logo = new Image();
		logo.onload = function() {
			lF++;
		}
		logo.src = "images/logo.gif";
		introoverlay = new Image();
		introoverlay.onload = function() {
			lF++;
		}
		introoverlay.src = "images/introoverlay.png";
		raster = new Image();
		raster.onload = function() {
			lF++;
		}
		raster.src = "images/raster.png";
		bigfont = new Image();
		bigfont.onload = function() {
			lF++;
		}
		bigfont.src = "images/bigfont.png";
		scoreoverlay = new Image();
		scoreoverlay.onload = function() {
			lF++;
		}
		scoreoverlay.src = "images/scoreoverlay.png";
		credits1overlay = new Image();
		credits1overlay.onload = function() {
			lF++;
		}
		credits1overlay.src = "images/credits1overlay.png";
		credits2overlay = new Image();
		credits2overlay.onload = function() {
			lF++;
		}
		credits2overlay.src = "images/credits2overlay.png";
		wipe0 = new Image();
		wipe0.onload = function() {
			lF++;
		}
		wipe0.src = "images/wipe0.png";
		wipe1 = new Image();
		wipe1.onload = function() {
			lF++;
		}
		wipe1.src = "images/wipe1.png";
		wipe2 = new Image();
		wipe2.onload = function() {
			lF++;
		}
		wipe2.src = "images/wipe2.png";
		wipe3 = new Image();
		wipe3.onload = function() {
			lF++;
		}
		wipe3.src = "images/wipe3.png";
		marker = new Image();
		marker.onload = function() {
			lF++;
		}
		marker.src = "images/marker.png";
		select = new Image();
		select.onload = function() {
			lF++;
		}
		select.src = "images/select.png";
		arrows = new Image();
		arrows.onload = function() {
			lF++;
		}
		arrows.src = "images/arrows.gif";
		ok = new Image();
		ok.onload = function() {
			lF++;
		}
		ok.src = "images/ok.gif";
		bignums = new Image();
		bignums.onload = function() {
			lF++;
		}
		bignums.src = "images/bignums.png";
		smallfont = new Image();
		smallfont.onload = function() {
			lF++;
		}
		smallfont.src = "images/smallfont.png";
		smallnums = new Image();
		smallnums.onload = function() {
			lF++;
		}
		smallnums.src = "images/smallnums.png";
		erroroverlay = new Image();
		erroroverlay.onload = function() {
			lF++;
		}
		erroroverlay.src = "images/erroroverlay.png";
		keyboard = new Image();
		keyboard.onload = function() {
			lF++;
		}
		keyboard.src = "images/keyboard.png";
		entryoverlay = new Image();
		entryoverlay.onload = function() {
			lF++;
		}
		entryoverlay.src = "images/entryoverlay.png";
		scorefont = new Image();
		scorefont.onload = function() {
			lF++;
		}
		scorefont.src = "images/scorefont.png";
		zoomoverlay = new Image();
		zoomoverlay.onload = function() {
			lF++;
		}
		zoomoverlay.src = "images/zoomoverlay.png";
		keyoverlay = new Image();
		keyoverlay.onload = function() {
			lF++;
		}
		keyoverlay.src = "images/keyoverlay.png";
		keyoverlay1 = new Image();
		keyoverlay1.onload = function() {
			lF++;
		}
		keyoverlay1.src = "images/keyoverlay1.png";
		keyoverlay2 = new Image();
		keyoverlay2.onload = function() {
			lF++;
		}
		keyoverlay2.src = "images/keyoverlay2.png";
		cursor = new Image();
		cursor.onload = function() {
			lF++;
		}
		cursor.src = "images/cursor.gif";
		lobutton = new Image();
		lobutton.onload = function() {
			lF++;
		}
		lobutton.src = "images/lobutton.png";
		music = new Audio("http://www.widdy.de/html5/reaxion/music.ogg");
		music.addEventListener("ended", function() {
			this.currentTime = 0;
			this.play();
		}, false);
		setInterval(updateGame, 33);
	} else {
		alert("ERROR: Can't create canvas context!");
	}
}

function updateGame() {
	if ((lF >= 2) && (lF < 44)) {
		ctx.drawImage(pl0, 20, 220);
		var barWidth = (lF * 13);
		if (barWidth > 592) {
			barWidth = 592;
		}
		ctx.drawImage(pl1, 0, 0, 592, 32, 24, 224, barWidth, 32);
	} else if (lF >= 44) {
		if (musicLoaded == 0) {
			music.play();
			musicLoaded = 1;
		}
		if (gameOverBlink < 30) {
			gameOverBlink++;
		} else {
			gameOverBlink = 0;
		}
		if (showIntro == 1) {
			intro();
		} else {
			game();
		}
	}
}

function loadLevel() {
	for (i = 0; i < 7; i++) {
		bitpattern = "" + levels[((level - 1) * 8) + i].toString(2);
		if (bitpattern.length < 8) {
			bitpattern = ('00000000' + bitpattern).slice(-8);
		}
		for (j = 0; j < 8; j++) {
			k = bitpattern.substring(j, (j + 1));
			setupLevelMap[(i * 8) + j] = k;
		}
	}
	drawLevelPtr = 0;
	if (currentPattern < 6) {
		currentPattern++;
	} else {
		currentPattern = 0;
	}
}

function updateMouse(e) {
	mouseX = (e.pageX - canvas.offsetLeft) * (640 / playfieldWidth);
	mouseY = (e.pageY - canvas.offsetTop) * (480 / playfieldHeight);
}

function toggleTile() {
	for (j = 0; j < 3; j++) {
		for (i = 0; i < 3; i++) {
			if (((targetTileX - 1 + i) >= 0) && ((targetTileX - 1 + i) <= 7) && ((targetTileY - 1 + j) >= 0) && ((targetTileY - 1 + j) <= 6)) {
				if (droneAnimPtr == 13) {
					if ((currentLevelMap[(((targetTileY - 1 + j) * 8) + (targetTileX - 1 + i))] == 0) || ((currentLevelMap[(((targetTileY - 1 + j) * 8) + (targetTileX - 1 + i))] == 10))) {
						currentLevelMap[(((targetTileY - 1 + j) * 8) + (targetTileX - 1 + i))] = 1;
					} else {
						currentLevelMap[(((targetTileY - 1 + j) * 8) + (targetTileX - 1 + i))] = 0;
					}
				} else {
					if (currentLevelMap[(((targetTileY - 1 + j) * 8) + (targetTileX - 1 + i))] == 0) {
						currentLevelMap[(((targetTileY - 1 + j) * 8) + (targetTileX - 1 + i))] = 10;
					} else if (currentLevelMap[(((targetTileY - 1 + j) * 8) + (targetTileX - 1 + i))] == 1) {
						currentLevelMap[(((targetTileY - 1 + j) * 8) + (targetTileX - 1 + i))] = 20;
					}
				}
			}
		}
	}
	j = 0;
	for (i = 0; i < 56; i++) {
		j += currentLevelMap[i];
	}
	if (j == 0) {
		targetScore = score + ((level + 1) * 10) + (currentTime * 10);
		if (level < 99) {
			level++;
			if (level > maxlevel) {
				maxlevel = level;
			}
		} else {
			level = 1;
		}
		loadLevel();
		markerZoomPtr = 0;
	}
}

function calcScore(currentScore) {
	if (currentScore > 999999) {
		currentScore -= 1000000;
	}
	digit0 = 0;
	digit1 = 0;
	digit2 = 0;
	digit3 = 0;
	digit4 = 0;
	digit5 = currentScore;

	while (digit5 >= 100000) {
		digit5 -= 100000;
		digit0++;
	}
	while (digit5 >= 10000) {
		digit5 -= 10000;
		digit1++;
	}
	while (digit5 >= 1000) {
		digit5 -= 1000;
		digit2++;
	}
	while (digit5 >= 100) {
		digit5 -= 100;
		digit3++;
	}
	while (digit5 >= 10) {
		digit5 -= 10;
		digit4++;
	}
}

function mouseTouch(e) {
	e.preventDefault();
	event = e.changedTouches[0];
	mouseX = (event.pageX - canvas.offsetLeft) * (640 / playfieldWidth);
	mouseY = (event.pageY - canvas.offsetTop) * (480 / playfieldHeight);
	mouseClick();
}

function mouseClick() {
	if (showIntro == 1) {
		if (nameEntry == 1) {
			if (keyChar == "0") {
				if (currentKeyChar > 0) {
					currentKeyChar--;
				}
			} else if (keyChar == "1") {
				makeRequest("save");
				nameEntry = 0;
			} else if (keyChar != "") {
				tmpName = "";
				for (i = 0; i < 10; i++) {
					if (i == currentKeyChar) {
						tmpName += keyChar;
					} else {
						tmpName += playername.charAt(i);
					}
				}
				playername = tmpName;
				if (currentKeyChar < 9) {
					currentKeyChar++;
				}
			}
		} else if (logoPos == 0) {
			if ((mouseX > 0) && (mouseX < 640) && (mouseY > 0) && (mouseY < 480)) {
				if ((selectLevel == 1) && (onOK == 1)) {
					level = selectedLevel;
					loadLevel();
					selectLevel = 0;
					ctx.drawImage(bg, 0, 0);
					score = 0;
					gameInit = 1;
					targetScore = 0;
					showIntro = 0;
					markerZoomPtr = 0;
				} else if ((selectLevel == 1) && (onLeft == 1)) {
					if (selectedLevel > 1) {
						selectedLevel--;
					} else {
						selectedLevel = maxlevel;
					}
				} else if ((selectLevel == 1) && (onRight == 1)) {
					if (selectedLevel < maxlevel) {
						selectedLevel++;
					} else {
						selectedLevel = 1;
					}
				} else if (maxlevel > 1) {
					selectLevel = 1;
				} else {
					ctx.drawImage(bg, 0, 0);
					level = 1;
					score = 0;
					gameInit = 1;
					targetScore = 0;
					loadLevel();
					showIntro = 0;
					markerZoomPtr = 0;
				}
			}
		}
	} else {
		if ((showGameOver == 0) && (pauseActive == 0)) {
			if (droneAnimPtr == 0) {
				if ((mouseX > 221) && (mouseX < 605) && (mouseY > 57) && (mouseY < 393)) {
					if (drawLevelPtr == 56) {
						droneActive = 1;
						targetX = (Math.floor((mouseX - 221) / 48) * 48) + 221;
						targetY = (Math.floor((mouseY - 57) / 48) * 48) + 57;
						targetTileX = Math.floor((mouseX - 221) / 48);
						targetTileY = Math.floor((mouseY - 57) / 48);
					}
				}
			}
			if ((mouseX >= 544) && (mouseX <= 568) && (mouseY >= 450) && (mouseY <= 474)) {
				pauseActive = 1;
			} else if ((mouseX >= 573) && (mouseX <= 597) && (mouseY >= 450) && (mouseY <= 474)) {
				if (drawLevelPtr == 56) {
					targetScore = score;
					currentX = 221;
					currentY = 57;
					droneActive = 0;
					droneAnimPtr = 0;
					showGameOver = 0;
					pauseAlpha = 0.0;
					gameOverBlink = 0;
					showMessage = 0;

					for (i = 0; i < 7; i++) {
						bitpattern = "" + levels[((level - 1) * 8) + i].toString(2);
						if (bitpattern.length < 8) {
							bitpattern = ('00000000' + bitpattern).slice(-8);
						}
						for (j = 0; j < 8; j++) {
							k = bitpattern.substring(j, (j + 1));
							currentLevelMap[(i * 8) + j] = k;
						}
					}
				}
			}
		} else if (pauseActive == 1) {
			pauseAlpha = 0.0;
			pauseActive = 0;
		}	else {
			if (showMessage == 1) {
				nameEntry = 1;
				currentKeyChar = 0;
				targetScore = 0;
				currentX = 221;
				currentY = 57;
				droneActive = 0;
				drawLevelPtr = 0;
				currentSetupPattern = 0;
				currentTime = 60;
				pulsePtr1 = 0;
				pulsePtr2 = 14;
				droneAnimPtr = 0;
				showGameOver = 0;
				pauseAlpha = 0.0;
				gameOverBlink = 0;
				showMessage = 0;
				pauseActive = 0;
				selectedLevel = maxlevel;
				loadLevel();
				for (i = 0; i < 56; i++) {
					currentLevelMap[i] = 0;
				}
				showIntro = 1;
				logoPos = -640;
				raster1Pos = 396;
				raster2Pos = 460;
				scrollTextPtr = 0;
				introTicker = 0;
				wipePos = -20;
				diagPtr = 0;
				add = 0;
				r = 0;
				g = 0;
				b = 0;
				selectLevel = 0;
				lastPos = 0;
				for (i = 0; i < 32; i++) {
					scrollPos[i] = lastPos;
					scrollBuffer[i] = 0;
					lastPos += charWidth[scrollBuffer[i]];
				}
			}
		}
	}
}

function updateDrone() {
	if (showGameOver == 0) {
		if ((currentX != targetX) || (currentY != targetY)) {
			if ((currentX != targetX) && (currentY != targetY)) {
				if (currentX < targetX) {
					currentX += 8 * diagonalMove[diagPtr];
				} else if (currentX > targetX) {
					currentX -= 8 * diagonalMove[diagPtr];
				} 
				if (currentY < targetY) {
					currentY += 8 * diagonalMove[diagPtr];
				} else if (currentY > targetY) {
					currentY -= 8 * diagonalMove[diagPtr];
				}
				if (diagPtr < 9) {
					diagPtr++;
				} else {
					diagPtr = 0;
				}
			} else {
				if (currentX < targetX) {
					currentX += 8;
				} else if (currentX > targetX) {
					currentX -= 8;
				} else if (currentY < targetY) {
					currentY += 8;
				} else if (currentY > targetY) {
					currentY -= 8;
				}
			}
		} else {
			droneActive = 0;
			droneAnimPtr = 1;
		}
	}
}

function intro() {
	if (raster1Pos > 332) {
		raster1Pos--;
	} else {
		raster1Pos = 459;
	}
	if (raster2Pos > 332) {
		raster2Pos--;
	} else {
		raster2Pos = 459;
	}
	ctx.drawImage(raster, 0, raster1Pos);
	ctx.drawImage(raster, 0, raster2Pos);

	if (selectLevel == 0) {
		if (nameEntry == 1) {
			ctx.drawImage(introoverlay, 0, 0);
			ctx.drawImage(logo, logoPos, 20);
			ctx.drawImage(entryoverlay, 0, 0);			
			lastPos = 0;
			for (i = 0; i < 32; i++) {
				if ((scrollPos[i] < 680) && (scrollPos[i] > 0)) {
					ctx.drawImage(bigfont, (scrollBuffer[i] * 32), 0, charWidth[scrollBuffer[i]], 32, scrollPos[i] - 32, 428, charWidth[scrollBuffer[i]], 32);
				}
				lastPos += charWidth[scrollBuffer[i]];
			}

			if (logoPos < 0) {
				logoPos += 20;
			}
			
			for (i = 0; i < 32; i++) {
				if (scrollPos[i] >= 4) {
					scrollPos[i] -= 4;
				} else {
					scrollTextPtr++;
					if (scrolltext.charCodeAt(scrollTextPtr) == 42) {
						charData = 0;
						scrollTextPtr = 0;
					} else {
						charData = (scrolltext.charCodeAt(scrollTextPtr) - 32);
					}
					if (charData > 64) {
						charData -= 64;
					} else if (charData != 0) {
						switch(charData) {
							case 1: 
								charData = 29;
								break;
							case 3: 
								charData = 30;
								break;
							case 12: 
								charData = 27;
								break;
							case 13: 
								charData = 31;
								break;
							case 14: 
								charData = 28;
								break;
							case 31: 
								charData = 32;
								break;
						}
					}
					scrollPos[i] = lastPos - (0 - (scrollPos[i] - 4));
					scrollBuffer[i] = charData;
				}
			}
			ctx.drawImage(keyboard, 34, 46);
			keyChar = "";
			if ((mouseX > 493) && (mouseX < 579) && (mouseY > 308) && (mouseY < 359)) {
				ctx.drawImage(keyoverlay1, 492, 306);
				keyChar = "1";
			} else if ((mouseX > 445) && (mouseX < 579) && (mouseY > 372) && (mouseY < 423)) {
				ctx.drawImage(keyoverlay2, 444, 370);
				keyChar = " ";
			} else {
				for (i = 0; i < 11; i++) {
					if (((mouseX - 62) - (i * 48) >= 0) && ((mouseX - 62) - (i * 48) <= 36)) {
						if ((mouseY > 244) && (mouseY < 295)) {
							ctx.drawImage(keyoverlay, ((i * 48) + 60), 242);
							keyChar = charMap0[i];
						} else if ((mouseY > 308) && (mouseY < 359)) {
							ctx.drawImage(keyoverlay, ((i * 48) + 60), 306);
							keyChar = charMap1[i];
						} else if ((mouseY > 372) && (mouseY < 423)) {
							ctx.drawImage(keyoverlay, ((i * 48) + 60), 370);
							keyChar = charMap2[i];
						}
					}
				}
			}
			
			for (i = 0; i < 10; i++) {
				charData = (playername.charCodeAt(i) - 32);
				if (charData > 64) {
					charData -= 64;
				} else if (charData == 14) {
					charData = 28;
				}
				ctx.drawImage(scorefont, (charData * 32), 0, 32, 32, (i * 42) + 116, 150, 32, 32);
			}
			if (droneAnimPtr < 27) {
				droneAnimPtr++;
			} else {
				droneAnimPtr = 0;
			}
			ctx.drawImage(cursor, 0, (cursorAnim[droneAnimPtr] * 5), 30, 5, (116 + (currentKeyChar * 42)), 180, 30, 5);
		} else {
			if (introTicker < 1200) {
				introTicker++;
			} else {
				introTicker = 0;
				wipePos = 0;
				loaderror = 1;
				makeRequest("load");
			}
			plasma();
			ctx.drawImage(introoverlay, 0, 0);
			if (introTicker < 400) {
				if (introTicker < 82) {
					if (wipePos < 640) {
						wipePos += 8;
					}
				} else if (introTicker > 317) {
					if (wipePos > -20) {
						wipePos -= 8;
					}
				}
				ctx.drawImage(wipe0, wipePos, 194);
				ctx.drawImage(wipe3, (0 - wipePos), 211);
				ctx.drawImage(wipe0, wipePos, 258);
				ctx.drawImage(wipe3, (0 - wipePos), 275);
				ctx.drawImage(wipe0, wipePos, 322);
				ctx.drawImage(wipe3, (0 - wipePos), 339);
				ctx.drawImage(credits1overlay, 0, 190);
			} else if (introTicker < 800) {
				if (introTicker == 400) {
					wipePos = -20;
				}
				if (introTicker < 482) {
					if (wipePos < 640) {
						wipePos += 8;
					}
				} else if (introTicker > 717) {
					if (wipePos > -20) {
						wipePos -= 8;
					}
				}
				ctx.drawImage(wipe2, (0 - wipePos), 194);
				ctx.drawImage(wipe1, wipePos, 211);
				ctx.drawImage(wipe2, (0 - wipePos), 258);
				ctx.drawImage(wipe1, wipePos, 275);
				ctx.drawImage(wipe2, (0 - wipePos), 322);
				ctx.drawImage(wipe1, wipePos, 339);
				ctx.drawImage(credits2overlay, 0, 190);
			} else {
				if (introTicker == 800) {
					wipePos = -20;
				}
				if (introTicker < 882) {
					if (wipePos < 640) {
						wipePos += 8;
					}
				} else if (introTicker > 1117) {
					if (wipePos > -20) {
						wipePos -= 8;
					}
				}
				ctx.drawImage(wipe1, wipePos, 192);
				ctx.drawImage(wipe2, (-20 - wipePos), 234);
				ctx.drawImage(wipe0, wipePos, 252);
				ctx.drawImage(wipe2, (-20 - wipePos), 270);
				ctx.drawImage(wipe0, wipePos, 288);
				ctx.drawImage(wipe2, (-20 - wipePos), 306);
				ctx.drawImage(wipe0, wipePos, 324);
				ctx.drawImage(wipe2, (-20 - wipePos), 342);
				ctx.drawImage(wipe0, wipePos, 360);
				if (loaderror == 0) {
					ctx.drawImage(scoreoverlay, 0, 190);
					for (i = 0; i < 8; i++) {
						digit0 = 0;
						digit1 = 0;
						for (j = 0; j < 10; j++) {
							k = (hiscoreNames[i].charCodeAt(j) - 32);
							l = (hiscoreNames[(i + 8)].charCodeAt(j) - 32);
							if (k > 64) {
								k -= 64;
							} else {
								k = 0;
							}
							if (l > 64) {
								l -= 64;
							} else {
								l = 0;
							}
							ctx.drawImage(smallfont, (k * 16), 0, 16, 16, 136 + digit0, 234 + (i * 2) + (i * 16), 16, 16);
							ctx.drawImage(smallfont, (l * 16), 0, 16, 16, 472 + digit1, 234 + (i * 2) + (i * 16), 16, 16);
							digit0 += smallWidth[k];
							digit1 += smallWidth[l];
						}
						ctx.drawImage(wipe2, 0, 0, (160 - digit0), 16, 136 + digit0, 234 + (i * 2) + (i * 16), (160 - digit0), 16);
						ctx.drawImage(wipe2, 0, 0, (160 - digit1), 16, 472 + digit1, 234 + (i * 2) + (i * 16), (160 - digit1), 16);
						for (j = 0; j < 6; j++) {
							ctx.drawImage(smallnums, ((hiscoreScores[i].charCodeAt(j) - 48) * 16), 0, 16, 16, 8 + (j * 16), 234 + (i * 2) + (i * 16), 16, 16);
							ctx.drawImage(smallnums, ((hiscoreScores[i + 8].charCodeAt(j) - 48) * 16), 0, 16, 16, 344 + (j * 16), 234 + (i * 2) + (i * 16), 16, 16);
						}
					}
				} else {
					ctx.drawImage(erroroverlay, 0, 190);
				}
			}
			ctx.drawImage(logo, logoPos, 20);
			lastPos = 0;
			for (i = 0; i < 32; i++) {
				if ((scrollPos[i] < 680) && (scrollPos[i] > 0)) {
					ctx.drawImage(bigfont, (scrollBuffer[i] * 32), 0, charWidth[scrollBuffer[i]], 32, scrollPos[i] - 32, 428, charWidth[scrollBuffer[i]], 32);
				}
				lastPos += charWidth[scrollBuffer[i]];
			}

			if (logoPos < 0) {
				logoPos += 20;
			} else {
				if (gameOverBlink < 18) {
					ctx.drawImage(clicktext, 214, 390);
				}
			}
			
			for (i = 0; i < 32; i++) {
				if (scrollPos[i] >= 4) {
					scrollPos[i] -= 4;
				} else {
					scrollTextPtr++;
					if (scrolltext.charCodeAt(scrollTextPtr) == 42) {
						charData = 0;
						scrollTextPtr = 0;
					} else {
						charData = (scrolltext.charCodeAt(scrollTextPtr) - 32);
					}
					if (charData > 64) {
						charData -= 64;
					} else if (charData != 0) {
						switch(charData) {
							case 1: 
								charData = 29;
								break;
							case 3: 
								charData = 30;
								break;
							case 12: 
								charData = 27;
								break;
							case 13: 
								charData = 31;
								break;
							case 14: 
								charData = 28;
								break;
							case 31: 
								charData = 32;
								break;
						}
					}
					scrollPos[i] = lastPos - (0 - (scrollPos[i] - 4));
					scrollBuffer[i] = charData;
				}
			}
		}
	} else {
		ctx.drawImage(introoverlay, 0, 0);
		ctx.drawImage(select, 0, 190);
		if ((mouseX >= 250) && (mouseX <= 274) && (mouseY >= 270) && (mouseY <= 310)) {
			onLeft = 1;
			ctx.drawImage(arrows, 24, 0, 24, 40, 250, 270, 24, 40);
		} else {
			onLeft = 0;
			ctx.drawImage(arrows, 0, 0, 24, 40, 250, 270, 24, 40);
		}
		if ((mouseX >= 365) && (mouseX <= 390) && (mouseY >= 270) && (mouseY <= 310)) {
			onRight = 1;
			ctx.drawImage(arrows, 24, 40, 24, 40, 365, 270, 24, 40);
		} else {
			onRight = 0;
			ctx.drawImage(arrows, 0, 40, 24, 40, 365, 270, 24, 40);
		}
		calcScore(selectedLevel);
		ctx.drawImage(bignums, (digit4 * 32), 0, 32, 32, 288, 277, 32, 32);
		ctx.drawImage(bignums, (digit5 * 32), 0, 32, 32, 320, 277, 32, 32);		
		if (okPtr < 28) {
			okPtr++;
		} else {
			okPtr = 0;
		}
		if ((mouseX >= 282) && (mouseX <= 358) && (mouseY >= 334) && (mouseY <= 366)) {
			ctx.drawImage(ok, 282, 334);
			onOK = 1;
		} else {
			ctx.globalAlpha = okAlpha[okPtr];
			ctx.drawImage(ok, 282, 334);
			ctx.globalAlpha = 1.0;
			onOK = 0;
		}
		ctx.drawImage(logo, logoPos, 20);
		lastPos = 0;
		for (i = 0; i < 32; i++) {
			if ((scrollPos[i] < 680) && (scrollPos[i] > 0)) {
				ctx.drawImage(bigfont, (scrollBuffer[i] * 32), 0, charWidth[scrollBuffer[i]], 32, scrollPos[i] - 32, 428, charWidth[scrollBuffer[i]], 32);
			}
			lastPos += charWidth[scrollBuffer[i]];
		}

		for (i = 0; i < 32; i++) {
			if (scrollPos[i] >= 4) {
				scrollPos[i] -= 4;
			} else {
				scrollTextPtr++;
				if (scrolltext.charCodeAt(scrollTextPtr) == 42) {
					charData = 0;
					scrollTextPtr = 0;
				} else {
					charData = (scrolltext.charCodeAt(scrollTextPtr) - 32);
				}
				if (charData > 64) {
					charData -= 64;
				} else if (charData != 0) {
					switch(charData) {
						case 1: 
							charData = 29;
							break;
						case 3: 
							charData = 30;
							break;
						case 12: 
							charData = 27;
							break;
						case 13: 
							charData = 31;
							break;
						case 14: 
							charData = 28;
							break;
						case 31: 
							charData = 32;
							break;
					}
				}
				scrollPos[i] = lastPos - (0 - (scrollPos[i] - 4));
				scrollBuffer[i] = charData;
			}
		}
	}
}

function game() {
	if (pauseAnim1 < 58) {
		pauseAnim1++;
	} else {
		pauseAnim1 = 8;
	}
	if (pauseAnim2 < 58) {
		pauseAnim2++;
	} else {
		pauseAnim2 = 8;
	}
	if (pulsePtr1 < 27) {
		pulsePtr1++;
	} else {
		pulsePtr1 = 0;
	}
	if (pulsePtr2 < 27) {
		pulsePtr2++;
	} else {
		pulsePtr2 = 0;
	}
	if (showGameOver == 0) {
		if ((droneAnimPtr >= 1) && (droneAnimPtr < 13)) {
			droneAnimPtr++;
			if (droneAnimPtr >= 3) {
				toggleTile();
			}
		} else {
			droneAnimPtr = 0;
		}
	}
	if (drawLevelPtr < 56) {
		currentLevelMap[setupPattern[drawLevelPtr + (currentPattern * 56)]] = setupLevelMap[setupPattern[drawLevelPtr + (currentPattern * 56)]];
	}
	for (j = 0; j < 7; j++) {
		for (i = 0; i < 8; i++) {
			if (currentLevelMap[(j * 8) + i] < 2) {
				ctx.drawImage(eval("tile" + currentLevelMap[(j * 8) + i]), (i * 48) + 221, ((j * 48) + 57));
			} else if (currentLevelMap[(j * 8) + i] < 20) {
				ctx.drawImage(hitiles, (tileBlinkX[(droneAnimPtr - 3)] * 48), (tileBlinkY[(droneAnimPtr - 3)] * 48), 48, 48, (i * 48) + 221, ((j * 48) + 57), 48, 48);
			} else {
				ctx.drawImage(hitiles, (tileBlinkX[(droneAnimPtr - 3)] * 48), (48 - (tileBlinkY[(droneAnimPtr - 3)] * 48)), 48, 48, (i * 48) + 221, ((j * 48) + 57), 48, 48);
			}

			if (drawLevelPtr < 56) {
				if (setupPattern[drawLevelPtr + (currentPattern * 56)] == ((j * 8) + i)) {
					ctx.drawImage(hitiles, 0, (currentLevelMap[(j * 8) + i] * 48), 48, 48, (i * 48) + 221, ((j * 48) + 57), 48, 48);
				}
				if (drawLevelPtr > 0) {
					if (setupPattern[(drawLevelPtr - 1) + (currentPattern * 56)] == ((j * 8) + i)) {
						ctx.drawImage(hitiles, 48, (currentLevelMap[(j * 8) + i] * 48), 48, 48, (i * 48) + 221, ((j * 48) + 57), 48, 48);
					}
				}
				if (drawLevelPtr > 1) {
					if (setupPattern[(drawLevelPtr - 2) + (currentPattern * 56)] == ((j * 8) + i)) {
						ctx.drawImage(hitiles, 96, (currentLevelMap[(j * 8) + i] * 48), 48, 48, (i * 48) + 221, ((j * 48) + 57), 48, 48);
					}
				}
			}
		}
	}		
	if ((showGameOver == 1) || (pauseActive == 1)) {
		ctx.globalAlpha = pauseAlpha;
		ctx.drawImage(pausetiles, 221, 57);
		ctx.globalAlpha = 1.0;
		if (pauseAlpha < 1.0) {
			pauseAlpha += 0.03;
		} else {
			for (j = 0; j < 7; j++) {
				for (i = 0; i < 8; i++) {
					for (k = 0; k < 3; k++) {
						if (pausePattern[pauseAnim1 - k] == ((j * 8) + i)) {
							ctx.drawImage(hipause, (k * 48), 0, 48, 48, (i * 48) + 221, ((j * 48) + 57), 48, 48);
						}
						if (pausePattern[pauseAnim2 - k] == ((j * 8) + i)) {
							ctx.drawImage(hipause, (k * 48), 0, 48, 48, (i * 48) + 221, ((j * 48) + 57), 48, 48);
						}
					}
				}
			}
			showMessage = 1;
			if (showGameOver == 1) {
				if (gameOverBlink < 18) {
					ctx.drawImage(gameovertext, 281, 194);
				}
			} else {
				if (gameOverBlink < 18) {
					ctx.drawImage(pausetext, 334, 194);
				}
			}
			ctx.drawImage(clicktext, 306, 240);
		}
		if (pauseAlpha > 1.0) {
			pauseAlpha = 1.0;
		}
	}
	ctx.drawImage(pulse, (pulseAnim[pulsePtr1] * 8), 0, 8, 12, 345, 40, 8, 12);
	ctx.drawImage(pulse, (pulseAnim[pulsePtr2] * 8), 0, 8, 12, 472, 40, 8, 12);
	ctx.drawImage(pulse, (pulseAnim[pulsePtr2] * 8), 0, 8, 12, 345, 399, 8, 12);
	ctx.drawImage(pulse, (pulseAnim[pulsePtr1] * 8), 0, 8, 12, 472, 399, 8, 12);
	if ((mouseX >= 544) && (mouseX <= 568) && (mouseY >= 450) && (mouseY <= 474)) {
		ctx.drawImage(hibutton, 547, 454);
		ctx.drawImage(lobutton, 576, 454);
	} else if ((mouseX >= 573) && (mouseX <= 597) && (mouseY >= 450) && (mouseY <= 474)) {
		ctx.drawImage(lobutton, 547, 454);
		ctx.drawImage(hibutton, 576, 454);
	} else if ((mouseX > 221) && (mouseX < 605) && (mouseY > 57) && (mouseY < 393)) {
		ctx.drawImage(lobutton, 547, 454);
		ctx.drawImage(lobutton, 576, 454);
		if ((showGameOver == 0) && (pauseActive == 0) && (drawLevelPtr == 56)) {
			if (markerAnimPtr < 9) {
				markerAnimPtr++;
			} else {
				markerAnimPtr = 0;
			}
			ctx.drawImage(marker, (markerAnim[markerAnimPtr] * 48), 0, 48, 48, ((Math.floor((mouseX - 221) / 48) * 48) + 221), ((Math.floor((mouseY - 57) / 48) * 48) +57), 48, 48);
		}
	} else {
		ctx.drawImage(lobutton, 547, 454);
		ctx.drawImage(lobutton, 576, 454);
	}
	ctx.drawImage(schatten, 221, 57);
	if (drawLevelPtr < 56) {
		drawLevelPtr++;
		if (drawLevelPtr == 25) {
			currentX = 221;
			currentY = 57;
		}
		ctx.drawImage(zoomoverlay, 196, 32);
		if (gameInit == 0) {
			ctx.globalAlpha = (droneAlpha[markerZoomPtr]);
			ctx.drawImage(drone, 0, 0, 52, 52, (currentX - Math.floor((droneSize[markerZoomPtr] - 52) / 2)), (currentY - Math.floor((droneSize[markerZoomPtr] - 52) / 2)), droneSize[markerZoomPtr], droneSize[markerZoomPtr]);
		} else {
			if (drawLevelPtr > 25) {
				ctx.globalAlpha = (droneAlpha[markerZoomPtr]);
				ctx.drawImage(drone, 0, 0, 52, 52, (currentX - Math.floor((droneSize[markerZoomPtr] - 52) / 2)), (currentY - Math.floor((droneSize[markerZoomPtr] - 52) / 2)), droneSize[markerZoomPtr], droneSize[markerZoomPtr]);
			}
		}
		ctx.globalAlpha = 1.0;
		markerZoomPtr++;		
	} else {
		ctx.globalAlpha = (1.0 - pauseAlpha);
		ctx.drawImage(drone, (droneAnim[droneAnimPtr] * 52), 0, 52, 52, currentX, currentY, 52, 52);
		ctx.globalAlpha = 1.0;
	}
	if (drawLevelPtr == 55) {
		currentTime = levels[((level - 1) * 8) + 7];
		timeTicker = 0;
		gameInit = 0;
	}

	if (score < targetScore) {
		if ((targetScore - score) > 100) {
			score += 10;
		} else if ((targetScore - score) > 50) {
			score += 5;
		} else if ((targetScore - score) > 30) {
			score += 3;
		} else {
			score++;
		}
	} else {
		score = targetScore;
	}	
	calcScore(score);
	ctx.drawImage(gamenums, (digit0 * 24), 0, 18, 36, 36, 62, 18, 36);
	ctx.drawImage(gamenums, (digit1 * 24), 0, 18, 36, 56, 62, 18, 36);
	ctx.drawImage(gamenums, (digit2 * 24), 0, 18, 36, 76, 62, 18, 36);
	ctx.drawImage(gamenums, (digit3 * 24), 0, 18, 36, 96, 62, 18, 36);
	ctx.drawImage(gamenums, (digit4 * 24), 0, 18, 36, 116, 62, 18, 36);
	ctx.drawImage(gamenums, (digit5 * 24), 0, 18, 36, 136, 62, 18, 36);
	
	if ((drawLevelPtr == 56) && (pauseActive == 0)) {
		if (timeTicker < 30) {
			timeTicker++;
		} else {
			timeTicker = 0;
			if (currentTime > 0) {
				currentTime--;
				targetScore++;
			} else {
				showGameOver = 1;
			}
		}
	}

	calcScore(level);
	ctx.drawImage(gamenums, (digit4 * 24), 0, 18, 36, 78, 179, 18, 36);
	ctx.drawImage(gamenums, (digit5 * 24), 0, 18, 36, 98, 179, 18, 36);
	
	calcScore(currentTime);
	ctx.drawImage(gamenums, (digit4 * 24), 0, 18, 36, 78, 296, 18, 36);
	ctx.drawImage(gamenums, (digit5 * 24), 0, 18, 36, 98, 296, 18, 36);
	if (droneActive == 1) {
		updateDrone();
	}
}

function plasma() {
	add++;
	for (i = 0; i < 320; i++) {
		color1 = (plasmaSine[((i) + (add * 4)) & 511] * 64) + (plasmaSine[((i / 4) + (add / 4)) & 511] * 256);
		for (j = 0; j < 192; j++) {
			color2 = (plasmaSine[((j) + (add * 8)) & 511] * 32) + (plasmaSine[((j) + (add / 8)) & 511] * 128);
			currentColor = ((color1 + color2) / 512) & 255;
			plasmaPix[((j * 320) + i) * 8] = paletteR[currentColor];
			plasmaPix[((j * 320) + i) * 8 + 1] = paletteG[currentColor];
			plasmaPix[((j * 320) + i) * 8 + 2] = paletteB[currentColor];
			plasmaPix[((j * 320) + i) * 8 + 3] = 255;
			plasmaPix[((j * 320) + i) * 8 + 4] = paletteR[currentColor];
			plasmaPix[((j * 320) + i) * 8 + 5] = paletteG[currentColor];
			plasmaPix[((j * 320) + i) * 8 + 6] = paletteB[currentColor];
			plasmaPix[((j * 320) + i) * 8 + 7] = 255;
		}
	}
	ctx.putImageData(plasmaBuffer, 0, 190);
}