function MovieClip(element){
	element.normalize();
	this.movieElement = element;//対応するエレメントへの参照
	this.movieElement.movieClip = this;//エレメントからの参照
	this.childMovieClip = new Array();//エレメントの子ノードのムービークリップの配列
	for(var i=0; i < this.movieElement.childNodes.length; i++){
		//すべての子ノードをムービークリップに展開し配列に展開
		this.childMovieClip[i] = new MovieClip(this.movieElement.childNodes[i]);
		this.childMovieClip[i].parentClip = this;
	}
	this.frameRate = 20;//ムービーのフレームレート（f/s）
	this.leverage = 1;//再生速度倍率
	this.delayCount = 1;//再生速度倍率
	this.loop = true;//ムービーのループ再生設定（true or false）
	this.playFlag = "stop";//ムービーの再生フラグ
	this.timeline = new Array(1);//ムービーのタイムライン
	this.currentFrame = 0;//現在のフレーム
	this.nextFrame = 0;//次のフレーム
	this.lastKeyFrame = 0;//最近のキーフレーム
	this.dumpTo = false;//プロパティのダンプ先
	
	this.button = {};//ボタン

	this.alpha = 100;//エレメントの透明度
	this.scale = 100;//エレメントのスケール（%）
	this.defWidth = this.movieElement.clientWidth;//エレメントの幅の初期値（px）
	this.defHeight = this.movieElement.clientHeight;//エレメントの高さの初期値（px）
	
	this.button = new Object();//ボタンの配列
	
	var movie = this;
	
	//現在のフレームに設定されたスクリプトを実行します
	this.enterFrame = function(){
		movie.currentFrame = movie.nextFrame;
		movie.nextFrame++;
		if(movie.timeline.length <= movie.nextFrame){
			movie.nextFrame = 0;
		}
		if(!!movie.timeline[movie.currentFrame]){
			movie.lastKeyFrame = movie.timeline[movie.currentFrame];
		}
		if(movie.lastKeyFrame != "blank") eval(movie.lastKeyFrame);
	}
	
	this.dump = function(){
		movie.dumpTo.nodeValue = "FrameRate :"+ movie.frameRate +", Leverage :"+ movie.leverage  +", DelayCount :"+ movie.delayCount +", PlayFlag :"+ movie.playFlag +", PlayId :"+ movie.playId +", CurrentFrame :"+ movie.currentFrame +", NextFrame :"+ movie.nextFrame +", LastKeyFrame :"+ movie.lastKeyFrame;
	}

	this.step = function(){
		clearTimeout(movie.playId);
		var myFlag = movie.playFlag;
//		if(myFlag != "skip" || myFlag != "delay") movie.enterFrame();
		switch(myFlag){
		case "delay":
			movie.delayCount--;
			if(movie.delayCount == 0) movie.playFlag = "play";
			break;
		case "skip":
			break;
		case "stop":
			movie.enterFrame();
			movie.playFlag = "skip";
			break;
		case "play":
			if(movie.delayCount != 0) movie.delayCount = 0;
		default:
			movie.enterFrame();
			break;
		}
		if(!!movie.dumpTo) movie.dump();
		for(var button in movie.button){
			if(!!movie.button[button].fresh){
				movie.button[button].fresh();
			}
		}
		movie.playId = setTimeout(movie.step, movie.leverage * 1000 / movie.frameRate);
	}
	
	this.kill = function(){
		clearTimeout(movie.playId);
	}

	this.step();
}

//ムービークリップ内の任意の位置にムービークリップを挿入
MovieClip.prototype.attachMovie = function(index, element){
	this.childMovieClip.splice(index, 0, new MovieClip(element));
	this.movieElement.insertBefore(element, this.childMovieClip[index]);
}

//ループ再生の有無を設定
MovieClip.prototype.setLoop = function(loop){
	this.loop = !!(loop);
}

//フレームレートを設定
MovieClip.prototype.setFrameRate = function(frameRate){
	this.frameRate = Math.abs(frameRate);
}

//再生速度倍率を設定
MovieClip.prototype.leverage = function(leverage){
	this.leverage = Math.abs(leverage);
}

//タイムラインの長さを変更
MovieClip.prototype.setLength = function(length){
	this.timeline.length = Math.abs(length);
}

//タイムライン全体のフレームを設定
MovieClip.prototype.setTimeline = function(timelineArray){
	this.timeline = timelineArray;
}

//任意のキーフレームを設定
MovieClip.prototype.setKeyframe = function(frameNum, script){
	this.timeline[frameNum] = script;
}


//ムーピークリップを再生します
MovieClip.prototype.play = function(){
//this.dump(21);
	this.playFlag = (this.delayCount > 0)? "delay" : "play";
}

//ムーピークリップを停止します
MovieClip.prototype.delay = function(count){
	this.delayCount = count;
	this.playFlag = "delay";
}

//ムーピークリップを停止します
MovieClip.prototype.stop = function(){
	this.playFlag = "skip";
}

//任意のフレームに移動します。再生状態は維持されます。
MovieClip.prototype.act = function(frameNum){
	switch(this.playFlag){
	case "delay":
	case "play":
		this.playFlag = "skip";
		break;
	case "stop":
	case "skip":
	default:
		this.playFlag = (this.delayCount > 0)? "delay" : "play";
	}
}

//任意のフレームからムービークリップを再生します
MovieClip.prototype.gotoAndPlay = function(frameNum){
	this.nextFrame = frameNum;
	this.playFlag = "play";
}

//任意のフレームでムービークリップを停止します
MovieClip.prototype.gotoAndStop = function(frameNum){
	this.nextFrame = frameNum;
	this.playFlag = "stop";
}

//任意のフレームに移動します。再生状態は維持されます。
MovieClip.prototype.goto = function(frameNum){
	switch(this.playFlag){
	case "delay":
	case "play":
		this.nextFrame = frameNum;
		this.playFlag = "play";
		break;
	case "stop":
	case "skip":
	default:
		this.nextFrame = frameNum;
		this.playFlag = "stop";
	}
}

//ムービークリップの上位置
MovieClip.prototype.top = function() {
	var offsetTrail = this.movieElement;
	var offsetTop = 0;
	
	while(offsetTrail) {
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	
	if(navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != "undefined") {
		offsetTop += document.body.topMargin;
	}
	
	return (offsetTop);
}

//ムービークリップの左位置
MovieClip.prototype.left = function() {
	var offsetTrail = this.movieElement;
	var offsetLeft = 0;
	
	while(offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;
		offsetTrail = offsetTrail.offsetParent;
	}
	
	if(navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != "undefined") {
		offsetLeft += document.body.leftMargin;
	}
	
	return (offsetLeft);
}

//ムービークリップの透明度を設定
MovieClip.prototype.setAlpha = function(alpha){
	if(alpha > 100){
		this.alpha = 100;
	}else if(alpha < 0){
		this.alpha = 0;
	}else{
		this.alpha = alpha;
	}
	this.movieElement.style.filter = 'alpha(opacity="'+ this.alpha +'")';
	this.movieElement.style.opacity = this.alpha / 100;
	this.movieElement.style.MozOpacity = this.alpha / 100;
}

//ムービークリップのスケールを設定
MovieClip.prototype.setScale = function(scale){
	if(scale < 0){
		this.scale = 0;
	}else{
		this.scale = scale;
	}
	this.movieElement.style.width = (this.defWidth * this.scale / 100) +"px";
	this.movieElement.style.height = (this.defHeight * this.scale / 100) +"px";
}

//ムービークリップの再生ボタンを設定
MovieClip.prototype.setButton = function(buttonName, element){
	this.button[buttonName] = element;
	this.button[buttonName].movieClip = this;//エレメントからの参照
}

MovieClip.prototype.setOnclickAction = function(buttonName, action){
	this.button[buttonName].onclick = action;
}

MovieClip.prototype.setUpdateAction = function(buttonName, action){
	this.button[buttonName].fresh = action;
}