function gatherAssets(){
	assetCount++;
	if ( assetCount >= 6 ) mainFunc();
}

function mainFunc(){
	  touchX = 0;
	  touchY = 0;
	  touchStart = 0;
      randCount = 0;
      rand = [ .702, .763, .307, .572, .955, .543, .120, .464, .682, .815, .672, .848, .719, .485, .149, .640, .804, .309, .231, .077, .978, .245, .857, .870, .572, .663, .125, .135, .447, .015, .578, .969, .990, .808, .902, .758, .341, .191, .501, .425, .465, .493, .514, .880, .986, .369, .566, .856, .130, .992];
      levelCount = 1;
	  document.getElementById( "levelNumber" ).innerHTML = "Level " + levelCount; 
	  document.getElementById( "levelName" ).innerHTML = "Blue Hearts";
	  document.getElementById( "levelDescription" ).innerHTML = "The blue heart is sick, but not contagious. You have 40 seconds to restore all sick creatures to a red heart. Get done early? A 2-finger tap will give you options."
      level = null; 
      document.getElementById( "tempLayer" ).innerHTML = "";
      //document.getElementById( "container" ).style.display = "block";
      screenManager = new ScreenManager();
      screenList = [ "start",  "splash", "level", "congrats", "game", "pause", "failure", "hider" ] ;
      screenManager.showScreen( "splash", "instant", "none", splashScreenPause );
}

function blank(){

}

function splashScreenPause(){
      setTimeout( "screenManager.showScreen( 'start', 'fade', 'in' );", 1000);
}

function createLevel(){
	screenManager.hideScreen('pause');
	screenManager.hideScreen( "failure" );
	screenManager.hideScreen( "success" );
    level = new Level( levelCount ); 
}

function introduceLevel(){
	var namer = "";
                  var descriptor = "";
	switch( levelCount ){
	case 1:
                  	namer = "Blue Hearts";
		descriptor = "The blue heart is sick, but not contagious. You have 40 seconds to restore all sick creatures to a red heart. Get done early? A 2-finger tap will give you options." 
               		break;
	case 2:
		namer = "Green Hearts";
		descriptor = "The Green heart is contagious and will turn a neighbor with a red heart blue. Keep it under the target to turn it to non-contagious blue, and again to cure it completely to red. You have 55 seconds to restore all creatures to a red heart."; 
		break;
	case 3:
		namer = "The Jumps";
		descriptor = "The creatures are jumping! They'll jump if they have a place to land -- if an area is too crowded they won't jump to it. You have 65 seconds to cure the whole lot.";
               		break;
	case 4:
		namer = "Greater Numbers";
		descriptor = "More creatures and another floor to jump to spells trouble! You have 75 seconds to cure them all."; 
             		break;
	case 5:
		namer = "White Hearts";
		descriptor = "The white heart is extremely contagious, changing red hearts to blue, and then blue to green. You have 90 seconds to get everybody back to red."; 
              		break;
	case 6:
		namer = "Quarantine Bubbles!";
               		descriptor = "A quarantine bubble can be placed around a creature by tapping it. These bubbles prevent the spread of disease as well as restricting jumping ability. However, creatures within bubbles cananot be treated. You must remove the bubble with a tap in order to do this. You currently can use up to 2 bubbles at a time.  Cure the creatures in 85 seconds."; 
               		break;
	case 7:
		namer = "Less Time, Another Bubble";
		descriptor = "You now have 3 quarantine bubbles to work with. Cure all creatures in 80 seconds.";
		break;
	case 8:
		namer = "More Guys, Another Bubble";
		descriptor = "You now have 4 quarantine bubbles to work with. Cure all creatures in 120 seconds.";
		break;
	case 9:
		namer = "Less time";
		descriptor = "You still have 4 bubbles, but cure all the creatures in 110 seconds.";
		break;
	case 10:
		namer = "Even less time";
		descriptor = "With the same 4 bubbles, get everybody red in 100 seconds."; 
		break;
         	}
	if ( levelCount == 11 ){
                  	setTimeout( "screenManager.showScreen( 'congrats', 'vert', 'in', blank );", 1500);
	}else{
		document.getElementById( "levelNumber" ).innerHTML = "Level " + levelCount; 
		document.getElementById( "levelName" ).innerHTML = namer;
		document.getElementById( "levelDescription" ).innerHTML = descriptor;
		setTimeout( "screenManager.showScreen( 'level', 'vert', 'in', blank );", 1500);
	}
}

function endLevel(){
	level.scoreLevel();
}

function startLevel(){
       level.setPaused( 0 );
}

function getRand(){
       randCount++;
       if ( randCount == 50 ) randCount = 0;
       return rand[ randCount ];
}

function repeatLevelFrame(){
	  setTimeout( "level.executeOneFrame();", 100 );
}

function updateTouchPos(e){
	touchX = e.touches[0].pageX;
   	touchY = e.touches[0].pageY;
}
function handleTouch(e){
  	updateTouchPos(e);
	if ( e.touches.length > 1 ) touchStart = 2;
                  else touchStart = 1;
}
function handleTouchEnd(){
   	touchStart = -1;
}