package my.name;

import android.content.Intent;
import android.net.Uri;

public class Script {
	MascotActivity activity;
	int state;
	long time;	
	
	public Script(MascotActivity a) {
		activity=a;
	}
	
	void open(String uri) {
		Intent i=new Intent();
		i.setAction(Intent.ACTION_VIEW);
		i.setData(Uri.parse(uri));
		activity.startActivity(i);
	}

	public void run(int s) {
		state=s;
		BitmapView view=activity.getView();
		Sound sound=activity.getSound();
		CameraView cameraView=activity.getCameraView();

		String text[]=null;
		int next[]=null;
		
		while (text==null) {
			switch (state) {
			case 0:
				text=new String[]{"@\IĂ", "^C}[", "J", "n}", "", "VC"};
				next=new int[]{0, 10, 20, 30, 40, 50};
				break;
			
			case 10:
				text=new String[]{"ԂIĂ", "1", "3", "5", "߂"};
				next=new int[]{0, 11, 12, 13, 0};
				break;
			case 11: case 12: case 13:
				int t[]={1, 3, 5};
				time=System.currentTimeMillis()+t[state-11]*60000;
				state=14;
				break;
			case 14:
				long l=System.currentTimeMillis();
				if (l<time) {
					text=new String[]{""+((time-l)/1000)+"bł"};
					next=new int[]{14};
				} else {
					sound.loop(0);
					text=new String[]{"A[~߂܂H", "~߂"};
					next=new int[]{0, 15};
				}
				break;
			case 15:
				sound.stop(0);
				state=0;
				break;
			
			case 20:
				cameraView.start();
				view.setTransparent(true);
				state=21;
				break;
			case 21:
				text=new String[]{"JŔwiBe܂", "tH[JX", "]", "Be", "߂"};
				next=new int[]{0, 22, 23, 24, 25};
				break;
			case 22:
				cameraView.focus();
				state=21;
				break;
			case 23:
				cameraView.rotate();
				state=21;
				break;
			case 24:
				cameraView.take();
				state=25;
				break;
			case 25:
				cameraView.stop();
				view.setTransparent(false);
				state=0;
				break;

			case 30:
				open("geo:0,0");
				state=0;
				break;
				
			case 40:
				open("http://www.google.co.jp/");
				state=0;
				break;
				
			case 50:
				open("http://www.google.co.jp/#q=VC");
				state=0;
				break;
				
			default:
				state=0;
				break;
			}
		}
	
		view.setText(text, next);
	}
}

