


/*
        __author__ = "john avila"
        __copyright__ = "Copyright 2013,"
        __license__ = "Affero GPL"
        __version__ = "1.0.1"
        __maintainer__ = "john"
	__by__ = "asikersoft"
	
        __email__ = "avilajohn@outlook.com"
        __status__ = "Production"

        */
/*
 * 
 * 
 * 
 music
 s2 intro theme2
Cicalone - IK Plus (extract)
s2 intro theme
Dr Future - Captured (Its A Machines World) (extract)*/
var jsApp =
{
    onload: function()
    {
      var intFrameWidth = window.innerWidth;
      var intFrameHeight = window.innerHeight;
      //debugger;
    //  if (!me.video.init("game", 480 , 320, true, 'auto', false))
        if ( !me.video.init( 'game', intFrameWidth, intFrameHeight ) )
    //  if ( !me.video.init( 'game', 480, 320 ) )
        {
            alert( "Sorry," );
            return;
        }

        me.audio.init( "mp3" );//,ogg

        me.loader.onload = this.loaded.bind( this );
        me.loader.preload( gameResources );

        me.state.change( me.state.LOADING );
	
	
	
    },

    loaded: function()
    {
        me.state.set( me.state.INTRO, new RadmarsScreen() );
       me.state.set( me.state.MENU, new TitleScreen() );
        me.state.set( me.state.PLAY, new PlayScreen() );
        me.state.set( me.state.GAMEOVER, new GameOverScreen() );

        me.state.transition( "fade", "white", 150 );

        me.entityPool.add( "player", Player );
        me.entityPool.add( "enemy", Enemy );
        me.entityPool.add( "Saw", Saw );
        me.entityPool.add( "water", Water );
        me.entityPool.add( "rock", Rock );
        me.entityPool.add( "bomb", Bomb );
        me.entityPool.add( "spikes", Spikes );
        me.entityPool.add( "balloon", Balloon );
        me.entityPool.add( "StoryNode", StoryNode );
        me.entityPool.add( "LevelChanger", LevelChanger );

        me.game.deathCount = 0;

        me.debug.renderHitBox = false;

        me.state.change( me.state.INTRO);
    }
}

var PlayScreen = me.ScreenObject.extend(
{
    /** Session persistence for unlocked abilities. */
    abilities: {
    },

    init: function()
    {
        this.storyDisplay = new StoryDisplay();
        this.levelDisplay = new LevelDisplay();
        this.skillDisplay = new SkillDisplay();

        this.music = "";
    },

    showStoryText: function( text )
    {
        this.storyDisplay.setText( 'storyDisplay', text );
    },

    getLevel: function()
    {
        return this.parseLevel( me.levelDirector.getCurrentLevelId() );
    },

    parseLevel: function( input )
    {
        var re = /level(\d+)/;
        var results = re.exec( input );
        return results[1];
    },

    /** Update the level  changes. */
    changeLevel: function( )
    {
        this.levelDisplay.reset("levelDisplay");
        this.skillDisplay.reset('skillDisplay');

        var curLevel = this.getLevel();

	 var levelnombre =  me.levelDirector.getCurrentLevelId();
		
		if(levelnombre =="level2")
		{
           huskycollect.style.backgroundImage ='url('+me.loader.getImage('barrahusky2').src +')';     
           huskycollect.style.left ="5%";	
			
		}
		if(levelnombre =="level3")
		{
           huskycollect.style.backgroundImage ='url('+me.loader.getImage('barrahusky3').src +')';     
           huskycollect.style.left ="5%";	
			
		}
		
		if(levelnombre =="level4")
		{
           huskycollect.style.backgroundImage ='url('+me.loader.getImage('barrahusky4').src +')';     
           huskycollect.style.left ="5%";	
			
		}
		if(levelnombre =="level5")
		{
           huskycollect.style.backgroundImage ='url('+me.loader.getImage('barrahusky5').src +')';     
           huskycollect.style.left ="5%";	
			
		}
		
		if(levelnombre =="level6")
		{
           huskycollect.style.backgroundImage ='url('+me.loader.getImage('barrahusky6').src +')';     
           huskycollect.style.left ="5%";	
			
		}
		if(levelnombre =="level7")
		{
           huskycollect.style.backgroundImage ='url('+me.loader.getImage('barrahusky7').src +')';     
           huskycollect.style.left ="5%";	
			
		}
		if(levelnombre =="level8")
		{
           huskycollect.style.backgroundImage ='url('+me.loader.getImage('barrahusky8').src +')';     
           huskycollect.style.left ="5%";	
			
		}
		
		/*
		if(levelnombre =="level9")
		{
           huskycollect.style.backgroundImage ='url('+me.loader.getImage('barrahusky9').src +')';     
           huskycollect.style.left ="5%";	
			
		}
		*/
		
        this.lastMusic = this.music;
        if ( curLevel < 2 )
        {
            this.music = "forest";//forest
        }
        else if ( curLevel < 4 )
        {
            this.music = "cave";
        }
         else if ( curLevel >= 8 )
        {
           pantacontinue.style.left= 0+"%";
	   btnreload.style.top= 0+"%";
	   
	    me.state.change( me.state.INTRO);
        }
        else
        {
            this.music = "tech";
        }

        if ( this.lastMusic != this.music )
        {
            me.audio.stopTrack();
            me.audio.playTrack( this.music );
        }
    },

    getCurrentMusic: function()
    {
        return this.music;
    },

    startLevel: function( level )
    {
        // this only gets called on start?
        me.levelDirector.loadLevel( level );
        me.game.sort();
        this.changeLevel();
    },




    
    onResetEvent: function()
    {
       me.game.addHUD( 0, 0, me.video.getWidth(), me.video.getHeight() );
      
     
        me.game.HUD.addItem( "deaths", new DeathDisplay( 15, 15 ) );
        this.startLevel( location.hash.substr(1) || "level1" );
    },

    onDestroyEvent: function()
    {
        me.game.disableHUD();
        me.audio.stopTrack();
    }
});

var RadmarsScreen = me.ScreenObject.extend({
    init: function() {
        this.parent( true );
        this.counter = 0;
    },

    onResetEvent: function() {
        if( ! this.title ) {
            this.bg= me.loader.getImage("intro_bg");
            this.glasses1 = me.loader.getImage("intro_glasses1"); // 249 229
            this.glasses2 = me.loader.getImage("intro_glasses2"); // 249 229
            this.glasses3 = me.loader.getImage("intro_glasses3"); // 249 229
            this.glasses4 = me.loader.getImage("intro_glasses4"); // 249 229
            this.text_mars = me.loader.getImage("intro_mars"); // 266 317
            this.text_radmars1 = me.loader.getImage("intro_radmars1"); // 224 317
            this.text_radmars2 = me.loader.getImage("intro_radmars2");
        }

        me.input.bindKey( me.input.KEY.ENTER, "enter", true );
        me.audio.playTrack( "radmarslogo" );
    },

    update: function() {
        if( me.input.isKeyPressed('enter')) {
            me.state.change(me.state.MENU);
        }
        if ( this.counter < 400 )
        {
            this.counter++;
        }
       
        else{
          me.state.change(me.state.MENU);
	  document.getElementById("btnplay").style.top="40%";
       pantaprincipal2.style.background="black";


	   
		    var  splashpublic = setInterval(function () {
				pt1.style.display="block";
			 pantaprincipal.style.display="none";
			 pantaprincipal2.style.background="transparent";
			 
 			 titulo.style.display="block";
			  facebook.style.display="block";
			   Twitter.style.display="block";
				btnplay.style.display="block";
					btnmapa.style.display="block";
					
					
		 clearInterval(splashpublic);
         }, 1700);
		 
		 
 var  splashpublic2 = setInterval(function () {
					 pantaprincipal2.style.display="none";
					 

					
		
		 clearInterval(splashpublic2);
  }, 2700);
		   
        }
        // have to force redraw :(
        me.game.repaint();
    },

    draw: function(context) {
        context.drawImage( this.bg, 0, 0 );
        if( this.counter < 130) context.drawImage( this.text_mars, 266+80, 317+60 );
        else if( this.counter < 135) context.drawImage( this.text_radmars2, 224+80, 317+60 );
        else if( this.counter < 140) context.drawImage( this.text_radmars1, 224+80, 317+60 );
        else if( this.counter < 145) context.drawImage( this.text_radmars2, 224+80, 317+60 );
        else if( this.counter < 150) context.drawImage( this.text_radmars1, 224+80, 317+60 );
        else if( this.counter < 155) context.drawImage( this.text_radmars2, 224+80, 317+60 );
        else if( this.counter < 160) context.drawImage( this.text_radmars1, 224+80, 317+60 );
        else if( this.counter < 165) context.drawImage( this.text_radmars2, 224+80, 317+60 );
        else context.drawImage( this.text_radmars1, 224+80, 317+60 );

        if( this.counter < 100) context.drawImage( this.glasses1, 249+80, 229*(this.counter/100)+60 );
        else if( this.counter < 105) context.drawImage( this.glasses2, 249+80, 229+60 );
        else if( this.counter < 110) context.drawImage( this.glasses3, 249+80, 229+60 );
        else if( this.counter < 115) context.drawImage( this.glasses4, 249+80, 229+60 );
        else context.drawImage( this.glasses1, 249+80, 229+60 );
					   luna.style.top= 50+"%";
					   
    },

    onDestroyEvent: function() {
        me.input.unbindKey(me.input.KEY.ENTER);
        me.audio.stopTrack();
    }
});

/** WHen coliding with the end of the level do things to swap the levels. */
var LevelChanger = me.LevelEntity.extend({
    init: function( x, y, settings ) {
        this.parent( x, y, settings );

        var fruitSettings = new Object();
        fruitSettings.image = "fruit";
        fruitSettings.spritewidth = 48;

        this.fruit = new me.ObjectEntity( x, y, fruitSettings );
        this.fruit.animationspeed = 3;

        this.fruit.addAnimation( "idle", [ 0, 1, 2, 3, 4, 5 ] );
        this.fruit.addAnimation( "eat", [ 6 ] );
        this.fruit.setCurrentAnimation( "idle" );

        me.game.add( this.fruit, 5 );
        me.game.sort();
    },

    onCollision : function()
    {
        this.fruit.setCurrentAnimation( "eat" );
        me.audio.play( "eat" );
        this.collidable = false;
        // hack to stop drown sound
        if ( me.game.player.drowning )
        {
            me.audio.stop( "drown" );
            me.audio.playTrack( me.state.current().getCurrentMusic() );
        }
        return this.parent();
    },

    /** Dirty hack. I don't think they intended to expose onFadeComplete. */
    onFadeComplete : function () {
        this.parent();
        me.state.current().changeLevel( );


    },

    goTo: function ( level ) {
        // hack bad. bad hack TODO
        if ( this.gotolevel == "gameover" ) {
            me.state.change( me.state.GAMEOVER );
           windowGAMEOVER.style.display="block";

		  return;
        }
        this.parent( level );

        // When we swap levels the correct way, we should 0 out any skills we've
        // learned.
        for( var skill in me.state.current().abilities  ) {
            me.state.current().abilities[skill] = false;
        }
		
		
				if (navigator.onLine) {
      cortina.style.display="block";
		
		var cortina1= setInterval(function () {
		cortina.style.backgroundColor="transparent";
	btncontinuep.style.left="10%";
        clearInterval(cortina1);
        }, 1000);
		
		var cortina2= setInterval(function () {
      ventanapublicidadprincipal.style.display="block";
	   cortina.style.display="none";
	 clearInterval(cortina2);
        }, 2000);
		
		
	}else
	{
		
		
	}
	
	
    }
});

var TemporaryDisplay = me.HUD_Item.extend({
    init: function( x, y, settings ) {
        settings = settings || {};
        this.parent( x, y, settings );
        this.font = settings.font || new me.BitmapFont( "32x32_font", 32 );
        this.font.set("left", 1);
        this.timeout = 2000;
    },

    /** Adds the display and resets the object. After a X ms timeout the
     * object goes away. */
    reset: function( item ) {
        this.parent();
        // TODO might be redundant if we call this again before timeout?
        me.game.HUD.addItem( item, this );
        window.setTimeout( function() {
            me.game.HUD.removeItem( item );
        }, this.timeout );
    },

    /** This should be overwritten. */
    getText: function() {
        return '';
    },

    /** Draws the text. Newlines are split out by font size. */
    draw: function( context, x, y ) {
        var lines = this.getText().split( "\n" );
        for( var i = 0; i < lines.length; i++ ) {
            this.font.draw(
                context,
                lines[i].toUpperCase(),
                this.pos.x + x,
                this.pos.y + y + i * this.font.size.y
            );
        }
    }
});

var SkillDisplay = TemporaryDisplay.extend({
    init: function() {
        this.parent( 50, 100, {
            font: new me.BitmapFont( "16x16_font", 16),
        });
        this.text = '';
        this.timeout = 5000;
    },

    skill: function( item ) {
        if( item == 'doubleJump') return 'double jump';
        if( item == 'shield') return 'shield one hit';
        if( item == 'spikeHat') return 'poke things with your head';
        if( item == 'buttStomp' ) return 'buttstomp (press c)';
        if( item == 'rocketJump' ) return 'ride the rocket (press v)';
        if( item == 'wallStick' ) return 'claw into the wall';
        // fallback...
        return item;
    },

    getText: function() {
        var abilities = me.state.current().abilities;
        var t = '';
        for( var item in abilities ) {
            if( abilities[item] != undefined ) {
                if ( item == 'gills' )
                {
                    t += "You have ";
                    t += ( abilities[item] ? this.skill( item ) : "lungs" );
                    t += "\n";
                }
                else
                {
                    t += "You ";
                    t += ( abilities[item] ? "can " : "can't " );
                    t += this.skill( item )
                    t += "\n";
                }
            }
       }
       return t;
    }
});

/* Story display could probably go away but it just displays a single text blob
 * on events. */
var StoryDisplay = TemporaryDisplay.extend({

    init: function( ) {
        this.parent( 50, 80, {
            font: new me.BitmapFont( "16x16_font", 16),
        });
        this.text = '';
    },

    setText: function( uiname, text ) {
        this.reset( uiname );
        this.text = text;
    },

    getText: function () {
        return this.text;
    }
});

var LevelDisplay = TemporaryDisplay.extend({
    init: function( ) {
        this.parent( 30, me.video.getHeight() *0.35, {
            font: new me.BitmapFont( "64x64_font", 64),
        } );
    },
    getText: function() {
        return "LEVEL " + me.state.current().getLevel();
    }
});

var StoryNode = me.InvisibleEntity.extend({
    init: function( x, y, settings ) {
        this.parent( x, y, settings );
        this.text = settings.text;
        this.toggled = false;
    },

    // only check collision with player, & only first time - prevents other stuff from hitting it & not other things (no multiple collision)
    checkCollision: function( obj ) {
        if ( obj == me.game.player && !this.toggled ) {
            return this.parent( obj );
        }
        return null;
    },

    onCollision: function() {
        if( ! this.toggled ) {
            me.state.current().showStoryText( this.text );
            this.toggled = true;
        }
    }
});

var TitleScreen = me.ScreenObject.extend(
{
    init: function()
    {
        this.parent( true );
        this.yCounter = 0;
		this.blinkCounter = 0;
    },

    onResetEvent: function()
    {
        if ( !this.backgroundImg )
        {
            this.backgroundImg = me.loader.getImage( "title_bg" );
            this.cta = me.loader.getImage( "title_cta" );
            this.overlay = me.loader.getImage( "title_overlay" );
        }
//here john
 // debugger
      me.input.bindKey( me.input.KEY.ENTER, "enter", true );
        me.audio.playTrack( "theme" );
    },

    update: function()
    {
        if( me.input.isKeyPressed( 'enter' ) )
        {
            me.state.change( me.state.PLAY );
	    
	        btnreload.style.right= "-100%";
	 
	 document.getElementById("btnplay").style.left="-100%";
	
	      	document.getElementById("facebook").style.left="-100%";
		
		
		document.getElementById("Twitter").style.left="-100%";
        }
        this.updateScroll();
    },

    updateScroll: function()
    {
        this.yCounter++;
        if ( this.yCounter > window.innerWidth )
        {
            this.yCounter = 0;
        }

        me.game.repaint();
    },

    draw: function( context )
    {
        // draw 2 backgrounds to scroll properly
        context.drawImage( this.backgroundImg, 0, 0 - this.yCounter ,window.innerWidth,window.innerHeight);
        context.drawImage( this.backgroundImg, 0, 0 - this.yCounter + window.innerWidth,window.innerWidth,window.innerHeight );
        context.drawImage( this.overlay, -80, -140);
        
		this.blinkCounter++; 
		if( this.blinkCounter > 20){
				context.drawImage( this.cta, window.innerWidth/2,window.innerHeight/2 );
				if(this.blinkCounter > 40) this.blinkCounter =0;
		}
		
    },

    onDestroyEvent: function()
    {
        me.input.unbindKey( me.input.KEY.ENTER );
        me.audio.stopTrack();
    }
});

var GameOverScreen = TitleScreen.extend(
{
	
//alert("jpo");
    init: function()
    {
        this.parent( true );
        this.fontSmall = new me.BitmapFont( "16x16_font", 16 );
        this.fontSmall.set( "center", 1 );
        this.fontLarge = new me.BitmapFont( "32x32_font", 32 );
        this.fontLarge.set( "center", 1 );
    },

    update: function()
    {
        this.updateScroll();
    },

    onResetEvent: function()
    {
        if ( !this.backgroundImg )
        {
            this.backgroundImg = me.loader.getImage( "title_bg" );
            this.overlay = me.loader.getImage( "gameover_overlay" );
        }

        me.audio.playTrack( "theme" );
    },

    draw: function( context )
    {
        context.drawImage( this.backgroundImg, 0, 0 - this.yCounter ,window.innerWidth,window.innerHeight);
        context.drawImage( this.backgroundImg, 0, 0 - this.yCounter + 1200,window.innerWidth,window.innerHeight );
        context.drawImage( this.overlay, 0, 0,window.innerWidth,window.innerHeight );
        this.fontLarge.draw( context, "CONGRATULATION!", 400, 200 );
        this.fontSmall.draw( context, "DEATHS: " + me.game.deathCount,
            400, 380 );
			
			 windowGAMEOVER.style.backgroundImage ='url('+me.loader.getImage('forrest_bg').src +')';
			 actor1.style.backgroundImage ='url('+me.loader.getImage('actor1img').src +')';
			 cortinagameover.style.backgroundImage ='url('+me.loader.getImage('gameover_overlay').src +')';
			        titulogameover.style.backgroundImage ='url('+me.loader.getImage('btncontinueimg2').src +')';
			      
				   windowGAMEOVER.style.display="block";
    }
});

function spawnParticle( x, y, sprite, spritewidth, frames, speed, z )
{
    var settings = new Object();
    settings.image = sprite;
    settings.spritewidth = spritewidth;

    var particle = new me.ObjectEntity( x, y, settings );
    particle.animationspeed = speed;
    particle.addAnimation( "play", frames );
    particle.setCurrentAnimation( "play",
        function() { me.game.remove( particle ) } );
    me.game.add( particle, z );
    me.game.sort();

    return particle;
}

window.onReady( function()
{
    jsApp.onload();
    
	
 if (navigator.onLine) {
    /*agregamos publicidad*/
	addAdsPrincipal("contenidopublicidadprincipal",
	"http://asikersoft-electronsoft.appspot.com/static/banner/index.html");
 }
	
    
      document.getElementById("btnplay").addEventListener("click", function () {
		  
		  
		  	 windowlevelmenu.style.top="0%";

			 

			       windowlevelmenu.style.backgroundImage ='url('+me.loader.getImage('mapa').src +')';
	 windowlevelmenup.style.backgroundImage ='url('+me.loader.getImage('gameover_overlay').src +')';
	 
	 
 btnleft1.style.backgroundImage ='url('+me.loader.getImage('left1').src +')';
	    btnright1.style.backgroundImage ='url('+me.loader.getImage('right1').src +')';
	  
	    btnup1.style.backgroundImage ='url('+me.loader.getImage('left1').src +')';
	    btndown1.style.backgroundImage ='url('+me.loader.getImage('right1').src +')';

	  btnnextok.style.display="none";
	  
	  if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
					 
	 windowlevelmenu.style.display ="block";
  windowlevelmenup.style.backgroundColor="rgba(0, 0, 0, 0.54)";

	 
	 
	   var introclosemenulevelbue1 = setInterval(function () {
		
		 		 windowlevelmenu.style.backgroundColor ="black";
   clearInterval(introclosemenulevelbue1);
        }, 1000);
		

	   var introclosemenulevelbue1g = setInterval(function () {
		
		 		 windowlevelmenu.style.top="-100%";
				 
   clearInterval(introclosemenulevelbue1g);
        }, 2500);



	
	  	   var introclosemenulevelbue1gs = setInterval(function () {
		  
		  
	
	
	document.getElementById("btnplay").style.left="-100%";
	document.getElementById("facebook").style.left="-100%";
	document.getElementById("Twitter").style.left="-100%";
	document.getElementById("titulo").style.left="-100%";
	document.getElementById("btnmapa").style.left="-100%";
	document.getElementById("pt1").style.background="white";
	document.getElementById("pt1").style.opacity="0.9";	
		  
		  
		  if (navigator.onLine) {
    ventanapublicidadprincipal.style.display="block"; 
			}else
			{
				
				
			if(me.levelDirector.getCurrentLevelId() == "level1")
			{
me.state.change( me.state.PLAY );
huskycollect.style.left ="5%";

			}else{ 

					 }
			}
		  clearInterval(introclosemenulevelbue1gs);
        }, 3500);
	  
	
		
		
		  var introbye2f = setInterval(function () {

windowlevelmenup.style.backgroundColor ="black";


	 
	 
	  var intFrameWidth = window.innerWidth;
      var intFrameHeight = window.innerHeight;
	 
	     
  
     btnup.style.left= intFrameWidth-70+"px";
     btnup.style.top= intFrameHeight-140+"px";
     
      btndown.style.left= intFrameWidth-90+"px";
     btndown.style.top= intFrameHeight-70+"px";
     
     
       btnleft.style.left= 5+"px";
     btnleft.style.top= intFrameHeight-70+"px";
     
     
       btnright.style.left= 75+"px";
     btnright.style.top= intFrameHeight-70+"px";
     
     
     btnreload.style.right= 1+"%";
	 
	 
	 	document.getElementById("pt1").style.display="none";
		document.getElementById("panta1").style.display="none";
		
		
		 if (navigator.onLine) {
			  ventanapublicidadprincipal.style.backgroundColor="#5D4E0E"; 
				}
				
				
			  	clearInterval(introbye2f);
        }, 5000);

		
				  var introbye2f5 = setInterval(function () {
			   windowlevelmenu.style.display ="none";
huskycollect.style.left ="5%";
			   	  	clearInterval(introbye2f5);
        }, 7000);
   
}, false);
      
   
      
	        
          
      document.getElementById("btncontinuep").addEventListener("click", function () {

if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
        
		 	
			
if (navigator.onLine) {
	
	btncontinuep.style.left="-100%";
	
     // cortina.style.display="block";
		cortina.style.display="block";
		var cortina1fs= setInterval(function () {
			 
           cortina.style.backgroundColor="black";
	
        clearInterval(cortina1fs);
        }, 1500);
		
		var cortina2f= setInterval(function () {
 ventanapublicidadprincipal.style.display="none";
	  
	 clearInterval(cortina2f);
        }, 4000);
		
		var cortina2f2= setInterval(function () {
   
cortina.style.display="none";

if(me.levelDirector.getCurrentLevelId() == "level1")
{
		 me.state.change( me.state.PLAY );

}else{ 

		 }
   


	 clearInterval(cortina2f2);
        }, 4100);
		
		
	}else
	{
		if(me.levelDirector.getCurrentLevelId() == "level1")
           {
		 me.state.change( me.state.PLAY );
	}else{ 
			 }
		
	}
		
		
	}, false);	
	  
      
	  
	  
	       document.getElementById("titulogameover2").addEventListener("click", function () {
idlevelcurrent.innerHTML = me.levelDirector.getCurrentLevelId();
if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
					 
					 clearInterval(gameover1);
	  
	  titulogameover2.style.display="none";
	  titulogameover3.style.display="none";
	  cortinagameover.style.backgroundColor="black";
	  
	  
	 //me.state.change( me.state.MENU );
	 
	 
	// var currentlevel  =me.levelDirector.getCurrentLevelId();
//	me.levelDirector.loadLevel(me.levelDirector.getCurrentLevelId());
			
           me.state.change( me.state.PLAY );
				 
		
	 
	 
//me.levelDirector.reloadLevel();
	 
	  	var cortina2f2d6a= setInterval(function () {
	    windowGAMEOVER.style.display="none";
		cortinagameover.style.display="none";

			
          clearInterval(cortina2f2d6a);
        }, 2000);		


	var cortina2f2ddsa= setInterval(function () {
		
	    titulogameover2.style.display="block";
	    cortinagameover.style.display="block";
		cortinagameover.style.backgroundColor="transparent";


	 me.levelDirector.loadLevel(idlevelcurrent.textContent);
	 
	  clearInterval(cortina2f2ddsa);
 
        }, 2200);			
		   
		   
		   }, false);
		   
		   
		   
		   
		    document.getElementById("titulogameover3").addEventListener("click", function () {

if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
	  titulogameover2.style.display="block";
	  titulogameover3.style.display="none";
	  cortinagameover.style.backgroundColor="black";
	  me.state.change( me.state.PLAY );
	 
	  	var cortina2f2d6g= setInterval(function () {
	    windowGAMEOVER.style.display="none";
		  cortinagameover.style.display="none";

			
          clearInterval(cortina2f2d6g);
        }, 2000);		


	var cortina2f2ddsg= setInterval(function () {
			  titulogameover2.style.display="block";
	    cortinagameover.style.display="block";
		
			  cortinagameover.style.backgroundColor="transparent";
	   me.state.change( me.state.PLAY );
location.href="playgame.html";
	   
	  clearInterval(cortina2f2ddsg);
 
        }, 2200);			
		   
		   
		   }, false);
		   
		   
          
      document.getElementById("facebook").addEventListener("touchstart", function () {

if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
        
		 window.open("http://www.facebook.com/sharer.php?u=https://www.facebook.com/asikergames", "ventana1", "width=480,height=320,scrollbars=NO");
       
            
   
}, false);
      
          document.getElementById("facebook").addEventListener("click", function () {


        
		 window.open("http://www.facebook.com/sharer.php?u=https://www.facebook.com/asikergames", "ventana1", "width=480,height=320,scrollbars=NO");
       
            
   
}, false);
      
         document.getElementById("Twitter").addEventListener("touchstart", function () {

if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
        
		    window.open("http://twitter.com/home?status="+escape("!playing husky adventure from  firefox os !"));
    
   
}, false);
      
	 
	   document.getElementById("Twitter").addEventListener("click", function () {


        
		    window.open("http://twitter.com/home?status="+escape("!playing husky adventure from  firefox os !"));
    
   
}, false);
      
      
 document.getElementById("btnrstart").addEventListener("click", function () {

  huskycollect.style.backgroundImage ='url('+me.loader.getImage('barrahusky1').src +')'; 
if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
	btncontinue.style.left ="-135%"; 
		btnrstart.style.left ="-135%"; 
		btnmainmenu.style.left ="-135%"; 

	   var introclosemenulevelbue1 = setInterval(function () {
		
		 	windowmainmenu.style.left ="-100%";
			
me.state.change( me.state.PLAY );
   clearInterval(introclosemenulevelbue1);
        }, 1000);


	 
}, false);







         
	 document.getElementById("btnmapa").addEventListener("click", function () {
	 windowlevelmenu.style.top="0%";
	 

	 
	 			       windowlevelmenu.style.backgroundImage ='url(none)';
	 windowlevelmenup.style.backgroundImage ='url(none)';
	 

	if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
					 
  windowlevelmenu.style.display ="block";
  windowlevelmenup.style.backgroundColor="rgba(0, 0, 0, 0.54)";

	 
	 
	   var introclosemenulevelbue1 = setInterval(function () {
			       windowlevelmenu.style.backgroundImage ='url('+me.loader.getImage('mapmision1').src +')';
	 windowlevelmenup.style.backgroundImage ='url('+me.loader.getImage('gameover_overlay').src +')';
	 
		 		 windowlevelmenu.style.backgroundColor ="black";
				 
				 
   clearInterval(introclosemenulevelbue1);
        }, 1000);
		
		
		
		
	 



 
	   var introclosemenulevelbue1g = setInterval(function () {
		
		btnnextok.style.display="block";
		
		 		 windowlevelmenu.style.top="-100%";
   clearInterval(introclosemenulevelbue1g);
        }, 2500);



		
		


}, false);

	
	
		 document.getElementById("btnnextok").addEventListener("click", function () {


	if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }

					 windowlevelmenup.style.backgroundColor="black";
					 
	   var introclosemenulevelbuek = setInterval(function () {

		
		windowlevelmenu.style.display="none";
				 		 windowlevelmenu.style.top="0%";
								 
   clearInterval(introclosemenulevelbuek);
        }, 2000);


}, false);

	
	
	         
	 document.getElementById("btncontinue").addEventListener("click", function () {

//me.state.change( me.state.PLAY );
	if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
	btncontinue.style.left ="-135%"; 
		btnrstart.style.left ="-135%"; 
		btnmainmenu.style.left ="-135%"; 

	   var introclosemenulevelbue = setInterval(function () {
		
		 	windowmainmenu.style.left ="-100%";
   clearInterval(introclosemenulevelbue);
        }, 1000);


}, false);

			 

			 
document.getElementById("btnmainmenu").addEventListener("click", function () {
btncontinuep.style.left="10%";
cortina.style.backgroundColor="transparent";
	if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
	btncontinue.style.left ="-135%"; 
		btnrstart.style.left ="-135%"; 
		btnmainmenu.style.left ="-135%"; 

	   var introclosemenulevelbue5 = setInterval(function () {
		
		 	windowmainmenu.style.left ="-100%";
   clearInterval(introclosemenulevelbue5);
        }, 1000);
		
		  var introclosemenulevelbue6 = setInterval(function () {
		
titulo.style.left ="10%";
btnplay.style.left ="5%";
btnmapa.style.left ="10%";
facebook.style.left ="15%";
Twitter.style.left ="9%";
		pt1.style.opacity  ="0.3";
		pt1.style.backgroundSize =" 100% 100%,auto auto,auto auto ";
		pt1.style.backgroundImage =" url(data/neblina.gif)";
		pt1.style.display="block";
panta1.style.display="block";

   clearInterval(introclosemenulevelbue6);
        }, 2000);



}, false);
	 
			 
      
      

             document.getElementById("btnreload").addEventListener("click", function () {


	//me.audio.play("botonpush");
     
	if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
	  
	    windowmainmenu.style.display ="block";
		btncontinue.style.display ="black";
		btnrstart.style.display ="block";
		btnmainmenu.style.display ="block";
		
		windowmainmenu.style.left ="0px";
		btncontinue.style.left ="35%"; 
		btnrstart.style.left ="35%"; 
		btnmainmenu.style.left ="35%"; 

		
		
	
	    windowmainmenu.style.backgroundImage=  "url("+me.loader.getImage('gameover_overlay').src+")";
	   btncontinue.style.backgroundImage ='url('+me.loader.getImage('btncontinueimg').src +')';
	   btnrstart.style.backgroundImage ='url('+me.loader.getImage('btnrstartimg').src +')';
	   btnmainmenu.style.backgroundImage ='url('+me.loader.getImage('btnmainmenuimg').src +')';
	  
	  
	   
		  
	  
	  
	  
}, false);
 
       
});



function addAdsPrincipal(idContenedorPrincipal,urlAdsPrincipal){

	if(typeof(idContenedorPrincipal) === "undefined"){
		idContenedorPrincipal = 'contenidopublicidadPrincipal';
	}
	if(typeof(urlAdsPrincipal) === "undefined"){
		//urlAdsPrincipal = 'http://asikersoft.com/static/husky/husky/husky.html';
		urlAdsPrincipal = 'http://asikersoft-electronsoft.appspot.com/static/banner/index.html';
		
	}
	if(navigator.onLine){
		var contenedorPrincipal = document.getElementById(idContenedorPrincipal);
		contenedorPrincipal.innerHTML = '<iframe width="320" height="100" frameBorder="1" scrolling="no" src="'+urlAdsPrincipal+'"></iframe>';
    }
	
}


