public void trainerBattle()
	{
		direction=(trainer[trainerToFight].direction+180)%360;

		repaint();
		messageBox=new ErrorWindow();

		if(!Mechanics.isSpecialTrainer(trainer[trainerToFight]))
			messageBox.addMessage(trainer[trainerToFight].getPreMessage(),trainer[trainerToFight].getNameAndType());
		else
			messageBox.addLargeMessage(trainer[trainerToFight].getPreMessage(),trainer[trainerToFight].getNameAndType());

		messageBox.repaint();
		while(messageBox.isVisible())
		{
			try
			{
				repaint();
				Thread.sleep(10);
			}
			catch(Exception e){e.printStackTrace();}
		}

		jf.toFront();

		evilEncounter.stop();
		maleEncounter.stop();
		femaleEncounter.stop();
		rivalEncounter.stop();
		leaderEncounter.stop();

		jf.setVisible(false);

		for(int i=0; i<6; i++)
		{
			enemy[i]=trainer[trainerToFight].getPokemon(i);
		}

		BattleWindow bwindow;

		if(trainer[trainerToFight].type==Trainer.TrainerType.GYM_LEADER)
		{
			healPokemonNoPrompt();
			bwindow=new BattleWindow(partyPokemon,enemy,"GYM",trainer[trainerToFight]);
		}
		else if(trainer[trainerToFight].type==Trainer.TrainerType.BABB||trainer[trainerToFight].type==Trainer.TrainerType.ELITE)
			bwindow=new BattleWindow(partyPokemon,enemy,"SUPER",trainer[trainerToFight]);
		else if(trainer[trainerToFight].type==Trainer.TrainerType.RIVAL)
			bwindow=new BattleWindow(partyPokemon,enemy,"RIVAL",trainer[trainerToFight]);
		else
			bwindow=new BattleWindow(partyPokemon,enemy,"TRAINER",trainer[trainerToFight]);

		trainerEnc=false;
		trainer[trainerToFight].hostile=false;

		for(int i=0; i<6; i++)
		{
			partyPokemon[i]=Battle.getPokemon(i);
		}

		alreadyBattled=true;
		moving=false;

		bwindow.thread.interrupt();

		bwindow=null;
		System.gc();
		jf.setVisible(true);
		jf.toFront();

		if(surfing)
			surfSong.loop();
		else if(bicycling&&!forceBike)
			bikeSong.loop();
		else
			bgm.loop();

		int qq = 0;
        for (Pokemon aPartyPokemon : partyPokemon) {
            if (aPartyPokemon != null)
                qq++;
        }

		if (!Mechanics.hasRemainingPokemon(partyPokemon,qq))
		{
			transition = true;
			createCurrentArea();
			return;
		}

		messageBox=new ErrorWindow();

		if(!Mechanics.isSpecialTrainer(trainer[trainerToFight]))
			messageBox.addMessage(trainer[trainerToFight].getPostMessage(),trainer[trainerToFight].getNameAndType());
		else
			messageBox.addLargeMessage(trainer[trainerToFight].getPostMessage(),trainer[trainerToFight].getNameAndType());

		messageBox.repaint();
		while(messageBox.isVisible())
		{
			try
			{
				repaint();
				Thread.sleep(10);
			}
			catch(Exception e){e.printStackTrace();}
		}

		gameEventHandler(trainer[trainerToFight]);

		jf.toFront();
	}