// JavaScript Document
//var slidePhoto = ["am001.jpg", "am005.jpg", "am014.jpg", "am016.jpg", "am020.jpg", "am022.jpg", "am029.jpg", "am008.jpg", "ma06.jpg", "og01.jpg", "og02.jpg", "og05.jpg", "og06.jpg", "og12.jpg", "og17.jpg"];


/*MovieClipの実行*/
window.onload = function(){
//alert(document.getElementById("slide_show"));
	window.slideShow = new MovieClip(document.getElementById("slide_show"));
	
	//counterUpdateメソッドの追加
	slideShow.counterUpdate = function(){
			this.counter.lastChild.nodeValue = this.photoCount +" / "+ slidePhoto.length;
	}
	//setupメソッドの追加
	slideShow.setup = function(){
		replaceStr = this.childMovieClip[1].movieElement.src;
		this.childMovieClip[1].setAlpha(0);
		this.childMovieClip[1].movieElement.src = replaceStr.replace(srcReg, slidePhoto[this.photoCount-1]);
		this.childMovieClip[0].setAlpha(0);
		this.childMovieClip[0].movieElement.src = replaceStr.replace(srcReg, slidePhoto[this.photoCount]);
		this.counterUpdate();
		this.photoCount++;
		this.stop();
		this.childMovieClip[1].movieElement.onload = function(){
			this.movieClip.parentClip.play();
		}
	}
	//fadeInメソッドの追加
	slideShow.fadeIn = function(factor){
		this.childMovieClip[1].setAlpha(this.childMovieClip[1].alpha + factor);
	}
	//zoomメソッドの追加
	slideShow.zoom = function(factor){
		this.childMovieClip[0].setScale(this.childMovieClip[0].scale + factor);
	}
	//opacityメソッドの追加
	slideShow.opacity = function(index, factor){
		this.childMovieClip[index].setAlpha(factor);
	}
	//fadeメソッドの追加
	slideShow.fade = function(factor){
		this.childMovieClip[1].setAlpha(this.childMovieClip[1].alpha - factor);
		this.childMovieClip[0].setAlpha(this.childMovieClip[0].alpha + factor);
	}
	//nextPhotoメソッドの追加
	slideShow.nextPhoto = function(){
		this.counterUpdate();
		replaceStr = this.childMovieClip[1].movieElement.src;
		this.childMovieClip[1].movieElement.src = replaceStr.replace(srcReg, slidePhoto[this.photoCount - 1]);
		this.childMovieClip[1].setAlpha(100);
		this.childMovieClip[0].setAlpha(0);
		if(this.photoCount >= slidePhoto.length){
			this.photoCount = 0;
		}
		this.childMovieClip[0].movieElement.src = replaceStr.replace(srcReg, slidePhoto[this.photoCount]);
		this.photoCount++;
	}
	
	
	//playButton用setOnclickAction
	var playPhoto = function(){
		slideShow.act();
	}
	//playButton用update
	var swapButton = function(){
		var srcReg = new RegExp("[^/]+\.(jpg|gif|png)$", "i");
		if(slideShow.playFlag == "stop" || slideShow.playFlag == "skip") {
			slideShow.button.playButton.src = slideShow.button.playButton.src.replace(srcReg, 'playbutton.png');
		}else{
			slideShow.button.playButton.src = slideShow.button.playButton.src.replace(srcReg, 'stopbutton.png');
		}
	}
	//nextButton用setOnclickAction
	var nextPhoto = function(){
		slideShow.goto(42);
	}
	//prevButton用setOnclickAction
	var prevPhoto = function(){
		slideShow.photoCount -= 2;
		if(slideShow.photoCount <= 0) slideShow.photoCount += slideShow.length;
		slideShow.goto(42);
	}

	
	//playButtonの追加
	slideShow.setButton("playButton", document.getElementById("play"));
	var srcReg = new RegExp("[^/]+\.(jpg|gif|png)$", "i");
	slideShow.button.playButton.playButtonImg = slideShow.button.playButton.src.replace(srcReg, 'playbutton.png');
	slideShow.button.playButton.stopButtonImg = slideShow.button.playButton.src.replace(srcReg, 'stopbutton.png');
	slideShow.setOnclickAction("playButton", playPhoto);
	slideShow.setUpdateAction("playButton", swapButton);
	
	//nextButtonの追加
	slideShow.setButton("nextButton", document.getElementById("next"));
	slideShow.setOnclickAction("nextButton", nextPhoto);

	//prevButtonの追加
	slideShow.setButton("prevButton", document.getElementById("prev"));
	slideShow.setOnclickAction("prevButton", prevPhoto);
	
	slideShow.setLoop(true);
	slideShow.setLength(14);
	slideShow.setFrameRate(20);
	slideShow.setTimeline(["movie.setup()","movie.fadeIn(5)",,,,,,,,,,,,,,,,,,,,"movie.delay(100)","movie.fade(5)",,,,,,,,,,,,,,,,,,,,"movie.nextPhoto()","movie.gotoAndPlay(21)"]);

	slideShow.counter = document.getElementById("counter");
	slideShow.photoCount = 1;
	var counterNode = document.createTextNode("");
	slideShow.counter.appendChild(counterNode);
//	slideShow.dumpTo = slideShow.counter.lastChild;
	
	slideShow.play();
}