

var jsApp =
{
    onload: function()
    {  

	
    //  var continuarlevel = false;
      var intFrameWidth = window.innerWidth;
      var intFrameHeight = window.innerHeight;
      
       
         if ( !me.video.init( 'game', intFrameWidth, intFrameHeight,'auto' ) )
        {
            alert( "Sorrry" );
            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()
    {
			document.getElementById("pantaprincipal").style.backgroundImage= "url("+ me.loader.getImage('overlay').src+")";
		
        me.state.set( me.state.PLAY, new PlayScreen() );               
        me.state.set( me.state.INTRO, new RadmarsScreen() );
        me.state.set( me.state.MENU, new TitleScreen() );
        me.state.set( me.state.GAMEOVER, new GameOverScreen() );
        
        me.state.transition( "fade", "white", 300 );

        me.entityPool.add( "player", Player );
        me.entityPool.add( "enemy", Enemy );

        me.debug.renderHitBox = false;

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

var LevelChanger = me.LevelEntity.extend({
    init: function( x, y, settings ) {
        this.parent( x, y, settings );
    },
    goTo: function ( level ) {
        // dumb hack
        if ( this.gotolevel == "gameover" )
        {
            me.state.change( me.state.GAMEOVER );

             ventanatabletgameover.style.display="block";
         btnpause.style.display="none";
			
	 
            return;
        }
 
 	   me.state.change( me.state.GAMEOVER );
ventanatabletscore.style.display="block";
btnpause.style.display="none";
		

       /*agregamos publicidad*/
	if (navigator.onLine === true) {

    	mipublicidadcross(); 

        }
		
    }

			


	});

var StoryNode = me.InvisibleEntity.extend(
{
    init: function( x, y, settings )
    {
        this.parent( x, y, settings );
        this.text = settings.text;
        this.toggled = false;
    },
    
  
    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 PlayScreen = me.ScreenObject.extend(
{

    init: function () {
        me.entityPool.add("LevelChanger", LevelChanger);
        me.entityPool.add("StoryNode", StoryNode);
        this.levelDisplay = new LevelDisplay();
        this.storyDisplay = new StoryDisplay();
        me.game.lives = 5;
        me.game.kills = 0;
	
		
		
	
    },

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

    changeLevel: function( l ) {
        this.levelDisplay.reset();
        var levelNum = this.parseLevel( l );



		/*
        if ( levelNum == 4 )
        {
            me.audio.stopTrack();
            me.audio.playTrack( "ld23-theme2" );
        }
        else if ( levelNum == 5 )
        {
            me.audio.stopTrack();
            me.audio.playTrack( "ld23-mars" );
        }*/
    },

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

    onResetEvent: function()
    {
     
      
        me.game.addHUD( 0, 0, me.video.getWidth(), me.video.getHeight() );
        me.game.HUD.addItem( "hp", new HPDisplay( 450, 15 ) );
        me.game.HUD.addItem( "levelDisplay", this.levelDisplay );
        me.game.HUD.addItem( "storyDisplay", this.storyDisplay );
        this.restartLevel(location.hash.substr(1));
    

	 me.audio.playTrack( "ld23-mars" );
	
	
 if ( me.levelDirector.getCurrentLevelId() == "level1" )
        {
		
//me.audio.stopTrack();
me.audio.playTrack( "sagamajinbuutrak4" ); //tebevroso

        }
	else if (  me.levelDirector.getCurrentLevelId() == "level2" )
        {
			
			//me.audio.stopTrack();
            me.audio.playTrack( "ld23-mars" );//aventurero
		}
else if (  me.levelDirector.getCurrentLevelId() == "level3" )
        {
			
			//me.audio.stopTrack();
            me.audio.playTrack( "ld23-theme2" );//desafiante
		}	
		else if (  me.levelDirector.getCurrentLevelId() == "level4" )
        {
			
			//me.audio.stopTrack();
            me.audio.playTrack( "ld23-theme" );//alucinante
		}
else if (  me.levelDirector.getCurrentLevelId() == "level5" )
        {
			
			//me.audio.stopTrack();
            me.audio.playTrack( "ld23-mars" );//aventurero
		}
else if (  me.levelDirector.getCurrentLevelId() == "level6" )
        {
			
			//me.audio.stopTrack();
            me.audio.playTrack( "ld23-theme2" );//desafiante
		}	
		else if (  me.levelDirector.getCurrentLevelId() == "level7" )
        {
			
			//me.audio.stopTrack();
            me.audio.playTrack( "ld23-theme" );//alucinante
		}
else if (  me.levelDirector.getCurrentLevelId() == "level8" )
        {
			
			//me.audio.stopTrack();
            me.audio.playTrack( "ld23-mars" );//aventurero
		}
else if (  me.levelDirector.getCurrentLevelId() == "level9" )
        {
			
			//me.audio.stopTrack();
            me.audio.playTrack( "ld23-theme2" );//desafiante
		}	




    },

    restartLevel: function( level ) {
        this.levelDisplay.reset();
        level = level || me.levelDirector.getCurrentLevelId();
        me.levelDirector.loadLevel( level );
        me.game.sort();
		
		
		 if(me.game.lives === 0)
		{
		
			cortinagameover.style.display= "block";
	 var  splashgameover1 = setInterval(function () {
  
cortinagameover.style.backgroundColor= "black";
  
     clearInterval(splashgameover1);
    }, 10);

	
	 var  splashgameover3 = setInterval(function () {
					 
	
		 ventanatabletgameover.style.display="block";
		 actornexllevel2.style.display="block";
	     titlegameover0.style.display="block";
         btnpause.style.display="none";

		 
			   clearInterval(splashgameover3);
    }, 1800);
	
	
				 var  splashgameover2 = setInterval(function () {
					 

cortinagameover.style.backgroundColor= "rgba(25, 8, 29, 0.84)";

			   clearInterval(splashgameover2);
    }, 2000);
	
	
		 var  splashgameover4 = setInterval(function () {
					 
cortinagameover.style.display= "none";

			   clearInterval(splashgameover4);
    }, 4000);

		 
		}
    },

	
	
	
	
	
    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 ) {
			
			document.getElementById("pantaprincipalsplash").style.backgroundImage= "url("+ me.loader.getImage('marca').src+")";
		
            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");
        }
		
		   	document.getElementById("titlegame").style.backgroundImage= "url("+ me.loader.getImage('titulogame').src+")";
			document.getElementById("btnplay").style.backgroundImage= "url("+ me.loader.getImage('btnplay').src+")";
            document.getElementById("btnlevelsstart").style.backgroundImage= "url("+ me.loader.getImage('btnlevelsstart').src+")";
			document.getElementById("btnpushstart").style.backgroundImage= "url("+ me.loader.getImage('btnpushstart').src+")";
			document.getElementById("btninstructionsstart").style.backgroundImage= "url("+ me.loader.getImage('btninstructionsstart').src+")";
            document.getElementById("btnpause").style.backgroundImage ='url('+me.loader.getImage('btnpause').src +')';

			 document.getElementById("btninstructionsback").style.backgroundImage ='url('+me.loader.getImage('cerrar').src +')';

			
	  
		   document.getElementById("DUP5pow").style.backgroundImage ='url('+me.loader.getImage('DUP5pow').src +')';
	     document.getElementById("DUP5up").style.backgroundImage ='url('+me.loader.getImage('DUP5up').src +')';
	  
		  document.getElementById("DUP5left").style.backgroundImage ='url('+me.loader.getImage('DUP5left').src +')';
	    document.getElementById("DUP5right").style.backgroundImage ='url('+me.loader.getImage('DUP5right').src +')';
	  
	  //help isntructions
	 document.getElementById("help").style.backgroundImage= "url("+me.loader.getImage('quieto1').src+")";	
	  document.getElementById("DUP5powh").style.backgroundImage ='url('+me.loader.getImage('DUP5pow').src +')';
	     document.getElementById("DUP5uph").style.backgroundImage ='url('+me.loader.getImage('DUP5up').src +')';
		  document.getElementById("DUP5lefth").style.backgroundImage ='url('+me.loader.getImage('DUP5left').src +')';
	    document.getElementById("DUP5righth").style.backgroundImage ='url('+me.loader.getImage('DUP5right').src +')';
	  


document.getElementById("actornexllevel2").style.backgroundImage= "url("+me.loader.getImage('quieto1').src+")";	
document.getElementById("titlegameover0").style.backgroundImage= "url("+me.loader.getImage('titlegameoverfin').src+")";	

	  

	  
	  
		    //menu instructions
		  document.getElementById("btnlevel1").style.backgroundImage ='url('+me.loader.getImage('1').src +')';
	    document.getElementById("btnlevel2").style.backgroundImage ='url('+me.loader.getImage('2').src +')';
	    document.getElementById("btnlevel3").style.backgroundImage ='url('+me.loader.getImage('3').src +')';
	    document.getElementById("btnlevel4").style.backgroundImage ='url('+me.loader.getImage('4').src +')';
	    document.getElementById("btnlevel5").style.backgroundImage ='url('+me.loader.getImage('5').src +')';
	    document.getElementById("btnlevel6").style.backgroundImage ='url('+me.loader.getImage('6').src +')';
		  document.getElementById("btnlevel7").style.backgroundImage ='url('+me.loader.getImage('7').src +')';
	    document.getElementById("btnlevel8").style.backgroundImage ='url('+me.loader.getImage('8').src +')';
	    document.getElementById("btnlevel9").style.backgroundImage ='url('+me.loader.getImage('9').src +')';
		 document.getElementById("btnlevelback").style.backgroundImage ='url('+me.loader.getImage('cerrar').src +')';
	  
		
		
		
		
		
		 document.getElementById("ventanapublicidad").style.backgroundImage ='url('+me.loader.getImage('overlay').src +')';
	
	document.getElementById("btnclose").style.backgroundImage ='url('+me.loader.getImage('btnpushstart').src +')';

		 document.getElementById("ventanatabletscore").style.backgroundImage ='url('+me.loader.getImage('overlay').src +')';

		 	 document.getElementById("ventanatabletgameover").style.backgroundImage ='url('+me.loader.getImage('overlay').src +')';


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

    update: function() {
        if( me.input.isKeyPressed('enter')) {
            me.state.change(me.state.MENU);
        }
        if ( this.counter < 100 )
        {
            this.counter++;
        }else{
			
			
			me.state.change(me.state.MENU);
			
		
	}
      
        me.game.repaint();
    },

    draw: function(context) {
        context.drawImage( this.bg, 0, 0 );
		if( this.counter < 130) context.drawImage( this.text_mars, 266, 317 );
		else if( this.counter < 135) context.drawImage( this.text_radmars2, 224, 317 );
		else if( this.counter < 140) context.drawImage( this.text_radmars1, 224, 317 );
		else if( this.counter < 145) context.drawImage( this.text_radmars2, 224, 317 );
		else if( this.counter < 150) context.drawImage( this.text_radmars1, 224, 317 );
		else if( this.counter < 155) context.drawImage( this.text_radmars2, 224, 317 );
		else if( this.counter < 160) context.drawImage( this.text_radmars1, 224, 317 );
		else if( this.counter < 165) context.drawImage( this.text_radmars2, 224, 317 );
		else context.drawImage( this.text_radmars1, 224, 317 );
		
		if( this.counter < 100) context.drawImage( this.glasses1, 249, 229*(this.counter/100) );
		else if( this.counter < 105) context.drawImage( this.glasses2, 249, 229 );
		else if( this.counter < 110) context.drawImage( this.glasses3, 249, 229 );
		else if( this.counter < 115) context.drawImage( this.glasses4, 249, 229 );
		else context.drawImage( this.glasses1, 249, 229 );
		
        
    },

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

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

    onResetEvent: function() {
        if( ! this.title ) {
	
	document.getElementById("pantaprincipalsplash").style.backgroundImage="url("+ me.loader.getImage('introfondo').src+")";
		     
		   
		    var introc30 = setInterval(function () {

		   pantaprincipal.style.opacity="1";
		   
     clearInterval(introc30);
			
        }, 300);
		   
		   
		    var introc31 = setInterval(function () {
		   btnpushstart.style.left="35%";
		     clearInterval(introc31);
			
        }, 700);
		   
		  
		   
		   this.splash= me.loader.getImage("splash");
            this.cta = me.loader.getImage("splash_cta");
            this.title = me.loader.getImage("splash_title");
        }

        me.input.bindKey( me.input.KEY.ENTER, "enter", true );
me.audio.playTrack( "ld23-theme" );// nostalegico

	
	},

    update: function() {
        if( me.input.isKeyPressed('enter')) {
            me.state.change(me.state.PLAY);
        }
        if ( this.counter > 0 )
        {
            this.counter--;
        }
        if ( this.entercount > 10 )
        {
            this.entercount = 0;
        }
        this.enterCount++;
        // have to force redraw :(
        me.game.repaint();
    },

    draw: function(context) {
        context.drawImage( this.splash, 0, 0 );
        context.drawImage( this.title, 0, 80 + ( this.counter / 5.85 ) );
        if ( this.counter == 0 && this.entercount < 5 )
        {
            context.drawImage( this.cta, 200, 420 );
        }
    },

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

var GameOverScreen = me.ScreenObject.extend(
{
    init: function()
    {
        this.parent( true );
    },
    
    onResetEvent: function()
    {
        if ( !this.background )
        {
            this.font = new me.BitmapFont( "32x32_font", 32 );
            this.font.set("center", 1);
            
            this.font2 = new me.BitmapFont( "16x16_font", 16);
            this.font2 .set("center", 1);
            
            this.background = me.loader.getImage( "end_background" );
            this.great = me.loader.getImage( "end_great" );
            this.terrible = me.loader.getImage( "end_terrible" );
            
        }
        me.audio.playTrack( "ld23-theme2" );
    },
    
    draw: function( context, x, y )
    {
        context.drawImage( this.background, 0, 0 );
        context.drawImage( me.game.lives >= 0 ? this.great : this.terrible, me.game.lives >= 0 ? 200 : 130, 50 );
        
		
		
        var text = new Array();
   
        if ( me.game.kills == 0 )
        {
            text[0] = "OOPS!WHAT HAPPENED";
            text[1] = "PLAYER";
	    
	    
	    pantaprincipal.style.left="0px"
	   	    document.getElementById("facebook").style.display="block";
	  
	      	document.getElementById("facebook").style.left="5%";
		
		document.getElementById("Twitter").style.top="45%";
		document.getElementById("Twitter").style.left="5%";
		
		
		
		  document.getElementById("btnleft").style.left="-110%";
		 document.getElementById("btnright").style.left="-110%";
		 document.getElementById("btnup").style.left="-110%";
	 document.getElementById("btndown").style.left="-110%";	
	    
        }
        else if ( me.game.kills < 10 )
        {
            text[0] = "BAD TO BEGIN .";
            text[1] = "WHAT IF YOU TRY AGAIN";
            text[2] = "OK";
	    
	      pantaprincipal.style.left="0px"
	   document.getElementById("facebook").style.display="block";
	      	document.getElementById("facebook").style.left="5%";
		
		document.getElementById("Twitter").style.top="45%";
		document.getElementById("Twitter").style.left="5%";
		
		
		
		  document.getElementById("btnleft").style.left="-110%";
		 document.getElementById("btnright").style.left="-110%";
		 document.getElementById("btnup").style.left="-110%";
	 document.getElementById("btndown").style.left="-110%";	
	    
	    
        }
        else if ( me.game.kills < 50 )
        {   text[0] = "HEY PLAYER";
            text[1] = "I GUESS IT'S NOT SO BAD...";
	    text[2] = "MUST PLAY TO WIN";
	    
	      pantaprincipal.style.left="0px"
	   document.getElementById("facebook").style.display="block";
	      	document.getElementById("facebook").style.left="5%";
		
		document.getElementById("Twitter").style.top="45%";
		document.getElementById("Twitter").style.left="5%";
		
		
		
		  document.getElementById("btnleft").style.left="-110%";
		 document.getElementById("btnright").style.left="-110%";
		 document.getElementById("btnup").style.left="-110%";
	 document.getElementById("btndown").style.left="-110%";	
        }
        else if ( me.game.kills == 69)
        {
            text[0] = "VERY GOOD!";
	    
	      pantaprincipal.style.left="0px"
	   document.getElementById("facebook").style.display="block";
	      	document.getElementById("facebook").style.left="5%";
		
		document.getElementById("Twitter").style.top="45%";
		document.getElementById("Twitter").style.left="5%";
		
		  document.getElementById("btnleft").style.left="-110%";
		 document.getElementById("btnright").style.left="-110%";
		 document.getElementById("btnup").style.left="-110%";
	 document.getElementById("btndown").style.left="-110%";	
        }
        else if ( me.game.kills < 200 )
        {
            text[0] = "FANTASTIC!";
            text[1] = "VERY VERY GOOD!";
	    
	      pantaprincipal.style.left="0px"
	   document.getElementById("facebook").style.display="block";
	      	document.getElementById("facebook").style.left="5%";
		
		document.getElementById("Twitter").style.top="45%";
		document.getElementById("Twitter").style.left="5%";
		
		
		
		  document.getElementById("btnleft").style.left="-110%";
		 document.getElementById("btnright").style.left="-110%";
		 document.getElementById("btnup").style.left="-110%";
	 document.getElementById("btndown").style.left="-110%";	
        }
        else if ( me.game.kills < 400 )
        {
            text[0] = "OH GREAT...";
	    
	      pantaprincipal.style.left="0px"
	   document.getElementById("facebook").style.display="block";
	      	document.getElementById("facebook").style.left="5%";
		
		document.getElementById("Twitter").style.top="45%";
		document.getElementById("Twitter").style.left="5%";
		
		
		
		  document.getElementById("btnleft").style.left="-110%";
		 document.getElementById("btnright").style.left="-110%";
		 document.getElementById("btnup").style.left="-110%";
	 document.getElementById("btndown").style.left="-110%";	
            
        }
        else
        {
            text[0] = "SHARE IF YOU LIKE THIS GAME!!";
	    text[1] = "leave feedback!!";
	    text[2] = "TO BE  CONTINUE.... !!";
	      pantaprincipal.style.left="0px"
	   document.getElementById("facebook").style.display="block";
	      	document.getElementById("facebook").style.left="5%";
		
		document.getElementById("Twitter").style.top="45%";
		document.getElementById("Twitter").style.left="5%";
		
		
		
		  document.getElementById("btnleft").style.left="-110%";
		 document.getElementById("btnright").style.left="-110%";
		 document.getElementById("btnup").style.left="-110%";
	 document.getElementById("btndown").style.left="-110%";	
        }

        var killString = "KILLS :" + me.game.kills;
        this.font.draw( context, killString, 220, 130);

		    
		
        for ( var i = 0; i < text.length; i++ )
        {
            
            this.font2.draw( context, text[i], 220, 230 + ( i * 30 ) );
        }
    }
});

window.onReady( function()
{
         
            /*agregamos publicidad*/
				//addAdsPrincipal("contenidopublicidadprincipal","http://asikersoft.com/static/dragon_ball/majin_buu/bannerInicial.html");


				
    jsApp.onload();

	
	
	
 function convertVersionNumber(ver) {
     var hashVersion = {
         '18.0': '1.0.1',
         '18.1': '1.1',
         '26.0': '1.2',
         '28.0': '1.3',
         '30.0': '1.4',
         '32.0': '1.5'
     }
     var rver = ver;
     var sStr = ver.substring(0, 4);
     if (hashVersion[sStr]) {
         rver = hashVersion[sStr];
     }
     return (rver);

 } function getVersion() {
     if (navigator.userAgent.match(/(mobile|tablet)/i)) {
         var ffVersionArray = (navigator.userAgent.match(/Firefox\/([\d]+\.[\w]?\.?[\w]+)/));
         if (ffVersionArray.length === 2) {
             return (convertVersionNumber(ffVersionArray[1]));
         }
     }
     return (null); 
}




			
			 document.getElementById("btninstructionsstart").addEventListener("click", function () {
				
  me.audio.play("botonpush");
				document.getElementById("btninstructionscortina").style.backgroundImage=  "url("+me.loader.getImage('overlay').src+")";
			
		if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
						
			windowmenustartinstructions.style.display="block";
			
			
			}, false);
			
			
				 document.getElementById("btninstructionsback").addEventListener("click", function () {
		
		  me.audio.play("botonpush");
		
		if (navigator.vibrate) {
                         navigator.vibrate(50);
                     }
					 
					 	windowmenustartinstructions.style.display="none";
			
			
				}, false);
			
	
 
 document.getElementById("btnpushstart").addEventListener("click", function () {
	
				 windowmainmenustart.style.backgroundColor="rgba(0, 0, 0, 0.68)";
			 
			if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
					 
					             me.audio.play( "lazer" );
					 
document.getElementById("pantaprincipalsplash").style.backgroundImage ='url('+me.loader.getImage('introfondo2').src +')';


	btnpushstart.style.display="none";
		
			 
		 var introstartmenu0 = setInterval(function () {
			 windowmainmenustart.style.backgroundColor="black";
			 
			 
		 clearInterval(introstartmenu0);
		 }, 5500);
			 
			 
		 var introstartmenu = setInterval(function () {
		 	document.getElementById("pantaprincipalsplash").style.backgroundImage=  "url("+me.loader.getImage('fondomenu').src+")";
		   windowmainmenustart.style.backgroundColor="transparent";	
		     clearInterval(introstartmenu);
			
        }, 6000);
		
		
		
			
		
		
		 var introstartmenu1 = setInterval(function () {
			
			titlegame.style.left="30%";
			btnplay.style.left="50%";
			btnlevelsstart.style.left="55%";
			btninstructionsstart.style.left="45%";
				document.getElementById("facebook").style.left="50%";
			
		    clearInterval(introstartmenu1);
			
        }, 7000);
					   
					   
					   
		
	
	   
}, false);
	
	
    
      document.getElementById("btnplay").addEventListener("click", function () {
		  
            me.audio.playTrack( "botonpush" );
      /*agregamos publicidad*/
	if (navigator.onLine === true) {

    	document.getElementById("ventanapublicidad").style.left="0px";
	
		
		
		var deviceplay = navigator.userAgent
if (deviceplay.match(/Iphone/i)|| deviceplay.match(/Ipod/i)|| deviceplay.match(/Android/i)|| deviceplay.match(/J2ME/i)|| deviceplay.match(/BlackBerry/i)|| deviceplay.match(/iPhone|iPad|iPod/i)|| deviceplay.match(/Opera Mini/i)|| deviceplay.match(/IEMobile/i)|| deviceplay.match(/Mobile/i)|| deviceplay.match(/Windows Phone/i)|| deviceplay.match(/windows mobile/i)|| deviceplay.match(/windows ce/i)|| deviceplay.match(/webOS/i)|| deviceplay.match(/palm/i)|| deviceplay.match(/bada/i)|| deviceplay.match(/series60/i)|| deviceplay.match(/nokia/i)|| deviceplay.match(/symbian/i)|| deviceplay.match(/HTC/i))
{

		//alert("movil");
		  
if(getVersion()=== "1.1"   ||  getVersion()=== "2.0" )
{

		  addAds("contenidopublicidad","publiclevelfx1.html");


}else{

		  addAds("contenidopublicidad","publiclevelfx1.html");

}


		  
		  
		}
		else
		{
		//alert("pc");

		  addAds("contenidopublicidad","publiclevelpc.html");
		} 

}

initgameok();
}, false);
      
     
	 function initgameok()
	 
	 {
		 	/*	  
				  if(me.levelDirector.getCurrentLevelId()=== "level1"){
	
	     me.audio.stopTrack();
me.audio.playTrack( "sagamajinbuutrak4" );//aventurerio
		 
           // me.audio.playTrack( "ld23-theme" );
	
}
else if(me.levelDirector.getCurrentLevelId()=== "level2"){
	
  me.audio.stopTrack();
		 me.audio.playTrack( "ld23-mars" );//aventurerio
		 
	
}*/
				  
				  
		  	if (navigator.vibrate) {

                         navigator.vibrate(100);
                     }
windowmainmenustart.style.background="white";
	  
	  document.getElementById("facebook").style.left="-135%";
	    document.getElementById("facebook").style.display="none";
	  
	  	titlegame.style.left="-50%";
			btnplay.style.left="-35%";
			btnlevelsstart.style.left="-35%";
			btninstructionsstart.style.left="-35%";
			titlegame.style.display="none";
			btnplay.style.display="none";
			btnlevelsstart.style.display="none";
			btninstructionsstart.style.display="none";
			
	   var introstartmenu0 = setInterval(function () {
		   windowmainmenustart.style.background="none";
			pantaprincipalsplash.style.display="none";
			 pantaprincipal.style.display="none";
			   me.state.change( me.state.PLAY );
			   
			   windowmainmenustart.style.display="none";
			   
			   btnpause.style.display="block";	
		  clearInterval(introstartmenu0);
			
        }, 3000);
			
	   var introstartmenu1 = setInterval(function () {
		
      
	 
	 
	  var intFrameWidth = window.innerWidth;
      var intFrameHeight = window.innerHeight;
	 
	   
     
     btnup.style.left= intFrameWidth-80+"px";
     btnup.style.top= intFrameHeight-140+"px";
     
      btndown.style.left= intFrameWidth-100+"px";
     btndown.style.top= intFrameHeight-70+"px";
     
     
       btnleft.style.left= 5+"px";
     btnleft.style.top= intFrameHeight-70+"px";
     
     
       btnright.style.left= 80+"px";
     btnright.style.top= intFrameHeight-70+"px";
	 
	 btnpause.style.right= "2%";
     btnpause.style.top= 20+"px";
     
     btnreload.style.left= 1+"%";
     
    
	 
     
  
	
	      	document.getElementById("facebook").style.left="-50%";
		
		
		document.getElementById("Twitter").style.left="-100px";
		
		  clearInterval(introstartmenu1);
			
        }, 4000);
		
   
		 
	 }
	

      
          document.getElementById("facebook").addEventListener("click", 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  majin buu from  firefox os !"));
    
   
}, false);


	
			document.getElementById("btnlevelsstart").addEventListener("click", function () {
				  me.audio.play("botonpush");
				
				  	if (navigator.vibrate) {

                         navigator.vibrate(100);
                     }
            windowmainmenustartlevels.style.display = "block";

			 
	   var introloadmenulevel = setInterval(function () {
		 
		 
	
	
	
		document.getElementById("windowmainmenustartlevels").style.backgroundImage=  "url("+me.loader.getImage('overlay').src+")";

			
			
			
			if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
        clearInterval(introloadmenulevel);
        }, 10);
		
	
		  var introloadmenulevel2 = setInterval(function () {
		 windowmainmenustartlevels.style.backgroundColor="#DBBB30";
        clearInterval(introloadmenulevel2);
        }, 500);
		
		
		
		var introloadmenulevel3 = setInterval(function () {
	
		 windowmainmenustartlevels.style.backgroundColor="#DBBB30";
		 	contenedor1.style.display="block";
        clearInterval(introloadmenulevel3);
        }, 600);
		
			
		
		 
		}, false);
		
		
	document.getElementById("btnlevelback").addEventListener("click", function () {
		  me.audio.play("botonpush");
						 windowmainmenustartlevels.style.backgroundColor="black";
				          contenedor1.style.display="none";

	   var introclosemenulevel = setInterval(function () {
		
		  windowmainmenustartlevels.style.display = "none";
        clearInterval(introclosemenulevel);
        }, 1000);
		

		}, false);
		
		 document.getElementById("btnlevel1").addEventListener("click", function () {

			me.levelDirector.loadLevel("level1");
			windowmainmenustartlevels.style.display="none";
			initgameok();
				  
				}, false);

  document.getElementById("btnlevel2").addEventListener("click", function () {
windowmainmenustartlevels.style.display="none";
			me.levelDirector.loadLevel("level2");
			initgameok();
				  
				}, false);
				
				 document.getElementById("btnlevel3").addEventListener("click", function () {
windowmainmenustartlevels.style.display="none";
			me.levelDirector.loadLevel("level3");
			initgameok();
				  
				}, false);
				 document.getElementById("btnlevel4").addEventListener("click", function () {
windowmainmenustartlevels.style.display="none";
			me.levelDirector.loadLevel("level4");
			initgameok();
				  
				}, false);
				
				 document.getElementById("btnlevel5").addEventListener("click", function () {
windowmainmenustartlevels.style.display="none";
			me.levelDirector.loadLevel("level5");
			initgameok();
				  
				}, false);
				
				 document.getElementById("btnlevel6").addEventListener("click", function () {
windowmainmenustartlevels.style.display="none";
			me.levelDirector.loadLevel("level6");
			initgameok();
				  
				}, false);
				 document.getElementById("btnlevel7").addEventListener("click", function () {
windowmainmenustartlevels.style.display="none";
			me.levelDirector.loadLevel("level7");
			initgameok();
				  
				}, false);
				
				 document.getElementById("btnlevel8").addEventListener("click", function () {
windowmainmenustartlevels.style.display="none";
			me.levelDirector.loadLevel("level8");
			initgameok();
				  
				}, false);
				 document.getElementById("btnlevel9").addEventListener("click", function () {
windowmainmenustartlevels.style.display="none";
			me.levelDirector.loadLevel("level9");
			initgameok();
				  
				}, false);
				
				
				 document.getElementById("btnrstart").addEventListener("click", function () {

				   me.audio.play("botonpush");
				 	if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
	btncontinue.style.left ="-135%"; 
		btnrstart.style.left ="-135%"; 
		btnmainmenu.style.left ="-135%"; 

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



				 


					 
				}, false);



 
              document.getElementById("btnpause").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('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);




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

  
    me.audio.play("botonpush");
	  document.getElementById("ventanapublicidad").style.left="-110%";
	  document.getElementById("btnclose").style.display="none";
	  
if(me.levelDirector.getCurrentLevelId() == "level1")
{
        me.levelDirector.reloadLevel();
		 me.state.change( me.state.PLAY );
}else{ 
		//me.levelDirector.nextLevel();
        me.levelDirector.reloadLevel();
		 me.state.change( me.state.PLAY );

		 }

   
		/*removemos publicidad*/
		removeAds("contenidopublicidad");


	
}, false);



function mipublicidadcross(){
	
	
    	document.getElementById("ventanapublicidad").style.left="0px";

      document.getElementById("btnclose").style.display ="none";
		
		
		
		var device = navigator.userAgent
if (device.match(/Iphone/i)|| device.match(/Ipod/i)|| device.match(/Android/i)|| device.match(/J2ME/i)|| device.match(/BlackBerry/i)|| device.match(/iPhone|iPad|iPod/i)|| device.match(/Opera Mini/i)|| device.match(/IEMobile/i)|| device.match(/Mobile/i)|| device.match(/Windows Phone/i)|| device.match(/windows mobile/i)|| device.match(/windows ce/i)|| device.match(/webOS/i)|| device.match(/palm/i)|| device.match(/bada/i)|| device.match(/series60/i)|| device.match(/nokia/i)|| device.match(/symbian/i)|| device.match(/HTC/i))
{

		//alert("movil");
		  
if(getVersion()=== "1.1")
{

		  addAds("contenidopublicidad","publiclevelfx1.html");


}else{

		  addAds("contenidopublicidad","publiclevelfx1.html");

}

		}
		else
		{
		//alert("pc");

		  addAds("contenidopublicidad","publiclevelpc.html");
		} 

}
	




        document.getElementById("btncontinue").addEventListener("click", function () {
  me.audio.play("botonpush");
	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("ventanatabletgameover").addEventListener("click", function () {
	location.reload(true); 
	
}, false);


	


 document.getElementById("ventanatabletscore").addEventListener("click", function () {
	  me.audio.play("botonpush");
	if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }		
	  ventanatabletscore.style.display="none";
      btnpause.style.display="block";
//me.state.change( me.state.PLAY );
	 
//continuarlevel = false;
	 
	 me.levelDirector.nextLevel();


	 
       /*agregamos publicidad*/
	if (navigator.onLine === true) {

mipublicidadcross();
initgameok();

	}else
	{
		initgameok();
		 me.levelDirector.reloadLevel();
		 me.state.change( me.state.PLAY );
	}
	 
	 
	 
	 
	 
		
}, false);







     document.getElementById("btnmainmenu").addEventListener("click", function () {
		 	if (navigator.vibrate) {
                         navigator.vibrate(100);
                     }
					 
					 
					 btnclose.style.display="none";	
					 
					 
	btnpause.style.display="none";	
	cortina.style.display="block";	
	
	
			var cortina1= setInterval(function () {
		cortina.style.backgroundColor="black";
	
        clearInterval(cortina1);
        }, 600);
	
		var cortina2 = setInterval(function () {
		
		 
	
windowmainmenustart.style.left="0px";
windowmainmenustart.style.display="block";	 
pantaprincipalsplash.style.display="block";	
pantaprincipal.style.display="block";	

  
	    document.getElementById("facebook").style.display="block";
	  
            titlegame.style.left="30%";
			btnplay.style.left="50%";
			btnlevelsstart.style.left="55%";
			btninstructionsstart.style.left="45%";
			document.getElementById("facebook").style.left="50%";

			
			
			
			
			titlegame.style.display="block";
			btnplay.style.display="block";
			btnlevelsstart.style.display="block";
			btninstructionsstart.style.display="block";
			
		windowmainmenu.style.left ="-100%";
		btncontinue.style.left ="-135%"; 
		btnrstart.style.left ="-135%"; 
		btnmainmenu.style.left ="-135%"; 
		

		
		

		
		btnup.style.left ="-135%"; 
		btndown.style.left ="-135%"; 
		btnleft.style.left ="-135%"; 
		btnright.style.left ="-135%"; 
        btnreload.style.left ="-135%"; 
		 	



   clearInterval(cortina2);
        }, 2000);
		
		
		
			var cortina3 = setInterval(function () {
				cortina.style.backgroundColor="transparent";	
		cortina.style.display="none";	
	    clearInterval(cortina3);
        }, 3000);
		

		
}, false);


     document.getElementById("btnlefth").addEventListener("click", function () {
		 	if (navigator.vibrate) {
                         navigator.vibrate(100);
			}
			
				 document.getElementById("help").style.backgroundImage= "url("+me.loader.getImage('mover1').src+")";	
				  document.getElementById("help").style.transform="scalex(-1)";
				   document.getElementById("help").style.width="150%";
                 document.getElementById("help").style.height="100%";
				 document.getElementById("help").style.bottom="20%";
				 document.getElementById("help").style.left="-45%";
			//	windowmenustartinstructions.style.backgroundColor="#C5AAF3";

			
}, false);


     document.getElementById("btnrighth").addEventListener("click", function () {
		 	if (navigator.vibrate) {
                         navigator.vibrate(100);
			}
			
		 document.getElementById("help").style.backgroundImage="url("+me.loader.getImage('mover1').src+")";	
				  document.getElementById("help").style.transform="scalex(1)";
				  
				  
				  
                  document.getElementById("help").style.width="150%";
                 document.getElementById("help").style.height="100%";
				 document.getElementById("help").style.left="0%";
				 	//windowmenustartinstructions.style.backgroundColor="#906DCB";

}, false);

    document.getElementById("btnuph").addEventListener("click", function () {
		 	if (navigator.vibrate) {
                         navigator.vibrate(100);
			}
			
			 document.getElementById("help").style.backgroundImage= "url("+me.loader.getImage('saltar1').src+")";	
				 
				 document.getElementById("help").style.width="120%";
                 document.getElementById("help").style.height="150%";
				 document.getElementById("help").style.bottom="20%";
				 document.getElementById("help").style.left="0%";
				   windowmenustartinstructions.style.transform="scaleX(1)";

}, false);

    document.getElementById("btndownh").addEventListener("click", function () {
		 	if (navigator.vibrate) {
                         navigator.vibrate(100);
			}

			 document.getElementById("help").style.backgroundImage= "url("+me.loader.getImage('poder1').src+")";	
				 document.getElementById("help").style.width="150%";
                 document.getElementById("help").style.height="100%";
				 document.getElementById("help").style.bottom="0%";
				 document.getElementById("help").style.left="20%";
//windowmenustartinstructions.style.backgroundColor="#CB38C9";
}, false);


});


function addAdsPrincipal(idContenedorPrincipal,urlAdsPrincipal){
	if(typeof(idContenedorPrincipal) === "undefined"){
		idContenedorPrincipal = 'contenidopublicidadPrincipal';
	}
	if(typeof(urlAdsPrincipal) === "undefined"){
		urlAdsPrincipal = 'http://asikersoft.com/static/dragon_ball/majin_buu/bannerInicial.html';
	}
	if(navigator.onLine){
		var contenedorPrincipal = document.getElementById(idContenedorPrincipal);
		contenedorPrincipal.innerHTML = '<iframe width="320" height="80" frameBorder="0" scrolling="no" src="'+urlAdsPrincipal+'"></iframe>';
    }
}


function addAds(idContenedor,urlAds){
	if(typeof(idContenedor) === "undefined"){
		idContenedor = 'contenidopublicidad';
	}
	if(typeof(urlAds) === "undefined"){
		urlAds = 'http://asikersoft.com/static/dragon_ball/majin_buu/index.html';
	}
	
		if(navigator.onLine){
		var contenedor = document.getElementById(idContenedor);
		//contenedor.innerHTML = '<iframe width="300" height="250" frameBorder="0" scrolling="yes" src="'+urlAds+'"></iframe>';
		contenedor.innerHTML = '<iframe id="test" style="width:100%;height:100%;left:0px;top:0px;position:absolute;frame-border:0px;" src="'+urlAds+'"></iframe>';
		
		
		}
	
	}

function removeAds(idContenedor){
	if(typeof(idContenedor) === "undefined"){
		idContenedor = 'contenidopublicidad';
	}
	var contenedor = document.getElementById(idContenedor);
	//contenedor.innerHTML = '';
   // contenedor.style.left="-100px";
    
//document.getElementById("ventanapublicidad").style.left ="0%";
document.getElementById("btnclose").style.display ="block";
    

    
}
