/**
 * ImageNavigation javascript
 *
 * @author me-you
 */

/* IE 高速化 */
/*@cc_on
	var $document = document;
	eval('var document = $document');
@*/

/* 読み込み */
window.onload = function() {

	new classMain();
	classMain.setingObject();
	classMain.start();
}

/* ==================================================================
	グローバルイベント
=================================================================== *
/* タブ切り替え */
changePanel = function( $event_element ) {

	/* IE6処理 */
	if ( typeof document.documentElement.style.maxHeight == "undefined" ) {

		location.href = $event_element.href;
	}

	// パネル名取得します。
	var $panel_name	 = $event_element.className;
	if ( $panel_name == this.classMain.$now_page_name ) {

		return false;
	}

	/* トランザクションスタート */
	$tranc = this.classMain.startTransaction();
	if ( $tranc ) {

		return;
	}

	/* タイトルタグの書き換え */
	classMain.$now_page_name	 = $panel_name;
	var $title					 = this.classMain.$const.collTitle();
	document.title				 = $title;
	window.top.document.title	 = $title;

	/* cssの切り替え */
	var $content		 = document.getElementById( 'content' );
	$content.className	 = $panel_name;

	/* リストの削除 */
	var $display_list	 = document.getElementById( 'display_list' );
	this.classMain.deleteChildrenElement( $display_list );

	this.classMain.setingObject();
	this.classMain.start();

	/* トランザクション終了 */
	this.classMain.endTransaction();
}

/* イメージナビからのイベント画像表示 */
displayImageNavi = function( $event_element ) {

	/* IE6処理 */
	if ( typeof document.documentElement.style.maxHeight == "undefined" ) {

		location.href	 =$event_element.href;
	}

	/* イベントの起こった番号を取得します。 */
	var $image_list	 = this.classMain.$const.imageList();
	for ( var $inc in $image_list ) {

		if ( !isNaN( $inc ) ) {

			if ( $event_element.className == $image_list[$inc] ) {

				var $image_inc = $inc;
			}
		}
	}

	if ( $image_inc == this.classMain.$now_image_inc ) {

		return;
	}

	/* トランザクションスタート */
	$tranc = this.classMain.startTransaction();
	if ( $tranc ) {

		return;
	}
	this.classMain.switchDisplayImage( $image_inc );
}

/* ナビからのイベント画像表示 */
displayNavi = function( $event_element ) {

	/* IE6処理 */
	if ( typeof document.documentElement.style.maxHeight == "undefined" ) {

		location.href = $event_element.href;
	}

	/* イベントの起こった番号を取得します。 */
	var $image_inc				 = 0;
	var $class_name				 = $event_element.className;
	if ( $class_name == 'next' ) {

		$image_inc				 = this.classMain.$now_image_inc + 1;
	} else if ( $class_name == 'back' ) {

		$image_inc				 = this.classMain.$now_image_inc - 1;
	}

	if ( !$image_inc || this.classMain.$image_max_count < $image_inc || $image_inc <= 0  ) {

		return;
	}

	/* トランザクションスタート */
	$tranc = this.classMain.startTransaction();
	if ( $tranc ) {

		return;
	}

	this.classMain.switchDisplayImage( $image_inc );
}

/* ビューアを表示します。 */
openViewer = function() {

	/* 画像の情報を取得します。 */
	var $image_inc						 = this.classMain.$now_image_inc;
	var $image_list						 = this.classMain.$const.imageList();
	var $display_area_element			 = document.getElementById( 'display_area' );
	var $image_type						 = $display_area_element.className;

	/* 値取得用 element */
	var $body_element 					 = document.getElementsByTagName( 'body' )[ 0 ];
	var $container						 = document.getElementById( 'container' );

	/* バックグランド */
	var $ground_element					 = document.getElementById( 'viewer_ground' );
	$ground_element.style.display		 = 'block';
	$ground_element.style.width			 = $body_element.clientWidth + 'px';
	$ground_element.style.height		 = $body_element.clientHeight + 'px';

	var $setWidth						 = 0;
	var $setHeight						 = 0;
	var $setOffset						 = 0;
	var $buttonOffset					 = 0;
	if( $image_type == 'height' ) {

		$setWidth						 = 740;
		$setHeight						 = 1110;
		$setOffset						 = $container.offsetLeft;
		$buttonOffset					 = $container.offsetLeft + $setWidth + 20;
	} else if ( $image_type == 'width' ) {

		$setWidth						 = 800;
		$setHeight						 = 600;
		$setOffset						 = ( $container.offsetLeft - 20 );
		$buttonOffset					 = $container.offsetLeft + $setWidth;
	}

	/* 操作エリア */
	var $viewer_box_element				 = document.getElementById( 'viewer_box' );
	$viewer_box_element.style.display	 = 'block';
	$viewer_box_element.style.left		 = $setOffset + 'px';

	/* 表示エリア */
	var $divs							 = $viewer_box_element.getElementsByTagName( 'div' );
	var $count							 = $divs.length;
	var $inc							 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $divs[$inc] != undefined ) {

			switch ( $divs[$inc].className ) {
				case 'viewer':

						/* 表示エリア */
						$divs[$inc].style.width			 = $setWidth + 'px';
						$divs[$inc].style.height		 = $setHeight + 'px';
					break;
				case 'buttom_area':

						/* ボタンエリア */
						$divs[$inc].style.left			 = $buttonOffset + 'px';
					break;
			}
		}
	}

	var $imgs		 = $viewer_box_element.getElementsByTagName( 'img' );
	var $count		 = $imgs.length;
	var $inc		 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $imgs[$inc] != undefined ) {
			switch ( $imgs[$inc].className ) {
				case 'view_img':

						/* 拡大表示用イメージ */
						$imgs[$inc].style.width		 = $setWidth + 'px';
						$imgs[$inc].style.height	 = $setHeight + 'px';
						$imgs[$inc].style.top		 = 0;
						$imgs[$inc].style.left		 = 0;
						new Draggable( $imgs[$inc] );
					break;
			}
		}
	}

	this.classMain.$coll_viewer			 = true;
	this.classMain.$minWidth			 = $setWidth;
}

/* リサイズ */
window.onresize = function() {

	if ( !this.classMain.$coll_viewer ) {

		return false;
	}

	/* 画像の情報を取得します。 */
	var $display_area_element			 = document.getElementById( 'display_area' );
	var $image_type						 = $display_area_element.className;

	/* 値取得用 element */
	var $body_element 					 = document.getElementsByTagName( 'body' )[ 0 ];
	var $container						 = document.getElementById( 'container' );

	/* バックグランド */
	var $ground_element					 = document.getElementById( 'viewer_ground' );
	$ground_element.style.display		 = 'block';
	$ground_element.style.width			 = $body_element.clientWidth + 'px';
	$ground_element.style.height		 = $body_element.clientHeight + 'px';

	var $setWidth						 = 0;
	var $setHeight						 = 0;
	var $setOffset						 = 0;
	var $buttonOffset					 = 0;
	if( $image_type == 'height' ) {

		$setWidth						 = 740;
		$setHeight						 = 1110;
		$setOffset						 = $container.offsetLeft;
		$buttonOffset					 = $container.offsetLeft + $setWidth + 20;
	} else if ( $image_type == 'width' ) {

		$setWidth						 = 800;
		$setHeight						 = 600;
		$setOffset						 = ( $container.offsetLeft - 20 );
		$buttonOffset					 = $container.offsetLeft + $setWidth;
	}

	/* 操作エリア */
	var $viewer_box_element				 = document.getElementById( 'viewer_box' );
	$viewer_box_element.style.display	 = 'block';
	$viewer_box_element.style.left		 = $setOffset + 'px';

	/* 表示エリア */
	var $divs							 = $viewer_box_element.getElementsByTagName( 'div' );
	var $count							 = $divs.length;
	var $inc							 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $divs[$inc] != undefined ) {

			switch ( $divs[$inc].className ) {
				case 'viewer':

						/* 表示エリア */
						$divs[$inc].style.width			 = $setWidth + 'px';
						$divs[$inc].style.height		 = $setHeight + 'px';
					break;
				case 'buttom_area':

						/* ボタンエリア */
						$divs[$inc].style.left			 = $buttonOffset + 'px';
					break;
			}
		}
	}
}


/* ==================================================================
	アクション
=================================================================== */
/* コンストラクタ */
function classMain() {

	// 定数オブジェクト
	this.$const;

	// 変数
	this.$now_image_inc;
	this.$now_image_offset;
	this.$now_page_name;
	this.$image_max_offset;
	this.$image_max_count;
	this.$displays_list_element;
	this.$minWidth;
	this.$coll_viewer;
	this.$trans_flag;
}

/* コンストラクタを設定します。 */
classMain.setingObject = function () {

	this.$const					 = new classConst();

	this.$now_image_inc			 = 1;
	this.$now_image_offset		 = 1;
	this.$now_page_name			 = undefined;
	this.$image_max_offset		 = undefined;
	this.$image_max_count		 = undefined;
	this.$displays_list_element	 = undefined;
	this.$minWidth				 = undefined;
	this.$coll_viewer			 = undefined;
	this.$trans_flag			 = undefined;
}

/* スクリプト起動します。 */
classMain.start = function() {

	/* 現在のページを取得します。 */
	var $now_page			 = document.getElementById( 'content' );
	this.$now_page_name		 = $now_page.className;

	this.creatViewer();
	this.setDisplayArea();
	this.creatNavi();
}

/* イメージナビを作成します。 */
classMain.creatNavi = function() {

	/* 表示イメージリストを取得します。 */
	var $image_list			 = this.$const.imageList();
	this.$image_max_offset	 = Math.ceil( $image_list.length / this.$const.$display_limit );
	var $now_image_offset	 = Math.ceil( this.$now_image_inc / this.$const.$display_limit );
	var $reduction_path		 = this.$const.$reduction_path;
	var $origin_path		 = this.$const.$origin_path;

	/* ボタンをイベント化します。 */
	var $view_list			 = document.getElementById( 'view_list' );
	var $as					 = $view_list.getElementsByTagName( 'a' );
	var $count				 = $as.length;
	var $inc				 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $as[$inc] != undefined ) {
			switch ( $as[$inc].className ) {
				case 'list_back':

						/* 前のリストへボタン */
						if ( $now_image_offset <= 1 ) {

							$as[$inc].style.display		 = 'none';
						} else {

							$as[$inc].style.display		 = 'block';
						}

						/* イベント化 */
						this.ElementToAddEvent(
												$as[$inc],
												'click',
												this.buttonBackImageNavi
											 );
					break;
				case 'list_next':

						/* 次のリストへボタン 規定数を超えた場合表示します。 */
						if ( this.$image_max_offset <= $now_image_offset ) {

							$as[$inc].style.display		 = 'none';
						} else {

							$as[$inc].style.display		 = 'block';
						}

						/* イベント化 */
						this.ElementToAddEvent(
												$as[$inc],
												'click',
												this.buttonNextImageNavi
											 );
					break;
			}
		}
	}

	/* 新たな画像elementを生成します。 */
	var $display_list			 = document.getElementById( 'display_list' );
	this.deleteChildrenElement( $display_list );

	var $comment_list			 = this.$const.commentList();
	for ( var $inc in $image_list ) {

		if ( !isNaN( $inc ) ) {

			var $div_obj		 = document.createElement( 'div' );
			$div_obj.className	 = 'individual';

			var $a_obj			 = document.createElement( 'a' );
			$a_obj.className	 = $image_list[$inc];
			$a_obj.innerHTML	 = $comment_list[$inc];
			if ( typeof document.documentElement.style.maxHeight == "undefined" ) {

				$a_obj.href			 = './' + $image_list[$inc] + '.html';
			} else {

				$a_obj.href			 = 'javascript:void(0)';
			}

			this.ElementToAddEvent(
									$a_obj,
									'click',
									window.displayImageNavi,
									$a_obj
								 );

			$div_obj.appendChild( $a_obj );
			if ( $display_list != null && $display_list != undefined ) {
				$display_list.appendChild( $div_obj );
			}
		}
	}

	if ( $display_list != null && $display_list != undefined ) {

		/* イメージナビのサイズを指定します。 */
		var $display_list_width					 = this.$image_max_count * this.$const.$display_element_width;
		var $move_distance						 = this.$const.$display_limit
													* this.$const.$display_element_width
													* ( this.$now_image_offset - $now_image_offset );
		$display_list.style.left				 = $move_distance + 'px';
		$display_list.style.width				 = $display_list_width + 'px';
		this.$displays_list_element				 = $display_list;
		this.$displays_list_element.className	 = $image_list[this.$now_image_inc] + ' clearfix';
		this.$now_image_offset					 = $now_image_offset;

	}
}

/* イメージナビ 次へボタンイベント */
classMain.buttonNextImageNavi = function () {

	/* トランザクションスタート */
	$tranc = this.classMain.startTransaction();
	if ( $tranc ) {

		return;
	}

	/* 終点の場合動かない。 */
	var $now_offset					 = this.classMain.$now_image_offset;
	var $max_offset					 = this.classMain.$image_max_offset;
	if ( $max_offset <= $now_offset ) {

		this.classMain.endTransaction();
		return;
	}

	/* ボタンの追加と削除します。 */
	var $aim_offset			 = $now_offset + 1;
	var $view_list			 = document.getElementById( 'view_list' );
	var $as					 = $view_list.getElementsByTagName( 'a' );
	var $count				 = $as.length;
	var $inc				 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $as[$inc] != undefined ) {
			switch ( $as[$inc].className ) {
				case 'list_back':

						/* 前のリストへボタン */
						if ( 1 <= $aim_offset ) {

							$as[$inc].style.display		 = 'block';
						}
					break;
				case 'list_next':

						/* 次のリストへボタン 終点なら非表示 */
						if ( $max_offset <= $aim_offset ) {

							$as[$inc].style.display		 = 'none';
						}
					break;
			}
		}
	}

	/* 距離を計算し動かします。 */
	var $now_aim					 = this.classMain.$displays_list_element.offsetLeft;
	var $move_distance				 = this.classMain.$const.$display_limit
										* this.classMain.$const.$display_element_width
										+ $now_aim;
	this.classMain.$now_image_offset = $aim_offset;
	new Effect.MoveBy(
						this.classMain.$displays_list_element
						, 0
						, '-' + $move_distance
						,{
							duration : 0.7
							,fps : 80
							,afterFinishInternal: function() {

								/* トランザクション終了 */
								window.classMain.endTransaction();
							}
						}
					 );
}

/* イメージナビ 前へボタンイベント */
classMain.buttonBackImageNavi = function () {

	/* トランザクションスタート */
	$tranc = this.classMain.startTransaction();
	if ( $tranc ) {

		return;
	}

	/* 始点の場合動かない。 */
	var $now_offset					 = this.classMain.$now_image_offset;
	if ( $now_offset <= 1 ) {

		this.classMain.endTransaction();
		return;
	}

	/* ボタンの追加と削除します。 */
	var $aim_offset			 = $now_offset - 1;
	var $view_list			 = document.getElementById( 'view_list' );
	var $as					 = $view_list.getElementsByTagName( 'a' );
	var $count				 = $as.length;
	var $inc				 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $as[$inc] != undefined ) {
			switch ( $as[$inc].className ) {
				case 'list_back':

						/* 前のリストへボタン 始点なら非表示 */
						if ( $aim_offset <= 1 ) {

							$as[$inc].style.display		 = 'none';
						}
					break;
				case 'list_next':

						/* 次のリストへボタン */
						if ( $aim_offset < this.classMain.$image_max_offset ) {

							$as[$inc].style.display		 = 'block';
						}
					break;
			}
		}
	}

	/* elementを動かします。 */
	var $move_distance				 = this.classMain.$const.$display_limit
										* this.classMain.$const.$display_element_width;
	this.classMain.$now_image_offset = $aim_offset;
	new Effect.MoveBy(
						this.classMain.$displays_list_element
						, 0
						, $move_distance
						,{
							duration : 0.7
							,fps : 80
							,afterFinishInternal: function() {

								/* トランザクション終了 */
								window.classMain.endTransaction();
							}
						}
					 );
}

/* 表示画像を切り替えます。 */
classMain.switchDisplayImage = function ( $key ) {

	var $image_inc				 = $key;

	/* 画像の情報を取得します。 */
	var $image_list				 = this.$const.imageList();
	var $comment_list			 = this.$const.commentList();
	var $image_type_list		 = this.$const.imageTypetList();
	var $reduction_path			 = this.$const.$reduction_path;
	var $origin_path			 = this.$const.$origin_path;

	/* コメントを表示します。 */
	var $display_area		 = document.getElementById( 'display_area' );
	var $ps					 = $display_area.getElementsByTagName( 'p' );
	var $count				 = $ps.length;
	var $inc				 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $ps[$inc] != undefined ) {

			/* コメントを入力 */
			$ps[$inc].innerHTML	 = $comment_list[$image_inc];
		}
	}

	/* 必須値を設定します。 */
	$display_area.className					 = $image_type_list[$image_inc];
	this.$displays_list_element.className	 = $image_list[$image_inc];
	this.$now_image_inc						 = parseFloat( $image_inc );

	/* イベントボタン取得 */
	var $display_box = document.getElementById( 'display_box' );
	var $as			 = $display_box.getElementsByTagName( 'a' );
	var $count		 = $as.length;
	var $inc		 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $as[$inc] != undefined ) {
			switch ( $as[$inc].className ) {
				case 'back':

						/* 戻るボタン */
						if( $image_inc <= 1 ) {

							$as[$inc].style.display		 = 'none';
						} else {

							$as[$inc].style.display		 = 'block';
						}
					break;
				case 'next':

						/* 次へボタン */
						if ( this.$image_max_count <=  $image_inc ) {

							$as[$inc].style.display		 = 'none';
						} else {

							$as[$inc].style.display		 = 'block';
						}
					break;
			}
		}
	}

	/* イメージの値を入れます。 */
	var $imgs		 = document.getElementsByTagName( 'img' );
	var $count		 = $imgs.length;
	var $inc		 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $imgs[$inc] != undefined ) {
			switch ( $imgs[$inc].className ) {
				case 'view_img':

						/* 拡大表示用イメージ */
						$imgs[$inc].alt			 = $comment_list[$image_inc];
						$imgs[$inc].src			 = $origin_path + $image_list[$image_inc] + '.jpg';
					break;
				default :

						/* 拡大前用イメージ */
						$imgs[$inc].alt			 = $comment_list[$image_inc];
						$imgs[$inc].src			 = $reduction_path + $image_list[$image_inc] + '.jpg';
					break;
			}
		}
	}

	/* トランザクションエンド */
	this.endTransaction();
}

/* 最初の画像とナビを作成します。 */
classMain.setDisplayArea = function () {

	/* 画像の情報を取得します。 */
	var $image_list			 = this.$const.imageList();
	var $comment_list		 = this.$const.commentList();
	var $image_type_list	 = this.$const.imageTypetList();
	var $reduction_path		 = this.$const.$reduction_path;
	var $origin_path		 = this.$const.$origin_path;
	this.$image_max_count	 = $image_list.length;

	/* IE6処理 */
	if ( typeof document.documentElement.style.maxHeight == "undefined" ) {

		var $url_str	 = location.href;
		var $file_name	 = $url_str.substring($url_str.lastIndexOf("/")+1, $url_str.length);
		$file_name		 = $file_name.substring(0, $file_name.indexOf("."));
		for ( var $inc in $image_list ) {

			if ( !isNaN( $inc ) ) {

				if ( $image_list[$inc] == $file_name ) {

					this.$now_image_inc = $inc;
				}
			}
		}
	}

	/* コメントを表示します。 */
	var $display_area		 = document.getElementById( 'display_area' );
	$display_area.className	 = $image_type_list[this.$now_image_inc];
	var $ps					 = $display_area.getElementsByTagName( 'p' );
	var $count				 = $ps.length;
	var $inc				 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $ps[$inc] != undefined ) {

			/* コメントを入力 */
			$ps[$inc].innerHTML	 = $comment_list[this.$now_image_inc];
		}
	}

	/* イベントボタン取得 */
	var $display_box = document.getElementById( 'display_box' );
	var $as			 = $display_box.getElementsByTagName( 'a' );
	var $count		 = $as.length;
	var $inc		 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $as[$inc] != undefined ) {
			switch ( $as[$inc].className ) {
				case 'back':

						/* 前のパネルへボタン */
						if ( this.$now_image_inc <= 1 ) {

							$as[$inc].style.display		 = 'none';
						} else {

							$as[$inc].style.display		 = 'block';
						}

					break;
				case 'next':

						/* 次のパネルへボタン */
						if ( this.$image_max_count <= this.$now_image_inc ) {

							$as[$inc].style.display		 = 'none';
						} else {

							$as[$inc].style.display		 = 'block';
						}

					break;
				case 'zoom':

						/* 拡大ボタンイベント化 */
						this.ElementToAddEvent(
												$as[$inc],
												'click',
												window.openViewer
											 );
					break;
			}
		}
	}

	/* イメージの値を入れます。 */
	var $imgs		 = document.getElementsByTagName( 'img' );
	var $count		 = $imgs.length;
	var $inc		 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $imgs[$inc] != undefined ) {
			switch ( $imgs[$inc].className ) {
				case 'view_img':

						/* 拡大表示用イメージ */
						$imgs[$inc].alt			 = $comment_list[this.$now_image_inc];
						$imgs[$inc].src			 = $origin_path + $image_list[this.$now_image_inc] + '.jpg';
					break;
				default :

						/* 拡大前用イメージ */
						$imgs[$inc].alt			 = $comment_list[this.$now_image_inc];
						$imgs[$inc].src			 = $reduction_path + $image_list[this.$now_image_inc] + '.jpg';
					break;
			}
		}
	}
}

/* ビューアを作成します。 */
classMain.creatViewer = function() {

	/* バックグランドを非表示にします。 */
	var $ground_element					 = document.getElementById( 'viewer_ground' );
	$ground_element.style.display		 = 'none';

	/* 操作エリアを非表示にします。 */
	var $viewer_box_element				 = document.getElementById( 'viewer_box' );
	$viewer_box_element.style.display	 = 'none';

	/* ボタンをイベント化します。 */
	var $viewer_element					 = this.getChildrenElement( $viewer_box_element, 'buttom_area' );
	var $children						 = $viewer_element.childNodes;
	var $count							 = $children.length;
	var $inc							 = 0;
	for ( $inc = 0; $inc <= $count; $inc++ ) {

		if ( $children[$inc] != undefined ) {
			switch ( $children[$inc].className ) {
				case 'enlarge':

						/* 拡大 */
						this.ElementToAddEvent(
												$children[$inc],
												'click',
												this.enlargeImage
											 );
					break;
				case 'collapse':

						/* 縮小 */
						this.ElementToAddEvent(
												$children[$inc],
												'click',
												this.collapseImage
											 );
					break;
				case 'close':

						/* 閉じる */
						this.ElementToAddEvent(
												$children[$inc],
												'click',
												this.closeViewer
											 );
					break;
			}
		}
	}
}

/* イメージを拡大します。 */
classMain.enlargeImage = function() {

	/* トランザクションスタート */
	$tranc = this.classMain.startTransaction();
	if ( $tranc ) {

		return;
	}

	/* 操作エリア */
	var $viewer_box_element				 = document.getElementById( 'viewer_box' );

	/* 表示エリア */
	var $viewer_element					 = this.classMain.getChildrenElement( $viewer_box_element, 'viewer' );

	/* 表示イメージ */
	var $view_img_element				 = this.classMain.getChildrenElement( $viewer_element, 'view_img' );
	$view_img_element.style.width		 = ( $view_img_element.width + ( $viewer_element.clientWidth / 2 ) ) + 'px';
	$view_img_element.style.height		 = ( $view_img_element.height + ( $viewer_element.clientHeight / 2 ) ) + 'px';

	/* トランザクションエンド */
	this.classMain.endTransaction();
}

/* イメージを縮小します。 */
classMain.collapseImage = function() {

	/* トランザクションスタート */
	$tranc = this.classMain.startTransaction();
	if ( $tranc ) {

		return;
	}

	/* 操作エリア */
	var $viewer_box_element				 = document.getElementById( 'viewer_box' );

	/* 表示エリア */
	var $viewer_element					 = this.classMain.getChildrenElement( $viewer_box_element, 'viewer' );

	/* 表示イメージ */
	var $view_img_element				 = this.classMain.getChildrenElement( $viewer_element, 'view_img' );
	if ( $view_img_element.width - ( $viewer_element.clientWidth / 2 ) < this.classMain.$minWidth ) {

		/* トランザクションエンド */
		this.classMain.endTransaction();

		return;
	}

	$view_img_element.style.top			 = 0;
	$view_img_element.style.left		 = 0;
	$view_img_element.style.width		 = ( $view_img_element.width - ( $viewer_element.clientWidth / 2 ) ) + 'px';
	$view_img_element.style.height		 = ( $view_img_element.height - ( $viewer_element.clientHeight / 2 ) ) + 'px';

	/* トランザクションエンド */
	this.classMain.endTransaction();
}

/* ビューアを閉じます。 */
classMain.closeViewer = function() {

	/* トランザクションスタート */
	$tranc = this.classMain.startTransaction();
	if ( $tranc ) {

		return;
	}

	/* バックグランド */
	var $ground_element					 = document.getElementById( 'viewer_ground' );
	$ground_element.style.display		 = 'none';

	/* 操作エリア */
	var $viewer_box_element				 = document.getElementById( 'viewer_box' );
	$viewer_box_element.style.display	 = 'none';

	/* トランザクションエンド */
	this.classMain.$coll_viewer			 = undefined;
	this.classMain.endTransaction();
}

/* 子要素を取得します。 */
classMain.getChildrenElement = function( $parent_element, $class_name, $name, $id_name, $tag_name ) {

	var $count			 = 0;
	var $child_element	 = new Array();
	var $children		 = $parent_element.childNodes;
	var $children_count	 = $children.length;
	for ( var $inc = 0; $inc <= $children_count; $inc++ ) {

		if ( $children[$inc] != undefined ) {

			if ( $class_name != undefined ) {

				if ( $children[$inc].className == $class_name ) {

					$child_element[$count] = $children[$inc];
					$count++;
				}
			} else if ( $name != undefined ) {

				if ( $children[$inc].name == $name ) {

					$child_element[$count] = $children[$inc];
					$count++;
				}
			} else if ( $id_name != undefined ) {

				if ( $children[$inc].id == $id_name ) {

					$child_element[$count] = $children[$inc];
					$count++;
				}
			} else if ( $tag_name != undefined ) {

				if ( $children[$inc].agName == $tag_name ) {

					$child_element[$count] = $children[$inc];
					$count++;
				}
			}
		}
	}

	if ( $child_element != undefined ) {

		if ( $count == 1 ) {

			$child_element = $child_element[0];
		}
		return $child_element;
	} else {

		return false;
	}
}

/* 子要素を削除します。 */
classMain.deleteChildrenElement = function( $parent_element, $class_name, $name, $id_name  ) {

	var $check_flag = false;
	if ( $class_name != undefined  || $name != undefined || $id_name != undefined ) {

		$check_flag = true;

	}

	if ( $parent_element != null && $parent_element != undefined ) {
		var $del_count		 = 0;
		var $children		 = $parent_element.childNodes;
		var $children_count	 = $children.length;
		if ( $children_count > 0 ) {
			for ( var $inc = 0; $inc <= $children_count; $inc++ ) {

				var $del_inc = $inc - $del_count;
				if ( $children[$del_inc] != undefined ) {

					if ( $class_name != undefined ) {

						if ( $children[$inc].className == $class_name ) {

								$parent_element.removeChild( $children[$del_inc] );
								$del_count++;
						}
					} else if ( $name != undefined ) {

						if ( $children[$inc].name == $name ) {

							$parent_element.removeChild( $children[$del_inc] );
							$del_count++;
						}
					} else if ( $id_name != undefined ) {

						if ( $children[$inc].id == $id_name ) {

							$parent_element.removeChild( $children[$del_inc] );
							$del_count++;
						}
					} else if ( $check_flag == false ) {

						$parent_element.removeChild( $children[$del_inc] );
						$del_count++;
					}
				}
			}
		}
	}
}

/* イベント追加します。 */
classMain.ElementToAddEvent = function( $taget_element, $event_type, $function, $argument ) {

	var $unsigned_function = function () {
											$function( $argument );
										}

	if ( $taget_element.attachEvent ) {

		$taget_element.attachEvent( "on" + $event_type, $unsigned_function );
	} else if ( $taget_element.addEventListener ) {

		$taget_element.addEventListener($event_type, $unsigned_function, true );
	} else {

		$taget_element["on" + $event_type] = $unsigned_function;
	}
}

/* トランザクション開始します。 */
classMain.startTransaction = function() {

	if ( this.$trans_flag ) {

		return true;
	} else {

		this.$trans_flag = true;
		return false;
	}
}

/* トランザクション終了します。 */
classMain.endTransaction = function() {

	this.$trans_flag = undefined;
}
