var unitTesting=false;
var curlevel=0;
var curlevelTarget=null;
var hasUsedCheckpoint=false;
var levelEditorOpened=false;

function doSetupTitleScreenLevelContinue(){
    try {
     	if (!!window.localStorage) { 
    		if (localStorage[document.URL]!==undefined) {
                if (localStorage[document.URL+'_checkpoint']!==undefined){
                    var backupStr = localStorage[document.URL+'_checkpoint'];
                    curlevelTarget = JSON.parse(backupStr);
                    
                    var arr = [];
                    for(var p in Object.keys(curlevelTarget.dat)) {
                        arr[p] = curlevelTarget.dat[p];
                    }
                    curlevelTarget.dat = new Int32Array(arr);

                }
    	        curlevel = localStorage[document.URL];            
    		}
    	}		 
    } catch(ex) {
    }
}

doSetupTitleScreenLevelContinue();


var verbose_logging=false;
var throttle_movement=false;
var cache_console_messages=false;
var quittingTitleScreen=false;
var quittingMessageScreen=false;
var deltatime=17;
var timer=0;
var repeatinterval=250;
var autotick=0;
var autotickinterval=0;
var winning=false;
var againing=false;
var againinterval=250;
var norepeat_action=false;
var oldflickscreendat=[];//used for buffering old flickscreen/scrollscreen positions, in case player vanishes
var keybuffer = [];
var interpolating = 0;
var displayIndex = 0;

var interpolationInterval=250;
var viewPitch = 0;
var scaleHeight = 1;
var viewDistance = 10;
var viewHeight = 0.5;
var fieldOfView = 60;
var fogPower = 2;
var gradientBottom = "#dfdfdf";
var gradientMiddle = "#ffffff";
var gradientTop = "#cfcfcf";

var restarting=false;

var messageselected=false;

var textImages={};
var initLevel = {
    width: 5,
    height: 5,
    layerCount: 2,
    dat: [
    1, 3, 3, 1, 1, 2, 2, 3, 3, 1,
    2, 1, 2, 2, 3, 3, 1, 1, 2, 2,
    3, 2, 1, 3, 2, 1, 3, 2, 1, 3,
    1, 3, 3, 1, 1, 2, 2, 3, 3, 1,
    2, 1, 2, 2, 3, 3, 1, 1, 2, 2
    ],
    movementMask:[
    1, 3, 3, 1, 1, 2, 2, 3, 3, 1,
    2, 1, 2, 2, 3, 3, 1, 1, 2, 2,
    3, 2, 1, 3, 2, 1, 3, 2, 1, 3,
    1, 3, 3, 1, 1, 2, 2, 3, 3, 1,
    2, 1, 2, 2, 3, 3, 1, 1, 2, 2
    ],
    rigidGroupIndexMask:[],//[indexgroupNumber, masked by layer arrays]
    rigidMovementAppliedMask:[],//[indexgroupNumber, masked by layer arrays]
    bannedGroup:[],
    colCellContents:[],
    rowCellContents:[]
};

var level = initLevel;
