﻿/**
 * 一定時間で画像を切り替え
 * @version 0.2 - 20:41 2010/07/16
 * CSS
 * #slides { position: relative;}
 * #slides img { position: absolute;}
 */

jQuery(function($) {
	var placeholder = $('#flash').empty(), // 画像のコンテナ
		time = 5, // 画像表示時間（秒）
		speed = 1, // フェイドインのスピード（秒）
		images = [ // 画像のパス
			'./img/flash/FLASH_10.jpg',
			'./img/flash/FLASH_12.jpg',
			'./img/flash/FLASH_9.jpg',
			'./img/flash/FLASH_11.jpg'
		],
		isLoop = true, // ループするか
		imageIdPrefix = 'slide', // 画像に付与するIDの接頭辞
		
		// 以下、変更不要
		i = 0, l = images.length, counter = 0, timer;
	
	for (; i < l; i++) {
		$('<img />').appendTo(placeholder).attr({
			'id': imageIdPrefix + i,
			'src': images[i],
			'alt': ''
		}).css({ 'opacity': '0' });
	}
	
	tween();
	timer = setInterval(tween, time * 1000);
	
	function tween() {
		$('#' + imageIdPrefix + counter).css({ 'opacity': '0' }).appendTo(placeholder).fadeTo(speed * 1000, 1);
		counter = counter < l - 1 ? counter + 1 : 0;
		if (!isLoop && counter == l) clearInterval(timer);
	}
});

