function TScene(ctx, PSceneManager) {

	this.SceneManager = PSceneManager;

	this.Scene = dummyScene;
	this.LastForm = 0;
	
	/*
	this.AddNewButton = function(bX, bY, bW, bH, Color1, Color2, Text ) {
	  return this.Button[this.Button.push(new TButton(ctx, X + bX, Y + bY, bW, bH, Color1, Color2, Text))-1];
	}
	*/

	this.Draw = function(){}
	this.Update = function(){}
	this.OnShow = function(){}
	this.Mouse = function(mX, mY){}
	
	this.Show = function(LastScene, sFX) {
		this.LastScene = LastScene;
		if (sFX)
			this.SceneManager.ChangeScene(this)
		else
			this.SceneManager.UseScene = this;
	}
	/*
	this.ShowMessage = function(Text) {
		this.SceneManager.MessageScene.IsShow = true;
		this.SceneManager.MessageScene.MessageText = Text;
	}
*/
	this.Close = function(sFX) {
		if (sFX)
			this.SceneManager.ChangeScene(this.LastScene)
		else
			this.SceneManager.UseScene = this.LastScene;
	}	
}

var dummyScene = new TScene(0, 0);

	function TActor() {
		this.Draw = function(){
			
		}
		this.Action = function() {
			
		}
	}
	var DummyActor = new TActor();
	
function TMessageForm(ctx, X, Y, W, H) {
	var bX = (0.5 + (W / 2 - 50) ) << 0;
	var bX2 = bX + 100;
	var bY   = Y + H - 40;
	var bY2 = bY + 30;
	this.IsShow = false;
	this.kEnter = false;
	
	this.Actor = DummyActor;
	this.Show = function(PActor) {
		this.IsShow = true;
		this.Actor = PActor;
	}
	this.Draw = function() {
		this.Actor.Draw();
		ctx.drawImage(mImg, 0, 300, 100, 30, bX, bY, 100, 30);
	}
	this.OnClick = function() {
		this.Actor.Action();
		this.IsShow = false;
	}
	this.Mouse = function(mX, mY){
		if ((mX > bX) & (mX < bX2) & (mY > bY) & (mY < bY2)) {
			this.OnClick();
			}
	}
}

function TSceneManager(ctx, X, Y, W, H, Color) {
	this.W2 = W / 2;
	this.H2 = H / 2;
	
	this.X1 = X;
	this.X2 = X + this.W2;
	this.Y1 = Y - this.H2;
	this.Y2 = H;
	this.DX = 0;
	this.DY = 0;

	this.UseScene = dummyScene;
	this.NewScene = dummyScene;
	this.Change = false;
	this.SceneSet = false;
	this.Alpha = 0;

	
	this.MessageForm = new TMessageForm(ctx, 0, (0.5 + H / 2 - 50) << 0, W, 100);
	/*var MessageForm = this.MessageForm;
	
	this.MessageForm.OnClick = function(){
		MessageForm.IsShow = false;
	}
*/
	
	this.ChangeScene = function(Scene) {
	  this.NewScene = Scene;
	  this.Change = true;
	  this.SceneSet = false;
	}

	this.Draw = function(){
	    this.UseScene.Draw();
		if (this.MessageForm.IsShow) 
			this.MessageForm.Draw();
		if (this.Change) {
		  ctx.fillStyle = Color;
		  ctx.fillRect(this.X1, this.Y1 + this.DY, W, this.H2);
		  ctx.fillRect(this.X1, this.Y2 - this.DY, W, this.H2);
		}

	}
	
	this.Mouse = function(mX, mY){
		if (this.MessageForm.IsShow) 
			this.MessageForm.Mouse(mX, mY)
		else
		if (!this.Change)
			this.UseScene.Mouse(mX, mY);	
	}
	
	this.Update = function(){

		if (this.MessageForm.IsShow) 
			{
				if (this.kEnter) 
					this.MessageForm.OnClick()
			}
		else		
		if (this.Change) {
			if (this.SceneSet) {
				if (this.DY <= 0)
					this.Change = false
				else
					this.DY-=4;
			}
			else
			if (this.DY < this.H2)
				this.DY+=4
			else {
				this.UseScene = this.NewScene;
				this.UseScene.OnShow();
				this.SceneSet = true;
			}
		}
		else
			this.UseScene.Update();
	}
	
}

