/**
 * Created with JetBrains WebStorm.
 * User: ankit.goel
 * Date: 9/27/12
 * Time: 3:42 PM
 * To change this template use File | Settings | File Templates.
 */
ig.module(
    'game.main'
)
    .requires(
    'impact.game',
    'game.entities.player',
    'game.entities.ball1',
    'game.entities.ball10',
    'game.entities.foodconsumed10',
    'game.entities.foodconsumed1',
    'game.entities.foodconsumed100',
    'game.entities.busting',
    'game.entities.reward',
    'plugins.scale',
    'game.entities.reward_second',
    'game.entities.endanimation',
	'game.entities.textBoxAnimation'
	)
    .defines(function(){
        MyGame = ig.Game.extend({
            canvasCenter:{},
            clearColor:null,
            MinimumNoOfYellow:10,
			MinimumNoOfPink:3,
            NumberOfOne:0,
            NumberOfTen:0,
            NumberOfHundred:0,
            blob_life_min:500,
            blob_life_max:1500,
            preRender:true,
            CurrentLevel:1,
            grider:0,
            poolsize:13,
            isfadeOutActivated:false,
            temp:0,  //Its an temporary variable can be used any where for just a instance storage.
            score:value_json.initail_Score,   
            levelDescription:{TotalScore:100,TotalLevel:3,grandTotal:0,range:[{min:20,max:25},{min:26,max:35},{min:40,max:50}],level:[{target:23,score:0},{target:35,score:0},{target:42,score:0}]},
            balls:[
            {animSheet:new ig.AnimationSheet('media/1.png', 12, 11), worth:value_json.ball1_worth, size:{x:12, y:11}},
            {animSheet:new ig.AnimationSheet('media/10.png', 57, 50), worth:value_json.ball10_worth, size:{x:57, y:50}}
            ],
            selectedGrid:[],
            isLongPressActivated:false,
               init:function(){
               this.canvasCenter.x = parseInt(ig.system.canvas.width / 2);
               this.canvasCenter.y = parseInt(ig.system.canvas.height / 2);
               
               //This code to place player in center..
               //  this.BindKey();
                this.temp = new EntityPlayer();
               
               this.spawnEntity(EntityPlayer, (ig.system.width - this.temp.animSheet.width) / 2, (ig.system.height - this.temp.animSheet.height) / 2, {name:"player_organism",type:ig.Entity.TYPE.A,
		       collides:ig.Entity.COLLIDES.PASSIVE,checkAgainst:ig.Entity.TYPE.B,  bounciness:1});
               this.spawnEntity(Entitybust,ig.system.width+100,ig.system.height +100, {name:"organism_bust"});
             
             
             /*  for (var i = 0;i<this.poolsize; i++) {
               this.checkScreenForSmallFood1();            
			   }*/         

            $('#canvas_background').css('background','url(media/background.png)');
			$('#gameTitle').css('display','block');    		
			//  ActivateGameSequenceWise(currentInstructionStatus);
            this.GameLogic();
			$('#game_info_container').css('display','block');
            },
         
            getRandomInt:function (min, max) {
                return Math.floor(Math.random()*(max-min +1))+min;
            },
            update:function () {
			       this.parent();
            },
            BindKey:function(){
            ig.input.bind(ig.KEY.MOUSE1,'pull');
            },

      
				static_entity_creator:function(EntityName,a,isInitialScale){
                //var mov = ig.game.getXY();
				var aP=this.getRandomInt(0,this.customCanvasPositionArrayForTut.length);
				//Math.floor((Math.random()*this.customCanvasPositionArrayForTut.length)+1);
				
				if(aP=='undefined')return false;
				var checkforNearByCenter={
				xMin:(ig.system.width/2)-200,xMax:(ig.system.width/2)+200,
				yMin:(ig.system.height/2)-50,yMax:(ig.system.height/2)+150
				}		
				var mov=[this.getRandomInt(checkforNearByCenter.xMin,checkforNearByCenter.xMax),this.getRandomInt(checkforNearByCenter.yMin,checkforNearByCenter.yMax)];
				//var mov=[this.getRandomInt(this.customCanvasPositionArrayForTut[aP].xMin,this.customCanvasPositionArrayForTut[aP].xMax),this.getRandomInt(this.customCanvasPositionArrayForTut[aP].yMin,this.customCanvasPositionArrayForTut[aP].yMax)];

			        var nn=ig.game.spawnEntity(EntityName, mov[0], mov[1],{
                    positionChecker:true,
                    IdIdentifier:ig.game.getRandomId(),
                    animSheet:ig.game.balls[a].animSheet,
                    worth:ig.game.balls[a].worth,
                    size:ig.game.balls[a].size,
                    type:ig.Entity.TYPE.B,
                    gridposition:mov[2],
                    pixcaltype:"B",
                 //   colision:true,
                    scaleCount:1,
                    collides:ig.Entity.COLLIDES.PASSIVE,
                    bounciness:1,
                    zIndex:2,
                    checkAgainst:ig.Entity.TYPE.B,
                    init:function (x, y, settings) {
                        this.parent(x, y, settings);
                        this.addAnim('idle', 1, [0]);
                        //var mover = this.getOuterRandomMotion();
                        this.vel.x = 0;//mover[0];
                        this.vel.y = 0;//mover[1];
                        this.id = ++ig.Entity._lastId;
                        this.pos.x = x;
                        this.pos.y = y;

                        /*default code for initialization for init ends here*/
                    }
                });
                if(isInitialScale){
                    nn.setScale(.1,.1)
                    nn.isInitialScale=isInitialScale;
                }
                return nn;
             },
            
            entityCreater1:function (EntityName, a, isInitialScale) {
              var mov = ig.game.getXY();
				 ig.game.selectedGrid.push(mov[2]); 
		          var nn=ig.game.spawnEntity(EntityName, mov[0], mov[1], {
                    positionChecker:true,
                    IdIdentifier:ig.game.getRandomId(),
                    animSheet:ig.game.balls[a].animSheet,
                    worth:ig.game.balls[a].worth,
                    size:ig.game.balls[a].size,
                    type:ig.Entity.TYPE.B,
                    gridposition:mov[2],
                    pixcaltype:"B",
					//   colision:true,
                    scaleCount:1,
                    collides:ig.Entity.COLLIDES.PASSIVE,
                    bounciness:1,
                    zIndex:2,
                    checkAgainst:ig.Entity.TYPE.B,
                    init:function (x, y, settings) {
                        this.parent(x, y, settings);
                        this.addAnim('idle', 1, [0]);
                        var mover = this.getOuterRandomMotion();
                        this.vel.x = mover[0];
                        this.vel.y = mover[1];
                        this.id = ++ig.Entity._lastId;
                        this.pos.x = x;
                        this.pos.y = y;

                        /*default code for initialization for init ends here*/
                    }
                });
                if(isInitialScale){
                    nn.setScale(.1,.1)
                    nn.isInitialScale=isInitialScale;
                }
                return nn;
            },
            entityCreater:function (EntityName, a) {
                var mov = ig.game.getOutsideXY();
               ig.game.selectedGrid.push(mov[2]);
                var nn=ig.game.spawnEntity(EntityName, mov[0], mov[1], {
                    positionChecker:true,
                    IdIdentifier:ig.game.getRandomId(),
                    animSheet:ig.game.balls[a].animSheet,
                    worth:ig.game.balls[a].worth,
                    size:ig.game.balls[a].size,
                    type:ig.Entity.TYPE.B,
                    gridposition:mov[2],
                    pixcaltype:"B",
                    scaleCount:1,
                    collides:ig.Entity.COLLIDES.PASSIVE,
                    bounciness:1,
                    zIndex:2,
                    checkAgainst:ig.Entity.TYPE.B,
                    init:function (x, y, settings) {
                        this.parent(x, y, settings);
                        this.addAnim('idle', 1, [0]);
                        var mover = this.getInnerRandomMotion();
                        this.vel.x = mover[0];
                        this.vel.y = mover[1];
                        this.id = ++ig.Entity._lastId;
                        this.pos.x = x;
                        this.pos.y = y;
                        /*default code for initialization for init ends here*/
                    }
                });
                return nn;
             },
         
            draw:function () {
                    ig.system.context.clearRect(0,0,ig.system.realWidth, ig.system.realHeight);
                    this.parent();
               },
            touches:function (other) {
              this.parent();
            },
            getXY:function () {
             var flag=true ,pp,aa, pl=ig.game.getEntitiesByType('EntityPlayer')[0];
			if (typeof pl != 'undefined' || pl != null){              
			if(pl != 0){
			while(flag){
                 pp= this.getRandomInt(0,this.canvasPositionArray.length-1);
                 aa= [this.getRandomInt(this.canvasPositionArray[pp].xMin+10, this.canvasPositionArray[pp].xMax-10), this.getRandomInt(this.canvasPositionArray[pp].yMin+10, this.canvasPositionArray[pp].yMax-10),pp];
                 if(!this.between(aa[0],pl.pos.x,pl.pos.x+pl.size.x) &&!this.between(aa[1],pl.pos.y,pl.pos.y+pl.size.y) && this.isInSelectedGrid(pp)){
                 flag=false;
                 break;
                 }
                 }
                 return aa;
				 }
				 }
				 return [0,0,0];
            },  between:function (x, min, max) {
                return x >= min && x <= max;
            },
            isInSelectedGrid:function(aa){
            this.temp=ig.game.selectedGrid;
                for(var i=0;i<this.temp.length;i++){
                if(this.temp[i]==aa){
                return false;
                    }
                }
            return true;
            },
              unbindKey:function(){
			ig.input.unbind(ig.KEY.MOUSE1);

            },
            getOutsideXY:function () {
                this.temp = this.getRandomInt(0,this.canvasPositionOutSide.length-1);
                return [this.getRandomInt(this.canvasPositionOutSide[this.temp].xMin, this.canvasPositionOutSide[this.temp].xMax),this.getRandomInt(this.canvasPositionOutSide[this.temp].yMin, this.canvasPositionOutSide[this.temp].yMax)];
            },
			updateGameVariables:function(){
                ig.game.levelDescription.level[(this.CurrentLevel-1)].score=this.score;
                textHighlight();

				document.getElementById('score').innerHTML=numberWithCommas(ig.game.levelDescription.level[(this.CurrentLevel-1)].score);//this.levelDescription.level[0].target;
                if(this.levelDescription.grandTotal==this.levelDescription.TotalScore){ //game end....
					this.unbindKey();
               		document.getElementById('gameTotal').innerHTML=ig.game.levelDescription.grandTotal;
                    setTimeout(function(){
                        var temp;
                         temp=ig.game.getEntitiesByType(EntityBall1);
                         if(temp!='undefined'){
                         for(var i=0;i<temp.length;i++){
                             temp[i].kill();
                         }
                     }
                     temp=ig.game.getEntitiesByType(EntityBall10);
                     if(temp!='undefined'){
                         for(var i=0;i<temp.length;i++){
                             temp[i].kill();
                         }
                     }
                     var pl=  ig.game.getEntitiesByType(EntityPlayer)[0];
                     pl.vel.x=0;
                     pl.vel.y=0;
                        //moving to center
						// playGameComplete();
                         pl.friction={x:0,y:0};
                        pl.isGameEndActivated=true;

                        pl.lastTouch.x=(ig.system.width)/ 2  ;
                        pl.lastTouch.y=(ig.system.height) / 2 ;
                        pl.isTouchTrue = true;
						var angle = pl.customAngleTo(pl.lastTouch);
                        pl.currentAngle = angle;
                        pl.currentSpeed = pl.baseSpeed *2 	//*parseInt(Math.round(pl.customDistanceTo(pl.lastTouch)/100,0));
                        var x = Math.cos(angle);
                        var y = Math.sin(angle);
						if(pl.currentSpeed<0 && pl.currentSpeed>1){
						pl.pos.x=(ig.system.width) / 2;
						pl.pos.y=(ig.system.height) / 2;
						}else{
						pl.vel.x = x * pl.currentSpeed;//*ig.system.tick;
                        pl.vel.y = y * pl.currentSpeed;//*ig.system.tick;
						}                 
					//	setCourseCompleted();//Scorm method to specifying the completion of the game.
						},300)

                    return false;
                    //Game exit point
                }
                //  this.levelDotsChanger();
				//document.getElementById('level').innerHTML=this.CurrentLevel;
		        if(this.score==ig.game.levelDescription.level[(this.CurrentLevel-1)].target){
					ig.input.bind(ig.KEY.MOUSE1);
					this.temp=ig.game.getEntitiesByType(EntityPlayer)[0];
					//this.temp.isEatingInProgress=true;
					this.levelChanger();
                }
                if(this.score>ig.game.levelDescription.level[(this.CurrentLevel-1)].target)
                {
				   
                    this.busting();
                }
			},
            gameEnd:function(){
                var pl=  ig.game.getEntitiesByType(EntityPlayer)[0];
                pl.vel.x=0;
                pl.vel.y=0;
                var pos=pl.pos;
             /*
               ig.game.killConsumedFoodEntity();
               ig.game.cleanScreen();*/
                    this.temp=ig.game.getEntitiesByType(EntityBall1);
                    if(this.temp!='undefined'){
                    for(var i=0;i<this.temp.length;i++){
                    this.temp[i].kill();
                        }
                    }
                    this.temp=ig.game.getEntitiesByType(EntityBall10);
                    if(this.temp!='undefined'){
                    for(var i=0;i<this.temp.length;i++){
                    this.temp[i].kill();
                    }
                    }
            var ll=new Entityendanimation();
            pl= ig.game.spawnEntity(Entityendanimation,(ig.system.width -ll.animSheet.width )/2,(ig.system.height-ll.animSheet.height)/2,{});
               // pl= ig.game.spawnEntity(Entityendanimation,(ig.system.width -(ll.animSheet.width *0.1))/2,(ig.system.height-(ll.animSheet.height*0.1))/2,{});
              //    pl.setScale(.1,.1);
                },

			    busting:function(){
				    
					var ent10=ig.game.getEntitiesByType(EntityBall10);
						if(ent10.length>0 && ent10.length>ig.game.NumberOfTen){
						for(var i=0;i<ig.game.NumberOfTen;i++){
                        ent10[i].BustingKillOptionChecked=true;
                        //ent10[i].kill();
						}
						}

						else if(ent10.length<=ig.game.NumberOfTen && ent10.length>0)
						{
						for(var i=0;i<ent10.length;i++){
                            ent10[i].BustingKillOptionChecked=true;
				        	}
						}


             ent10=ig.game.getEntitiesByType(EntityBall1);
                if(ent10.length>0 && ent10.length>ig.game.NumberOfOne){
                    for(var i=0;i<ig.game.NumberOfOne;i++){
                        ent10[i].BustingKillOptionChecked=true;
                        //ent10[i].kill();
                    }
                }
                else if(ent10.length<=ig.game.NumberOfOne && ent10.length>0)
                {
                    for(var i=0;i<ent10.length;i++){
                        ent10[i].BustingKillOptionChecked=true;
                        //	ent10[i].kill();
                    }
                }
                this.temp=ig.game.getEntitiesByType(EntityPlayer)[0];
                     this.temp.vel.x=0;
                     this.temp.vel.y=0;
               if(typeof foodconsumed1 !="undefined"){
                   if(foodconsumed1 !=0){
                       foodconsumed1.vel.x=0;
                       foodconsumed1.vel.y=0;
                   }
               }
              if(typeof foodconsumed10 !="undefined"){
                   if(foodconsumed10 !=0){
                       foodconsumed10.vel.x=0;
                       foodconsumed10.vel.y=0;
                   }
               }
              if(typeof foodconsumed100 !="undefined"){
                   if(foodconsumed100 !=0){
                       foodconsumed100.vel.x=0;
                       foodconsumed100.vel.y=0;
                   }
               }
                 var bust=ig.game.getEntitiesByType(Entitybust)[0];
                 bust.pos=this.temp.pos;
                 ig.game.poser=this.temp.pos;
                 this.temp.kill();
				playIncorrect();
                 
			if(typeof foodconsumed1 !="undefined"){
                   if(foodconsumed1 !=0){
                       foodconsumed1.pos.x=bust.pos.x+(bust.animSheet.width-foodconsumed1.animSheet.width)/2;
                       foodconsumed1.pos.y=bust.pos.y+(bust.animSheet.height-foodconsumed1.animSheet.height)/2;
                   }
               }
              if(typeof foodconsumed10 !="undefined"){
                   if(foodconsumed10 !=0){
                  foodconsumed10.pos.x=bust.pos.x+(bust.animSheet.width-foodconsumed10.animSheet.width)/2;
                       foodconsumed10.pos.y=bust.pos.y+(bust.animSheet.height-foodconsumed10.animSheet.height)/2;
                   }
               }
              if(typeof foodconsumed100 !="undefined"){
                   if(foodconsumed100 !=0){
                      foodconsumed100.pos.x=bust.pos.x+(bust.animSheet.width-foodconsumed100.animSheet.width)/2;
                       foodconsumed100.pos.y=bust.pos.y+(bust.animSheet.height-foodconsumed100.animSheet.height)/2;
                   }
               }

                 bust.currentAnim=bust.changeAnimationSheet(ig.game.levelDescription.level[(ig.game.CurrentLevel-1)].score,bust).rewind();

	               setTimeout(function(){
                  		var bust=ig.game.getEntitiesByType(Entitybust)[0];
                        for(var i=0;i<ig.game.NumberOfOne;i++){
                            var pppp= ig.game.entityCreater(EntityBall1,0);
                            pppp.name='hello';
                            pppp.pos.x=bust.pos.x+(bust.size.x/2);//foodconsumed1.pos; //ig.game.poser           //
                            pppp.pos.y=bust.pos.y+(bust.size.y/2);                   //ig.game.poser//
                            pppp.speed=300;
                            var mov=pppp.getRandomMovement();
                            pppp.vel.x=mov[0];
                            pppp.vel.y=mov[1];
                            pppp.update();
                        }
		                  for(var i=0;i<ig.game.NumberOfTen;i++){
                            var pppp= ig.game.entityCreater(EntityBall10,1);
                            pppp.name='hello';
                            pppp.pos.x=bust.pos.x+(bust.size.x/2);//foodconsumed1.pos; //ig.game.poser           //
                            pppp.pos.y=bust.pos.y+(bust.size.y/2);
                            pppp.speed=300;
                            var mov=pppp.getRandomMovement();
                            pppp.vel.x=mov[0];
                            pppp.vel.y=mov[1];
                            pppp.update();
                        }
                     ig.game.killConsumedFoodEntity();
                    setTimeout(function(){ //This set time out for changing the velocity of the after busting
                        var abc=ig.game.getEntitiesByType(EntityBall1);
                        var mov;
                        for(var i=0;i<abc.length;i++){
                            if(abc[i].name=='hello'){
                                abc[i].speed=5;
                                mov=abc[i].getRandomMovement();
                                abc[i].vel.x=mov[0];
                                abc[i].vel.y=mov[1];
                                abc[i].update();
                            }
                           }
						abc=  ig.game.getEntitiesByType(EntityBall10);
                        for(var i=0;i<abc.length;i++){
                            if(abc[i].name=='hello'){
                               abc[i].speed=5;
                               mov=abc[i].getRandomMovement();
                               abc[i].vel.x=mov[0];
                               abc[i].vel.y=mov[1];
                               abc[i].update();
                            }
                           }
                    },1500);
                    },1100)
                    setTimeout(function(){
                    var  pp=ig.game.getEntitiesByType(Entitybust);
                    for(var i=0;i<pp.length;i++){
                        pp[i].kill();
                    }
                    ig.game.spawnEntity(EntityPlayer, ig.game.poser.x,ig.game.poser.y, {name:"player_organism"});
                    ig.game.spawnEntity(Entitybust,ig.system.width+100,ig.system.height +100, {name:"organism_bust"});
                    ig.game.levelDescription.grandTotal=ig.game.levelDescription.grandTotal-ig.game.score;
                    ig.game.score=0;
                    ig.game.updateGameVariables();
                    },2500)
            },
            killConsumedFoodEntity:function(){
                if(typeof foodconsumed1 !="undefined"){
                    if(foodconsumed1 !=0){
                        foodconsumed1.kill();
                        foodconsumed1=0;
                    }
                }
                if(typeof foodconsumed10 !="undefined"){
                    if(foodconsumed10 !=0){
                        foodconsumed10.kill();
                        foodconsumed10=0;
                    }
                }
                if(typeof foodconsumed100 !="undefined"){
                    if(foodconsumed100 !=0){
                        foodconsumed100.kill();
                        foodconsumed100=0;
                    }
                }
            },
            recreateGame:function(){
            this.levelAnimation();
               },
			levelChanger:function(){
            this.isfadeOutActivated=true;
			this.selectedGrid.length=0;
		this.CurrentLevel++;
	        this.recreateGame();
		},
            cleanScreen:function(){
                    this.temp=ig.game.getEntitiesByType(EntityBall1);
                    if(this.temp!='undefined'){
			        for(var i=0;i<this.temp.length;i++){
                    this.temp[i].kill();
                    }
                    }
                    this.temp=ig.game.getEntitiesByType(EntityBall10);
                    if(this.temp!='undefined'){
                    for(var i=0;i<this.temp.length;i++){
                    this.temp[i].kill();
                    }
                    }
                    this.temp=ig.game.getEntitiesByType(EntityPlayer)
                    if(this.temp!='undefined'){
                    for(var i=0;i<this.temp.length;i++){
                    this.temp[i].kill();
                    }
                    }
             },

			GameLogic:function(){
			        this.initializeGameVariables();
			        this.initializeHTML();
			},
            initializeHTML:function(){
                  this.levelDotsChanger();
		           document.getElementById('target').innerHTML=numberWithCommas(this.levelDescription.level[0].target);
			       document.getElementById('gameTotal').innerHTML=0;//this.levelDescription.level[0].target;
			      document.getElementById('score').innerHTML=numberWithCommas(value_json.initail_Score);//this.levelDescription.level[0].target;
			},
            initializeGameVariables:function(){
		    this.temp=0;
			for(var i=0;i<(this.levelDescription.TotalLevel-1);i++){
		    this.levelDescription.level[i].target=this.getRandomInt(this.levelDescription.range[i].min,this.levelDescription.range[i].max);
            this.temp=this.temp+this.levelDescription.level[i].target;
		
			}
			this.levelDescription.level[i].target=this.levelDescription.TotalScore-this.temp;
			this.levelDescription.level[0].target=value_json.target_score;
			this.levelDescription.level[1].target=26;
			this.levelDescription.level[2].target=49;

		  },
           levelAnimation:function(){
                            setTimeout(function(){
                            var pl=  ig.game.getEntitiesByType(EntityPlayer)[0];
                            pl.vel.x=0;
                            pl.vel.y=0;
                            var pos=[pl.pos,pl.size];
                            pl.kill();
							playLevelComplete();
                            var ll=new Entityreward_two();
                            pl= ig.game.spawnEntity(Entityreward_two,pos[0].x+pos[1].x/2-ll.size.x/2,pos[0].y+pos[1].y/2-ll.size.y/2,{});
                            pl.currentAnim=(pl.changeRewardAnimationSheet(ig.game.score,pl)).rewind();
                            setTimeout(function(){
                            if (typeof foodconsumed10 != "undefined" ) {
                            if( foodconsumed10 != 0){
                            foodconsumed10.kill();
                            foodconsumed10=0;
                            }
                            }
                            if (typeof foodconsumed1 != "undefined" ) {
                            if( foodconsumed1 != 0){
                            foodconsumed1.kill();
                            foodconsumed1=0;
                            }
                            }
                            var  pl=ig.game.getEntitiesByType(Entityreward_two)[0];
                            var  pos=[pl.pos,pl.size];
                            pl.kill();
                            ig.game.cleanScreen();
                            ig.game.isfadeOutActivated=false;
                            var ll= new Entityreward();
                            ig.game.spawnEntity(Entityreward,pos[0].x+pos[1].x/2-ll.size.x/2,pos[0].y+pos[1].y/2-ll.size.y/2,{});
                            pl=ig.game.getEntitiesByType(Entityreward)[0];
                            pl.currentAnim=(pl.changeRewardAnimationSheet(ig.game.score,pl)).rewind();
                            ig.game.score=0;
                            },500);
                            setTimeout(function(){
							ig.input.bind(ig.KEY.MOUSE1,'pull');
                            var ll = new EntityPlayer();
                            ig.game.getEntitiesByType(Entityreward)[0].kill();
                            var pp=ig.game.spawnEntity(EntityPlayer, (ig.system.width - ll.animSheet.width) / 2, (ig.system.height - ll.animSheet.height) / 2, {name:"player_organism"});
                        	ig.game.levelDotsChanger();
                            document.getElementById('target').innerHTML=numberWithCommas(ig.game.levelDescription.level[(ig.game.CurrentLevel-1)].target);
                            document.getElementById('gameTotal').innerHTML=numberWithCommas(ig.game.levelDescription.grandTotal);     //this.levelDescription.level[0].target;
                            ig.game.updateGameVariables();
                            for (var i = 0; i <ig.game.poolsize; i++) {
                            ig.game.checkScreenForSmallFood1();
                            }
                            },3000);

                            },1000);
             },
            getRandomId:function () {
                            this.temp = "";
                            for (var i = 0; i < 5; i++)
                            this.temp += this.PoolOfRandomStringSelection.charAt(Math.floor(Math.random()*this.PoolOfRandomStringSelection.length));
                            return this.temp;
        },
            levelDotsChanger:function(){
                                this.temp=document.getElementsByClassName('common');
                                this.temp[this.CurrentLevel-1].className +=' current_level_selected';
                                this.temp[this.CurrentLevel-1].className.replace('default_selected_level','');
                                for(var i=0;i<(this.CurrentLevel-1);i++){
                                $(this.temp[i]).removeClass('default_selected_level current_level_selected').addClass('passed_level_selected');
                                }
		},
             PoolOfRandomStringSelection:'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
			canvasPositionOutSide : [
                //Above the Top edge
                {xMin:0, xMax:100, yMin:-10, yMax:-5},
                {xMin:101, xMax:200, yMin:-10, yMax:-5},
                {xMin:201, xMax:300, yMin:-10, yMax:-5},
                {xMin:301, xMax:400, yMin:-10, yMax:-5},
                {xMin:401, xMax:500, yMin:-10, yMax:-5},
                {xMin:501, xMax:600, yMin:-10, yMax:-5},
                {xMin:601, xMax:700, yMin:-10, yMax:-5},
                {xMin:701, xMax:800, yMin:-10, yMax:-5},
       
                //Right side
                {xMin:790 + 5, xMax:790 + 10, yMin:-10, yMax:100},
                {xMin:790 + 5, xMax:790 + 10, yMin:101, yMax:200},
                {xMin:790 + 5, xMax:790 + 10, yMin:201, yMax:300},
                {xMin:790 + 5, xMax:790 + 10, yMin:301, yMax:400},
                {xMin:790 + 5, xMax:790 + 10, yMin:401, yMax:500},
                {xMin:790 + 5, xMax:790 + 10, yMin:501, yMax:600},
                //bottom side of canvas
                {xMin:0, xMax:100, yMin:600, yMax:600 + 10},
                {xMin:101, xMax:200, yMin:600, yMax:600 + 10},
                {xMin:201, xMax:300, yMin:600, yMax:600 + 10},
                {xMin:301, xMax:400, yMin:600, yMax:600 + 10},
                {xMin:401, xMax:500, yMin:600, yMax:600 + 10},
                {xMin:501, xMax:600, yMin:600, yMax:600 + 10},
                {xMin:601, xMax:700, yMin:600, yMax:600 + 10},
         
                //left side of canvas
                {xMin:-30, xMax:1, yMin:0, yMax:100},
                {xMin:-30, xMax:1, yMin:101, yMax:200},
                {xMin:-30, xMax:1, yMin:201, yMax:300},
                {xMin:-30, xMax:1, yMin:301, yMax:400},
                {xMin:-30, xMax:1, yMin:401, yMax:500},
                {xMin:-30, xMax:1, yMin:501, yMax:600}
            ],
			customCanvasPositionArrayForTut:[
            {xMin:501, xMax:600, yMin:0, yMax:116},//2
            {xMin:601, xMax:700, yMin:0, yMax:116},
            {xMin:701, xMax:800, yMin:0, yMax:116},
            {xMin:801, xMax:900, yMin:0, yMax:116},
            {xMin:901, xMax:980, yMin:0, yMax:116},
            //for second grid
        /*    {xMin:10, xMax:100, yMin:116, yMax:232},//3
            {xMin:101, xMax:200, yMin:116, yMax:232},
            {xMin:201, xMax:300, yMin:116, yMax:232},
            {xMin:301, xMax:400, yMin:116, yMax:232},
            {xMin:401, xMax:500, yMin:116, yMax:232},*/

            {xMin:501, xMax:600, yMin:116, yMax:232},//4
            {xMin:601, xMax:700, yMin:116, yMax:232},
            {xMin:701, xMax:800, yMin:116, yMax:232},
            {xMin:801, xMax:900, yMin:116, yMax:232},
            {xMin:901, xMax:980, yMin:116, yMax:232},
            //for third grid
         //   {xMin:10, xMax:100, yMin:232, yMax:348},//5
            //{xMin:101, xMax:200, yMin:232, yMax:348},
          //  {xMin:201, xMax:300, yMin:232, yMax:348},
            {xMin:301, xMax:400, yMin:232, yMax:348},
            {xMin:401, xMax:450, yMin:232, yMax:348},
            //since here ameoba lies so we skip this position
            {xMin:550, xMax:600, yMin:232, yMax:348},//6

            {xMin:601, xMax:700, yMin:232, yMax:348},
            {xMin:701, xMax:800, yMin:232, yMax:348},
            {xMin:10, xMax:100, yMin:348, yMax:580},//7
			{xMin:101, xMax:200, yMin:348, yMax:580},
            {xMin:201, xMax:300, yMin:348, yMax:580},
            {xMin:301, xMax:400, yMin:348, yMax:580},
            {xMin:401, xMax:500, yMin:348, yMax:580},
],
			canvasPositionArray : [
            //For first grid
            {xMin:0, xMax:100, yMin:0, yMax:116},//1
            {xMin:101, xMax:200, yMin:0, yMax:116},
            {xMin:201, xMax:300, yMin:0, yMax:116},
            {xMin:301, xMax:400, yMin:0, yMax:116},
            {xMin:401, xMax:500, yMin:0, yMax:116},

            {xMin:501, xMax:600, yMin:0, yMax:116},//2
            {xMin:601, xMax:700, yMin:0, yMax:116},
            {xMin:701, xMax:800, yMin:0, yMax:116},
            {xMin:801, xMax:900, yMin:0, yMax:116},
            {xMin:901, xMax:980, yMin:0, yMax:116},
            //for second grid
            {xMin:10, xMax:100, yMin:116, yMax:232},//3
            {xMin:101, xMax:200, yMin:116, yMax:232},
            {xMin:201, xMax:300, yMin:116, yMax:232},
            {xMin:301, xMax:400, yMin:116, yMax:232},
            {xMin:401, xMax:500, yMin:116, yMax:232},

            {xMin:501, xMax:600, yMin:116, yMax:232},//4
            {xMin:601, xMax:700, yMin:116, yMax:232},
            {xMin:701, xMax:800, yMin:116, yMax:232},
            {xMin:801, xMax:900, yMin:116, yMax:232},
            {xMin:901, xMax:980, yMin:116, yMax:232},
            //for third grid
            {xMin:10, xMax:100, yMin:232, yMax:348},//5
            {xMin:101, xMax:200, yMin:232, yMax:348},
            {xMin:201, xMax:300, yMin:232, yMax:348},
            {xMin:301, xMax:400, yMin:232, yMax:348},
            {xMin:401, xMax:450, yMin:232, yMax:348},
            //since here ameoba lies so we skip this position
            {xMin:550, xMax:600, yMin:232, yMax:348},//6

            {xMin:601, xMax:700, yMin:232, yMax:348},
            {xMin:701, xMax:800, yMin:232, yMax:348},
            {xMin:10, xMax:100, yMin:348, yMax:580},//7
            {xMin:101, xMax:200, yMin:348, yMax:580},
            {xMin:201, xMax:300, yMin:348, yMax:580},
            {xMin:301, xMax:400, yMin:348, yMax:580},
            {xMin:401, xMax:500, yMin:348, yMax:580},

            {xMin:501, xMax:600, yMin:348, yMax:580},//8
            {xMin:601, xMax:700, yMin:348, yMax:580},
            {xMin:701, xMax:800, yMin:348, yMax:580}
         ]
    });
   ig.main('#canvas',MyGame,60,788,600,1);
    });
