

var js_version = 10;
var XMAX = 4;
var YMAX = 4;
var chip_name = new Array('00','01','02','03',
						  '04','05','06','07',
						  '08','09','10','11',
						  '12','13','14','15','16');



var js_version = 11;

var CHIPS = 16;
var ALLCHIPS = 17;
var BLANK = 15;
var COURSES = 4;
var UP = 0;
var RIGHT = 1;
var DOWN = 2;
var LEFT = 3;
var ERROR = -1;
var YES = 1;
var NO = 0;

var chips_set = new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
var chip = new Array(ALLCHIPS);
	for (var index = 0; index < ALLCHIPS; index++){
		chip[index] = new Image(150, 150);
		chip[index].src = 'moto_' + chip_name[index] + '.jpg';
	}

var game_flag = NO;


/////完成判定
function complete_judge()
{
	var index;

	if (game_flag == NO) return;
	for (index = 0; index < CHIPS; index++){
		if (chips_set[index] != index) return;
	}
	for (index = 0; index < CHIPS; index++){
		chips_set[index] = index;
	}
	document.images[15].src = chip[16].src;
	game_flag = NO;
}

/////ゲームを中止する
function give_up()
{
	var index;

	if (game_flag == NO) return;
	for (index = 0; index < CHIPS; index++){
		chips_set[index] = index;
		document.images[index].src = chip[index].src;
	}
	document.images[15].src = chip[16].src;
	game_flag = NO;
}

/////ゲーム開始処理
function game_start()
{
	var index, random_1, random_2, cash;

	if (game_flag == YES) return;

	for (index = 0; index < 100 ; index++){
		random_1 = Math.floor(Math.random() * 100) % BLANK;
		random_2 = Math.floor(Math.random() * 100) % BLANK;
		while (random_1 == random_2){
			random_2 = Math.floor(Math.random() * 100) % BLANK;
		}
		cash = chips_set[random_1];
		chips_set[random_1] = chips_set[random_2];
		chips_set[random_2] = cash;
	}

	for (index = 0; index < CHIPS; index++)
		document.images[index].src = chip[chips_set[index]].src;

	game_flag = YES;

	if (navigator.appVersion.indexOf('3.') != -1
			|| navigator.appVersion.indexOf('MSIE') != -1) return;

	document.embeds[1].stop();
	document.embeds[0].play(50);
}

/////コマを移動する
function move(click)
{
	var course;//0;UP 1;RIGHT 2;DOWN 3;LEFT -1;ERROR
	var blank, step, cash;

	if (game_flag == NO) return;

	if (check(click) == ERROR) return;
	course = check(click) % 10;
	blank = Math.floor(check(click) / 10);

	if (course == UP) step = XMAX;
	else if (course == RIGHT) step = -1;
	else if (course == DOWN) step = -XMAX;
	else step = 1;

	for(index = blank; index != click; index += step) {
		chips_set[index] = chips_set[index + step];
		chips_set[index + step] = BLANK;
		document.images[index + step].src = chip[BLANK].src;
		document.images[index].src = chip[chips_set[index]].src;
	}
	complete_judge();
}

/////移動できるかチェックし、可能ならブランクコマを探す
function check(click)
{
	var course, index, step;
	var axis_x = click % XMAX;

	for (course = UP; course < COURSES; course++){
		for (index = 1; ; index++){
			if (course == UP){
				step = -XMAX;
				if ( index * step + click < 0) break;
				if (chips_set[index * step + click] == BLANK)
					return ((index * step + click) * 10 + course);
			} else if (course == RIGHT){
				step = 1;
				if (index * step + axis_x >= XMAX) break;
				if (chips_set[index * step + click] == BLANK)
					return ((index * step + click) * 10 + course);
			} else if (course == DOWN){
				step = XMAX;
				if ( index * step + click >= CHIPS) break;
				if (chips_set[index * step + click] == BLANK)
					return ((index * step + click) * 10 + course);
			} else {
				step = -1;
				if (index * step + axis_x < 0) break;
				if (chips_set[index * step + click] == BLANK)
					return ((index * step + click) * 10 + course);
			}
		}
	}
	return (ERROR);
}

/////終了して指定ページにジャンプする
function go_out()
{
	window.location="./puzzle.shtml";
}














	var tr, td;
	var index = 0;

	document.write('<a href="http://ac-pink.net/b/" target="_top"><strong>ロリータ動画像</strong></a><CENTER><h4>無邪気な少女が危機一髪！ロリータ１５パズル</h4><FORM NAME="puzzle"><TABLE BORDER="4"'
		+' CELLSPACING="0" CELLPADDING="0" BGCOLOR="#000000">');

	for (tr = 0; tr < YMAX; tr++){
		document.write('<TR>');
		for (td = 0; td < XMAX; td++){
			document.write('<TD>'
				+'<A HREF="JavaScript:void(0);" onClick="move('
				+ index
				+'); return false;">'
				+'<IMG SRC="moto_'
				+ chip_name[index]
				+'.jpg"'
				+' WIDTH="150" HEIGHT="150" BORDER="0">'
				+'</A></TD>');
			index++;
		}
		document.write('</TR>');
	}
	document.write('</TABLE>');




