


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

        */
/*
 * 
 * 
 * 
*/
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", "black", 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();
 if ( curLevel < 3||  curLevel < 4||  curLevel < 5||  curLevel < 6||  curLevel < 7 ||  curLevel < 8||  curLevel < 9||  curLevel < 10 || curLevel < 11|| curLevel < 12|| curLevel < 13||  curLevel < 14 )
       
	   {
   
		/*agregamos publicidad*/
	//	addAds("contenidopublicidad","http://asikersoft.com/static/dragon_ball/celladventure/index.html");

	  //document.getElementById("ventanapublicidad").style.left="0px";
		
		 if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
					 
					 
	 windowmenulevelstart.style.display="block";
	   windowmenulevelstart.style.backgroundImage=  "url("+me.loader.getImage('radar1').src+")";
					 
var intromenulevel4 = setInterval(function () {
		
		//cortinilla.style.zIndex="20";
		 	cortinilla2.style.backgroundColor="transparent";
			cortinilla3.style.display="block";
			
			
   clearInterval(intromenulevel4);
        }, 100);
		
          
        }
		
if(me.levelDirector.getCurrentLevelId() == "level1")
           {
	 
	  boladragon.style.left="65%";
	  boladragon.style.top="25%";

  }
  if(me.levelDirector.getCurrentLevelId() == "level2")
           {
	 
	  boladragon.style.left="60%";
	  boladragon.style.top="40%";
	  
boladragon1.style.display="block";
	
	  
  }
  
    if(me.levelDirector.getCurrentLevelId() == "level3")
           {
	 
	  boladragon.style.left="50%";
	  boladragon.style.top="20%";
	  
	  boladragon1.style.display="block";
	boladragon2.style.display="block";
	  
	  

  }
  
  
    if(me.levelDirector.getCurrentLevelId() == "level4")
           {
	 
	  boladragon.style.left="65%";
	  boladragon.style.top="60%";
	  
    boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	
	
  }
  
     
  
    if(me.levelDirector.getCurrentLevelId() == "level5")
           {
	 
	  boladragon.style.left="45%";
	  boladragon.style.top="35%";
	  
	  
	  
    boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	boladragon4.style.display="block";

  }
  
  
   if(me.levelDirector.getCurrentLevelId() == "level6")
           {
	 
	  boladragon.style.left="55%";
	  boladragon.style.top="25%";

	  
    boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	boladragon4.style.display="block";
    boladragon5.style.display="block";
	
	
  }
  
   
   if(me.levelDirector.getCurrentLevelId() == "level7")
           {
	 
	  boladragon.style.left="60%";
	  boladragon.style.top="45%";

	  
	  
	boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	boladragon4.style.display="block";
    boladragon5.style.display="block";
	boladragon6.style.display="block";
	
	
  }
   
   if(me.levelDirector.getCurrentLevelId() == "level8")
           {
	 
	  boladragon.style.left="58%";
	  boladragon.style.top="40%";

	  
	  
	  	boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	boladragon4.style.display="block";
    boladragon5.style.display="block";
	boladragon6.style.display="block";
    boladragon7.style.display="block";
  
  }
		
   if(me.levelDirector.getCurrentLevelId() == "level9")
           {
	 
	  boladragon.style.left="70%";
	  boladragon.style.top="40%";

	  
	boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	boladragon4.style.display="block";
    boladragon5.style.display="block";
	boladragon6.style.display="block";
    boladragon7.style.display="block";
	boladragon8.style.display="block";
	
	  
	  
  }
  
  
    if(me.levelDirector.getCurrentLevelId() == "level10")
           {
	 
	  boladragon.style.left="79%";
	  boladragon.style.top="30%";

	  
	  
	boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	boladragon4.style.display="block";
    boladragon5.style.display="block";
	boladragon6.style.display="block";
    boladragon7.style.display="block";
	boladragon8.style.display="block";
	boladragon9.style.display="block";
	
	
  }
  
  
   if(me.levelDirector.getCurrentLevelId() == "level11")
           {
	 
	  boladragon.style.left="79%";
	  boladragon.style.top="50%";

	  
	  boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	boladragon4.style.display="block";
    boladragon5.style.display="block";
	boladragon6.style.display="block";
    boladragon7.style.display="block";
	boladragon8.style.display="block";
	boladragon9.style.display="block";
	boladragon10.style.display="block";
	  
  }
  
  
     if(me.levelDirector.getCurrentLevelId() == "level12")
           {
	 
	  boladragon.style.left="80%";
	  boladragon.style.top="50%";

	  
    boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	boladragon4.style.display="block";
    boladragon5.style.display="block";
	boladragon6.style.display="block";
    boladragon7.style.display="block";
	boladragon8.style.display="block";
	boladragon9.style.display="block";
	boladragon10.style.display="block";
	boladragon12.style.display="block";


	
  }
  
    if(me.levelDirector.getCurrentLevelId() == "level13")
           {
	 
	  boladragon.style.left="70%";
	  boladragon.style.top="40%";

	  
	  	  
    boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	boladragon4.style.display="block";
    boladragon5.style.display="block";
	boladragon6.style.display="block";
    boladragon7.style.display="block";
	boladragon8.style.display="block";
	boladragon9.style.display="block";
	boladragon10.style.display="block";
	boladragon12.style.display="block";
	boladragon13.style.display="block";
	  
	  
	  
  }
  
     if(me.levelDirector.getCurrentLevelId() == "level14")
           {
	 
	  boladragon.style.left="60%";
	  boladragon.style.top="20%";

	  
	    boladragon1.style.display="block";
	boladragon2.style.display="block";
	boladragon3.style.display="block";
	boladragon4.style.display="block";
    boladragon5.style.display="block";
	boladragon6.style.display="block";
    boladragon7.style.display="block";
	boladragon8.style.display="block";
	boladragon9.style.display="block";
	boladragon10.style.display="block";
	boladragon12.style.display="block";
	boladragon13.style.display="block";
	boladragon14.style.display="block";
	  
	  
  }
		
		

        this.lastMusic = this.music;
        if ( curLevel < 2 )
        {
            this.music = "tech";//drown    tech
        }
        else if ( curLevel < 4 )
        {
            this.music = "cave";
        }
        
         else if ( curLevel <9 )
       {
      this.music = "tech";
       }
        
       else if ( curLevel <13 )
       {
      this.music = "drown";
       }
       
       else if ( curLevel <15 )
       {
      this.music = "cave";
       }
   
  else if ( curLevel >= 16 )
       {
           //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 < 550 )
        {
	  
	  if ( this.counter > 350 &&  this.counter < 450 ){
	    
	    pantacontinue.style.left="0%";
	    pantaprincipal.style.left="0%";
	  }
	  
	   if ( this.counter >540 ){
	    
	    pantacontinue.style.left="-100%";
	    pantaprincipal.style.left="-100%";
	  }
	  
            this.counter++;
	    
	            
        }
        
        /*if ( this.counter ==350 )
        {
           // this.counter++;
	    pantacontinue.style.left="0%";
	            
        }*/
    
      
        else{
	  
	  
	  
          me.state.change(me.state.MENU);
	

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

    draw: function(context) {
    
		// pantacontinue.style.left="0%";			  
					   
	
        context.drawImage( this.bg, 0, 0 );
        if( this.counter < 130) context.drawImage( this.text_mars, 124+8, 217+6 );
        else if( this.counter < 135) context.drawImage( this.text_radmars2, 124+80, 217+60 );
        else if( this.counter < 140) context.drawImage( this.text_radmars1, 124+80, 217+60 );
        else if( this.counter < 145) context.drawImage( this.text_radmars2, 124+80, 217+60 );
        else if( this.counter < 150) context.drawImage( this.text_radmars1, 124+80, 217+60 );
        else if( this.counter < 155) context.drawImage( this.text_radmars2, 124+80, 217+60 );
        else if( this.counter < 160) context.drawImage( this.text_radmars1, 124+80, 217+60 );
        else if( this.counter < 165) context.drawImage( this.text_radmars2, 124+80, 217+60 );
        else context.drawImage( this.text_radmars1, 124+8, 217+6 );

        if( this.counter < 100) context.drawImage( this.glasses1, 289+80, 289*(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, 289+8, 589+6 );
					   
		 		
    },

    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 );
            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;
        }
    }
});

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 'hitting head';
        if( item == 'buttStomp' ) return 'power 2';
        if( item == 'rocketJump' ) return 'power 1 long jump ';
        if( item == 'wallStick' ) return 'climbing 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
                {
		  
                    
                  
                }
            }
       }
       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( -10, me.video.getHeight() *0.5, {
            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 );
        }
        this.updateScroll();
    },

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

        me.game.repaint();
    },

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

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

var GameOverScreen = TitleScreen.extend(
{
    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 );
        context.drawImage( this.backgroundImg, 0, 0 - this.yCounter + 1200 );
        context.drawImage( this.overlay, 0, 0 );
        this.fontLarge.draw( context, "CONGRATULATION!", 400, 200 );
        this.fontSmall.draw( context, "DEATHS: " + me.game.deathCount,
            400, 380 );
    }
});

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();
    
      /*agregamos publicidad*/
      addAdsPrincipal("contenidopublicidadprincipal",
	  "https://asikersoft-electronsoft.appspot.com/static/banner/index.html");

	  
	  document.getElementById("btnhelp2").addEventListener("click", function () {
		btnhelp2.style.display="none";
		
		if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
	
    }, false);

      document.getElementById("btnplay").addEventListener("touchstart", function () {
if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
					 
					   btnhelp2.style.right="1%";
	  /*removemos publicidad*/
		removeAdsPrincipal("contenidopublicidadprincipal");

		
		ventanapublicidadprincipal.style.display="none";
	cortinilla.style.zIndex="25";
	
	
		var  splashpublicfin = setInterval(function () {

	   cortinilla.style.backgroundColor="black";

		   clearInterval(splashpublicfin);
    }, 200);
		
		
		
		var  splashpublicfin2 = setInterval(function () {

	   windowmainmenustart.style.display="none";
	   
	   cortinilla.style.zIndex="20";
	//cortinilla.style.backgroundColor="transparent";
   btnpause.style.display="block";


		   clearInterval(splashpublicfin2);
    }, 2500);
		
		
	 // document.getElementById("ventanapublicidadprincipal").style.left="-100%";
	  
	
		   pantaprincipal.style.backgroundImage = "none";
            pantaprincipal.style.backgroundSize = "100% 100%,0px 0px ,auto,auto";
            pantaprincipal.style.backgroundImage = "url(data/gameover_overlay.png)";
            pantaprincipal.style.backgroundRepeat = "no-repeat";
		
            pantaprincipal.style.left="0%";
	
         me.state.change( me.state.PLAY );
	 
	 
	  var intFrameWidth = window.innerWidth;
      var intFrameHeight = window.innerHeight;
	
	 
     btnup.style.left= intFrameWidth-80+"px";
     btnup.style.top= intFrameHeight-180+"px";
     
     
     btndown.style.left= intFrameWidth-80+"px";
     btndown.style.top= intFrameHeight-80+"px";
     
     
     
     
        
     btnrocketer.style.left= intFrameWidth-150+"px";
     btnrocketer.style.top= intFrameHeight-200+"px";
     
    
          btnromperdown.style.left= intFrameWidth-150+"px";
     btnromperdown.style.top= intFrameHeight-80+"px";
     
     
     
      
     
     
       btnleft.style.left= 5+"px";
     btnleft.style.top= intFrameHeight-80+"px";
     
     
       btnright.style.left= 90+"px";
     btnright.style.top= intFrameHeight-80+"px";
    
     
  
   
}, false);
      
        document.getElementById("game").addEventListener("touchstart", function () {

		
		if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
		    windowmainmenustart.style.backgroundImage=  "url("+me.loader.getImage('title_bg').src+")";
		  
		    //titlegame.style.backgroundImage=  "url("+me.loader.getImage('newgameimg1').src+")";
		    btnplay.style.backgroundImage=  "url("+me.loader.getImage('newgameimg1').src+")";
		    btnlevelsstart.style.backgroundImage=  "url("+me.loader.getImage('levels').src+")";
		    facebook.style.backgroundImage=  "url("+me.loader.getImage('f').src+")";
            btninstructionsstart.style.backgroundImage=  "url("+me.loader.getImage('instructions').src+")";

		windowmainmenustart.style.display="block";
	    
	   var  splashpublic7 = setInterval(function () {

	   
	cortinilla.style.backgroundColor="rgba(1, 2, 1, 0.16)";

		   clearInterval(splashpublic7);
    }, 200);
			
	   var  splashpublic8 = setInterval(function () {

	  
            titlegame.style.left="1%";
			btnplay.style.left="3%";
			btnlevelsstart.style.left="8%";
			btninstructionsstart.style.left="0%";
			facebook.style.left="5%";
				

	   
	    clearInterval(splashpublic8);
    }, 500);
		  
		  
       

				
				
			}, 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("Twitter").addEventListener("touchstart", function () {

        
		    window.open("http://twitter.com/home?status="+escape("!playing husky adventure from  firefox os !"));
    
   
}, false);*/
      
      
      
  
	 
      	 
	  
	    
	    


document.getElementById("btnclose").addEventListener("touchstart", function () {
		/*removemos publicidad*/
		removeAds("contenidopublicidad");

	  document.getElementById("ventanapublicidad").style.left="-100%";
	  
	  
	 
}, false);



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

	 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("btnrstart").addEventListener("touchstart", function () {

	  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("btnmainmenu").addEventListener("touchstart", function () {

	  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%";
			

   clearInterval(introclosemenulevelbue1);
        }, 1000);

		

		
		
	   var introclosemenulevelbue2 = setInterval(function () {
		windowmainmenustart.style.display ="block";
		
		cortinilla.style.zIndex="22";
   clearInterval(introclosemenulevelbue2);
        }, 2000);
		
		 var introclosemenulevelbue3 = setInterval(function () {
		
	
		 	cortinilla.style.backgroundColor="rgba(1, 2, 1, 0.16)";
			
   clearInterval(introclosemenulevelbue3);
        }, 2100);
		
		
		 var introclosemenulevelbue4 = setInterval(function () {
		
		cortinilla.style.zIndex="20";
		 	
			
   clearInterval(introclosemenulevelbue4);
        }, 3000);
		
		
	

	 }, false);
	  
	  
	   
		  
  document.getElementById("btnlevelsstart").addEventListener("touchstart", function () {
	  if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
					 
					 
	 windowmenulevelstart.style.display="block";
	   windowmenulevelstart.style.backgroundImage=  "url("+me.loader.getImage('radar1').src+")";
					 
var intromenulevel = setInterval(function () {
		
		//cortinilla.style.zIndex="20";
		 	cortinilla2.style.backgroundColor="transparent";
			cortinilla3.style.display="block";
			
			
   clearInterval(intromenulevel);
        }, 100);
					 
					 
		
	 }, false);
	 
	 
	 
	 
	 
	   document.getElementById("cortinilla3").addEventListener("touchstart", function () {
	  if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
				

 cortinilla2.style.backgroundColor="black";
			cortinilla3.style.display="none";	
			
var intromenulevel5 = setInterval(function () {
					 
			windowmenulevelstart.style.display="none";
			
   clearInterval(intromenulevel5);
        }, 1500);
					 
					 
	 	 }, false);
		 
	
	  
  document.getElementById("btninstructionsstart").addEventListener("touchstart", function () {
	  if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
					 
					 
	 windowmenulevelstarta.style.display="block";
	// windowmenulevelstarta.style.backgroundImage=  "url("+me.loader.getImage('radar1').src+")";
					 
	var intromenulevela = setInterval(function () {
			
			
				cortinilla2a.style.backgroundColor="transparent";
				cortinilla3a.style.display="block";
				
				
	   clearInterval(intromenulevela);
			}, 100);
						 
					 
		
	 }, false);
	 
	 
	 
	 
	  
	   document.getElementById("cortinilla3a").addEventListener("touchstart", function () {
	  if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
				

 cortinilla2a.style.backgroundColor="black";
			cortinilla3a.style.display="none";	
			
var intromenulevel5a = setInterval(function () {
					 
			windowmenulevelstarta.style.display="none";
			
   clearInterval(intromenulevel5a);
        }, 1500);
					 
					 
	 	 }, false);
		 
	

	

document.getElementById("btnpause").addEventListener("touchstart", function () {
		
		  
	  if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
		
		
	        windowmainmenu.style.backgroundImage=  "url("+me.loader.getImage('title_overlay').src+")";
		    windowmainmenu.style.backgroundColor="rgba(204, 189, 23, 0.5)";
		 
	  	
			
			
		    btncontinue.style.backgroundImage=  "url("+me.loader.getImage('continue').src+")";
		    btnrstart.style.backgroundImage=  "url("+me.loader.getImage('rstart').src+")";
		    btnmainmenu.style.backgroundImage=  "url("+me.loader.getImage('mainmenu').src+")";
		
	
	  
	  
	  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%"; 

	  
	 
}, false);
   
});




	
function addAdsPrincipal(idContenedorPrincipal,urlAdsPrincipal){

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

function removeAdsPrincipal(idContenedorPrincipal){
	if(typeof(idContenedorPrincipal) === "undefined"){
		idContenedorPrincipal = 'contenidopublicidadPrincipal';
	}
	var contenedorPrincipal = document.getElementById(idContenedorPrincipal);
	contenedorPrincipal.innerHTML = '';
}



function addAds(idContenedor,urlAds){
	if(typeof(idContenedor) === "undefined"){
		idContenedor = 'contenidopublicidad';
	}
	if(typeof(urlAds) === "undefined"){
		urlAds = 'https://asikersoft-electronsoft.appspot.com/static/banner/index.html';
	}
	
		if(navigator.onLine){
		var contenedor = document.getElementById(idContenedor);
		contenedor.innerHTML = '<iframe width="300" height="250" frameBorder="0" scrolling="yes" src="'+urlAds+'"></iframe>';
		}
	
	}

function removeAds(idContenedor){
	if(typeof(idContenedor) === "undefined"){
		idContenedor = 'contenidopublicidad';
	}
	var contenedor = document.getElementById(idContenedor);
	contenedor.innerHTML = '';
}


