/*
 * グローバルナビ
 */
function setGnav(){
	$("div[id^='gnavi']").mouseover(function(){
		$(this).css('background-position', '0px 60px');
	});
	$("div[id^='gnavi']").mouseout(function(){
		$(this).css('background-position', '0px 0px');
	});
	$("div[id^='gnavi']").mousedown(function(){
		$(this).css('background-position', '0px 30px');
	});
	$("div[id^='gnavi']").mouseup(function(){
		$(this).css('background-position', '0px 30px');
	});
}

/*
 * ボタンのスタイル制御
 */
function setBtnStyle(){
	var btnObj = $("div[class='btnOff'], div[class='btnDown'], div[class='btnOver']");
	btnObj.mouseover(function(){
		$(this).attr('class', 'btnOver');
	});
	btnObj.mouseout(function(){
		$(this).attr('class', 'btnOff');
	});
	btnObj.mousedown(function(){
		$(this).attr('class', 'btnDown');
	});
	btnObj.mouseup(function(){
		$(this).attr('class', 'btnOver');
	});

	var btnObj = $("div[class='btnOff float-r'], div[class='btnDown float-r'], div[class='btnOver float-r']");
	btnObj.mouseover(function(){
		$(this).attr('class', 'btnOver float-r');
	});
	btnObj.mouseout(function(){
		$(this).attr('class', 'btnOff float-r');
	});
	btnObj.mousedown(function(){
		$(this).attr('class', 'btnDown float-r');
	});
	btnObj.mouseup(function(){
		$(this).attr('class', 'btnOver float-r');
	});

	$("div[class^='btnShort']").mouseover(function(){
		$(this).css('background-position', '0px -23px');
		$(this).css('color', '#FFFFFF');
	});
	$("div[class^='btnShort']").mouseout(function(){
		$(this).css('background-position', '0px 0px');
		$(this).css('color', '#000000');
	});
	$("div[class^='btnShort']").mousedown(function(){
		$(this).css('background-position', '0px -46px');
		$(this).css('color', '#FFFFFF');
	});
	$("div[class^='btnShort']").mouseup(function(){
		$(this).css('color', '#FFFFFF');
		$(this).css('background-position', '0px -23px');
	});
}
/*
 * 一覧テーブルのボタンスタイル制御
 */
function setListTblBtnStyle(){
	var btnObj = $("table.list_tbl input:submit, table.list_tbl input:button");
	btnObj.mouseover(function(){
		$(this).attr('class', 'on');
	});
	btnObj.mouseout(function(){
		$(this).attr('class', 'off');
	});
}

/*
 * 画面ポップアップ
 * @param url     遷移先（必須）
 * @param winName 画面名
 * @param width   幅
 * @param height  高さ
 * @return
 */
function popup(url, winName, width, height){
	if(url == '' || url == null) return false;
	var option = 'resizable=yes,scrollbars=yes';
	width = width + "";
	if(width.match(/^[1-9]{1}[0-9]*$/)){
		option += ',width=' + width;
	}
	height = height + "";
	if(height.match(/^[1-9]{1}[0-9]*$/)){
		option += ',height=' + height;
	}
	window.open(url, winName, option);
}

/*
 * 画面ポップアップ 改
 * popupの改良：サイズ固定を追加
 *
 * @param url     遷移先（必須）
 * @param winName 画面名
 * @param width   幅
 * @param height  高さ
 * @return
 */
function popup_SizeRock(url, winName, width, height){
	if(url == '' || url == null) return false;
	var option = 'resizable=no,scrollbars=no';
	width = width + "";
	if(width.match(/^[1-9]{1}[0-9]*$/)){
		option += ',width=' + width;
	}
	height = height + "";
	if(height.match(/^[1-9]{1}[0-9]*$/)){
		option += ',height=' + height;
	}
	window.open(url, winName, option);//サイズ固定
}

/*
 * submit関数
 * @param formId 該当フォームのid名（必須）
 * @param url    遷移先（文字列が入力されていれば、そちらへaction先変更）
 * @return
 */
function submitBtn(formId, url){
	if(formId == '' || formId == null) return false;
	if (url == undefined) url = '';

	if(url != ''){
		$("#" + formId).attr('action', url);
	}
	$("#" + formId).submit();
}

/*
 * 検索ボタン押下処理
 * @param formId     該当フォームのid名（必須）
 * @param searchName 検索ボタン名（必須）
 * @param url        遷移先（文字列が入力されていれば、そちらへaction先変更）
 * @return
 */
function searchBtn(formId, searchName, url){
	if(formId == '' || formId == null) return false;
	if(searchName == '' || searchName == null) return false;
	if (url == undefined) url = '';

	var formObj = $("#" + formId);
	if(url != ''){
		formObj.attr('action', url);
	}

	formObj.append('<input type="hidden" name="' + searchName + '" value="1" />');

	formObj.submit();
}

/*
 * リセットボタン押下処理
 * @param formId     該当フォームのid名（必須）
 * @return
 */
function resetBtn(formId){
	if(formId == '' || formId == null) return false;
	$("#" + formId + " input:text").val('');
	$("#" + formId + " input:password").val('');
	//$("#" + formId + " input:radio").removeAttr("checked");
	$("#" + formId + " input:checkbox").removeAttr("checked");
	$("#" + formId + " textarea").val('');
	$("#" + formId + " select").each(function(){
		$(this).children().each(function(key, val){
			if(key == 0){
				$(this).attr("selected", "selected");
			}else{
				$(this).removeAttr("selected");
			}
		});
	});
	//ソートの昇降順リセット
	$("#" + formId + " input:radio[name='SORT_TYPE']").each(function(){
		if($(this).attr('value') == 'ASC'){
			$(this).attr("checked", "checked");
		}else{
			$(this).removeAttr("checked");
		}
	});
}

/*
 * 日付入力補助リンク押下処理（期間）
 * @param weekFlag   日単位か週単位か判定　0:日、1：週、2：月、3：年
 * @param dateType   日(週)の種類　1:当日(当週)、2：翌日(翌週)(翌年)、3：先日(先週)(去年)
 * @param targetList 入力フォームのid名の配列（必須）
 *                   {start_y:id名, start_m:id名, start_d:id名, end_y:id名, end_m:id名, end_d:id名 }
 */
function setDate(weekFlag,dateType,targetList){
	if(!targetList) return false;
	dataList = {};
	//日付を設定
	if(weekFlag == 1){
		var startDate = new Date();
		var week = startDate.getDay();
		startDate.setDate(startDate.getDate() - week);
		var endDate = new Date();
		endDate.setYear(startDate.getFullYear());
		endDate.setMonth(startDate.getMonth());
		endDate.setDate(startDate.getDate() + 6);
		//当週
		dataList.start_y = startDate.getFullYear();
		dataList.start_m = startDate.getMonth();
		dataList.start_d = startDate.getDate();
		dataList.end_y = endDate.getFullYear();
		dataList.end_m = endDate.getMonth();
		dataList.end_d = endDate.getDate();

		switch(dateType){
			case 2:  //翌週
				startDate.setDate(dataList.start_d + 7);
				endDate.setDate(dataList.end_d + 7);
				dataList.start_y = startDate.getFullYear();
				dataList.start_m = startDate.getMonth();
				dataList.start_d = startDate.getDate();
				dataList.end_y = endDate.getFullYear();
				dataList.end_m = endDate.getMonth();
				dataList.end_d = endDate.getDate();
				break;
			case 3:  //先週
				startDate.setDate(dataList.start_d - 7);
				endDate.setDate(dataList.end_d - 7);
				dataList.start_y = startDate.getFullYear();
				dataList.start_m = startDate.getMonth();
				dataList.start_d = startDate.getDate();
				dataList.end_y = endDate.getFullYear();
				dataList.end_m = endDate.getMonth();
				dataList.end_d = endDate.getDate();
				break;
		}
	}else if(weekFlag == 2){
		var date = new Date();
		var month = date.getMonth();
		//当月
		dataList.start_y = date.getFullYear();
		dataList.start_m = date.getMonth();
		dataList.start_d = "1";
		dataList.end_y   = date.getFullYear();
		dataList.end_m   = date.getMonth();
		dataList.end_d   = new Date(dataList.end_y, dataList.end_m+1, 0).getDate();

		switch(dateType){
			case 2:  //翌月
				date.setMonth(date.getMonth() + 1);
				dataList.start_y = date.getFullYear();
				dataList.start_m = date.getMonth();
				dataList.start_d = "1";
				dataList.end_y   = date.getFullYear();
				dataList.end_m   = date.getMonth();
				dataList.end_d   = new Date(dataList.end_y, dataList.end_m+1, 0).getDate();
				break;
			case 3:  //先月
				date.setMonth(date.getMonth() - 1);
				dataList.start_y = date.getFullYear();
				dataList.start_m = date.getMonth();
				dataList.start_d = "1";
				dataList.end_y   = date.getFullYear();
				dataList.end_m   = date.getMonth();
				dataList.end_d   = new Date(dataList.end_y, dataList.end_m+1, 0).getDate();
				break;
		}
	}else if(weekFlag == 3){

		var date = new Date();
		var month = date.getMonth();
		//当年
		dataList.start_y = date.getFullYear();
		dataList.start_m = "0";
		dataList.start_d = "1";
		dataList.end_y   = date.getFullYear();
		dataList.end_m   = "12";
		dataList.end_d   = new Date(dataList.end_y, dataList.end_m, 0).getDate();

		switch(dateType){
			case 2:  //翌年
				date.setYear(date.getYear() + 1);
				dataList.start_y = date.getFullYear();
				dataList.start_m = "0";
				dataList.start_d = "1";
				dataList.end_y   = date.getFullYear();
				dataList.end_m   = "12";
				dataList.end_d   = new Date(dataList.end_y, dataList.end_m, 0).getDate();
				break;
			case 3:  //去年
				date.setYear(date.getYear() - 1);
				dataList.start_y = date.getFullYear();
				dataList.start_m = "0";
				dataList.start_d = "1";
				dataList.end_y   = date.getFullYear();
				dataList.end_m   = "12";
				dataList.end_d   = new Date(dataList.end_y, dataList.end_m, 0).getDate();
				break;
		}
	}else{
		var date = new Date();
		//当日
		dataList.start_y = date.getFullYear();
		dataList.start_m = date.getMonth();
		dataList.start_d = date.getDate();
		dataList.end_y = date.getFullYear();
		dataList.end_m = date.getMonth();
		dataList.end_d = date.getDate();

		switch(dateType){
			case 2:  //翌日
				date.setDate(dataList.start_d + 1);
				dataList.start_y = date.getFullYear();
				dataList.start_m = date.getMonth();
				dataList.start_d = date.getDate();
				dataList.end_y = date.getFullYear();
				dataList.end_m = date.getMonth();
				dataList.end_d = date.getDate();
				break;
			case 3:  //先日
				date.setDate(dataList.start_d - 1);
				dataList.start_y = date.getFullYear();
				dataList.start_m = date.getMonth();
				dataList.start_d = date.getDate();
				dataList.end_y = date.getFullYear();
				dataList.end_m = date.getMonth();
				dataList.end_d = date.getDate();
				break;
		}
	}

	//日付をセット
	inputDate(targetList, dataList);

}

/*
 * 日付入力補助リンク押下処理
 * @param unitaryType 日単位か週単位か判定　0:日、1：週、2：月、3：年
 * @param dateType    日(週)の種類　1:当日(当週)、2：翌日(翌週)(翌年)、3：先日(先週)(去年)
 * @param targetList  入力フォームのid名の配列（必須）
 *                    {y:id名, m:id名, d:id名, h:id名, i:id名, s:id名 }
 */
function setDateTime(unitaryType, dateType, targetList){
	if(!targetList) return false;
	dataList = {};
	//日付を設定
	if(unitaryType == 1){
		//当週
		var dt = new Date();
		var week = dt.getDay();
		var day = dt.getDate();
//		dt.setDate(day - week);
		switch(dateType){
			case 2:  //翌週
				dt.setDate(day + 7);
				break;
			case 3:  //先週
				dt.setDate(day - 7);
				break;
		}
		dataList.y = dt.getFullYear();
		dataList.m = dt.getMonth();
		dataList.d = dt.getDate();
		dataList.h = '0';
		dataList.i = '0';
		dataList.s = '0';
	}else if(unitaryType == 2){
		//当月
		var date = new Date();
		switch(dateType){
			case 2:  //翌月
				date.setMonth(date.getMonth() + 1);
				break;
			case 3:  //先月
				date.setMonth(date.getMonth() - 1);
				break;
		}
		dataList.y = date.getFullYear();
		dataList.m = date.getMonth();
		dataList.d = date.getDate();
		dataList.h = '0';
		dataList.i = '0';
		dataList.s = '0';
	}else if(unitaryType == 3){
		//当年
		var date = new Date();
		switch(dateType){
			case 2:  //翌年
				date.setYear(date.getFullYear() + 1);
				break;
			case 3:  //去年
				date.setYear(date.getFullYear() - 1);
				break;
		}
		dataList.y = date.getFullYear();
		dataList.m = date.getMonth();
		dataList.d = date.getDate();
		dataList.h = '0';
		dataList.i = '0';
		dataList.s = '0';
	}else{
		//当日
		var date = new Date();
		switch(dateType){
			case 2:  //翌日
				date.setDate(dataList.d + 1);
				break;
			case 3:  //先日
				date.setDate(dataList.d - 1);
				break;
		}
		dataList.y = date.getFullYear();
		dataList.m = date.getMonth();
		dataList.d = date.getDate();
		//dataList.h = date.getHours();
		//dataList.i = date.getMinutes();
		//dataList.s = date.getSeconds();
		dataList.h = '0';
		dataList.i = '0';
		dataList.s = '0';
	}

	//日付をセット
	inputDate(targetList, dataList);

}

/**
 * 日付をセット
 * @param targetList 挿入先IDリスト
 * @param dataList   日付データ
 */
function inputDate(targetList, dataList) {
	$.each(targetList, function(key, val){
		if(val != ''){
			var data = '';
			if(dataList[key] || dataList[key] == 0){
				if(key == 'start_m' || key == 'end_m' || key == 'm'){
					data = dataList[key] + 1;
					if(data > 12) data = 12;
					if(data == '01') data = '1';
				}else{
					data = dataList[key];
				}
			}
			$(document).find("#" + targetList[key]).val(data);
		}
	});
}

/**
 * 年月を指定して月末日を求める
 * @param year  年
 * @param month 月
 * @return      月末の日数
 */
function getMonthEndDay(year, month) {
    //日付を0にすると前月の末日が取得できる
    var dt = new Date(year, month, 0);
    return dt.getDate();
}


/*
 * 登録ボタン押下
 * @param formId     該当フォームのid名（必須）
 * @param url        遷移先（文字列が入力されていれば、そちらへaction先変更）
 * @param dataName   登録情報の和名
 * @param checkPath  データチェックファイルのパス
 * @param selectIdList  取得したいselectタグのID名(optionタグのvalue値すべて取得)の連想配列
 * @return
 */
function submitEdit(formId, url, dataName, checkPath, selectIdList){
	if(formId == '' || formId == null) return false;
	if(dataName == '' || dataName == null) return false;
	if(checkPath == '' || checkPath == null) return false;
	if(selectIdList == '' || selectIdList == null || selectIdList == undefined || selectIdList == 'undefined' ){
		selectIdList = {};
	}

	dataList = getInputData(formId);

	$.each(selectIdList, function(key, val){
		dataList[key] = getSelectOptionData(val);
	});

	ajaxPost(formId, url, dataName, checkPath, dataList);
}

/*
 * 登録データ取得
 * @param  formId 該当フォームのid名（必須）
 * @return Array  form要素の連想配列
 */
function getInputData(formId){
	var dataList = {};

	$("#" + formId + " input, #" + formId + " select").each(function(key){
		var name = $(this).attr('name');

		if($(this).attr('type') == 'radio'){
			if($(this).attr('checked')){
				var value = $(this).val();
				if(name != ''){
					dataList[name] = value;
				}
			}
		}else if($(this).attr('type') != 'checkbox'){
			var value = $(this).val();
			if(name != ''){
				dataList[name] = value;
			}
		}
	});
	$("#" + formId + " textarea").each(function(key){
		var name = $(this).attr('name');
		//var value = $(this).html();
		var value = $(this).val();
		if(name != ''){
			dataList[name] = value.split('\n').join('\r\n');
		}
	});

	var num = 0;
	var strname = ',';
	$("#" + formId + " input:checkbox").each(function(key){
		var name = $(this).attr('name');
		name = name.replace("[]","");

		var match = strname.match(',' + name + ',');
		if(strname.match(',' + name + ',') == null){
			//num = 0;
			//dataList[name] = new Array();
			dataList[name] = ',';
		}

		var value = $(this).attr('value');
		if($(this).attr('checked')){
			if(name != ''){
				dataList[name] += value + ',';
			}
		}
		strname += name + ',';
	});
	/*
	var strList = '';
	$.each(dataList, function(key, val){
		strList += ',' + key + '=' + val;
	});
	if(strList != '') strList.substr(1);
	alert(strList);
	*/

	return dataList;

}

/*
 * selectタグのに表示されているvalue値すべて取得
 * @param  idName 該当id名（必須）
 * @return String 要素の配列
 */
function getSelectOptionData(idName){
	var strDataList = "";

	$("#" + idName + " option").each(function(key){
		var value = $(this).val();
		if(value != ''){
			strDataList += ',' + value;
		}
	});

	if(strDataList != ""){
		strDataList = strDataList.substr(1);
	}

	return strDataList;
}

/*
 * Ajax(POST)実行
 * @param formId     該当フォームのid名（必須）
 * @param url        遷移先（文字列が入力されていれば、そちらへaction先変更）
 * @param dataName   登録情報の和名
 * @param checkPath  データチェックファイルのパス
 * @param dataList   POSTするデータの配列
 */
function ajaxPost(formId, url, dataName, checkPath, dataList){
	if(formId == '' || formId == null) return false;
	if(dataName == '' || dataName == null) return false;
	if(checkPath == '' || checkPath == null) return false;

	$(".errorMsg").empty();

	$.ajax({
		type: 'POST',
		url: checkPath + '?cache=' + (new Date()).getTime(),
		data:dataList,
		dataType: 'json',
		success: function(data){
			//エラーメッセージ取得
			var errMsg = '';
			var error_list = {};
			if(data.error){
				if(data.error.msg){
					error_list = data.error.msg;
				}
			}else if(data.msg){
				error_list = data.msg;
			}
			$.each(error_list, function(key, val){
				errMsg += val + '\n';
				$(document).find("#ERROR_" + key).text(val);
			});

			//警告メッセージ取得
			var warningMsg = '';
			if(data.warning){
				$.each(data.warning, function(key, val){
					warningMsg += val + '\n';
				});
			}

			if(errMsg != ''){
				//alert(errMsg);
			}else if(warningMsg != ''){
				if(confirm(warningMsg + '\n' + '登録してもよろしいですか？')){
					if(url == '' || url == null){
						url = $("#" + formId).attr('action');
					}
					$("#" + formId).attr('action', url + '?MODE=add&overlap=1');
					$("#" + formId).submit();
				}
			}else{
				if(confirm(dataName + 'を以上の内容で登録しますか？')){
					if(url != ''){
						$("#" + formId).attr('action', url);
					}
					$("#" + formId).submit();

				}else{
					return false;
				}
			}
		},
		error: function(data){
			alert('通信に失敗しました');
			return false;
		}
	});

}

/*
 * 警告用ダイアログ
 * @param formId      該当フォームのid名（必須）
 * @param url         遷移先（文字列が入力されていれば、そちらへaction先変更）
 * @param warningMsg  警告メッセージ
 */
function checkOverlap(formId, url, warningMsg){
	if(confirm(warningMsg + '\n' + '登録してもよろしいですか？')){
		if(url == '' || url == null){
			url = $("#" + formId).attr('action');
		}
		$("#" + formId).attr('action', url + '?MODE=add&overlap=1');
		$("#" + formId).submit();
	}
}

/*
 * 削除ボタン押下
 * @param url     遷移先（必須）
 * @param message 確認ダイアログに出すメッセージ（必須）
 * @return
 */
function deleteBtn(url, message){
	if(url == '' || url == null) return false;
	if(message == '' || message == null) return false;
	if(confirm(message)){
		location.href = url;
	}else{
		return false;
	}
}

/*
 * カテゴリ削除ボタン押下
 * @param url     遷移先（必須）
 * @param message 確認ダイアログに出すメッセージ（必須）
 * @param checkPath   紐づけチェック遷移先（必須）
 * @return
 */
function deleteCategoryBtn(url, message, checkPath, value){
	if(url == '' || url == null) return false;
	if(message == '' || message == null) return false;
	if(checkPath == '' || checkPath == null) return false;
	if(value == '' || value == null) return false;

	var dataList = {};
	dataList["CATEGORY_ID"] = value;

	$.ajax({
		type: 'POST',
		url: checkPath + '?cache=' + (new Date()).getTime(),
		data:dataList,
		dataType: 'json',
		success: function(data){
			//紐づけ結果取得
			var flag = '';
			if(data.flag) flag = data.flag;
			if(flag == "0"){
				if(confirm(message)){
					location.href = url;
				}else{
					return false;
				}
			}else{
				alert('すでに使用されているカテゴリです');
			}
		},
		error: function(data){
			alert('通信に失敗しました');
			return false;
		}
	});
}

/*
 * 番組削除ボタン押下
 * @param url     遷移先（必須）
 * @param message 確認ダイアログに出すメッセージ（必須）
 * @param checkPath   紐づけチェック遷移先（必須）
 * @return
 */
function deleteProgramBtn(url, message, checkPath, value){
	if(url == '' || url == null) return false;
	if(message == '' || message == null) return false;
	if(checkPath == '' || checkPath == null) return false;
	if(value == '' || value == null) return false;

	var dataList = {};
	dataList["PROGRAM_ID"] = value;

	$.ajax({
		type: 'POST',
		url: checkPath + '?cache=' + (new Date()).getTime(),
		data:dataList,
		dataType: 'json',
		success: function(data){
			//紐づけ結果取得
			var flag = '';
			if(data.flag) flag = data.flag;
			if(flag == "0"){
				if(confirm(message)){
					location.href = url;
				}else{
					return false;
				}
			}else{
				alert('すでに使用されている番組です');
			}
		},
		error: function(data){
			alert('通信に失敗しました');
			return false;
		}
	});
}

/*
 * エピソード削除ボタン押下
 * @param url     遷移先（必須）
 * @param message 確認ダイアログに出すメッセージ（必須）
 * @param checkPath   紐づけチェック遷移先（必須）
 * @return
 */
function deleteEpisodeBtn(url, message, checkPath, value){
	if(url == '' || url == null) return false;
	if(message == '' || message == null) return false;
	if(checkPath == '' || checkPath == null) return false;
	if(value == '' || value == null) return false;

	var dataList = {};
	dataList["EPISODE_ID"] = value;

	$.ajax({
		type: 'POST',
		url: checkPath + '?cache=' + (new Date()).getTime(),
		data:dataList,
		dataType: 'json',
		success: function(data){
			//紐づけ結果取得
			var flag = '';
			if(data.flag) flag = data.flag;
			if(flag == "0"){
				if(confirm(message)){
					location.href = url;
				}else{
					return false;
				}
			}else{
				alert('すでに使用されているエピソードです');
			}
		},
		error: function(data){
			alert('通信に失敗しました');
			return false;
		}
	});
}

/*
 * ビデオ削除ボタン押下
 * @param url     遷移先（必須）
 * @param message 確認ダイアログに出すメッセージ（必須）
 * @param checkPath   紐づけチェック遷移先（必須）
 * @return
 */
function deleteVideoBtn(url, message, checkPath, value){
	if(url == '' || url == null) return false;
	if(message == '' || message == null) return false;
	if(checkPath == '' || checkPath == null) return false;
	if(value == '' || value == null) return false;

	var dataList = {};
	dataList["VIDEO_ID"] = value;

	$.ajax({
		type: 'POST',
		url: checkPath + '?cache=' + (new Date()).getTime(),
		data:dataList,
		dataType: 'json',
		success: function(data){
			//紐づけ結果取得
			var flag = '';
			if(data.flag) flag = data.flag;
			if(flag == "0"){
				if(confirm(message)){
					location.href = url;
				}else{
					return false;
				}
			}else{
				alert('すでに使用されているビデオです');
			}
		},
		error: function(data){
			alert('通信に失敗しました');
			return false;
		}
	});
}

/*
 * 画像一覧表示
 * @param imageList 画像URL一覧（必須）
 * @param obj       押下対象（必須）
 * @param id        各画面ID（必須）
 */
function viewImageList(imageList, obj, id){
	hideImageList();
	if(!imageList[id]){
		$("#thumbnailList").append(document.createTextNode('画像が登録されていません'));
		var position = $(obj).position();
		$("#thumbnailList").css('top', parseInt(position.top) - 38);
		$("#thumbnailList").css('left', parseInt(position.left) + 30);
		$("#thumbnailList").css('width', '150px');
		$("#thumbnailList").show();
		//閉じるリンク
		var closeTagDiv = document.createElement('div');
		closeTagDiv.className = 'colse';
		var closeTagA = document.createElement('a');
		closeTagA.appendChild(document.createTextNode('閉じる'));
		closeTagA.href = 'javascript:void(0)';
		closeTagA.onclick = function(){ hideImageList() };
		closeTagDiv.appendChild(closeTagA);
		$("#thumbnailList").append(closeTagDiv);
		return false;
	}

	//PC画像一覧
	var blockPc = document.createElement('div');
	blockPc.className = 'imageBlock';
	var pcCnt = 0;
	var pHeight = 0;
	$.each(imageList[id][0], function(idNo, data){
		var divTag = document.createElement('div');
		if(!isNaN(idNo)){
			divTag.appendChild(document.createTextNode('PCサムネイル' + idNo));
		}else{
			divTag.appendChild(document.createTextNode(idNo));
		}
		var brTag = document.createElement('br');
		divTag.appendChild(brTag);
		var imageTag = document.createElement('img');
		imageTag.src = data.src;
		imageTag.style.width = data.width + 'px';
		imageTag.style.height = data.height + 'px';
		divTag.appendChild(imageTag);
		blockPc.appendChild(divTag);
		pcCnt++;
		pHeight += parseInt(data.height) + 24;
	});
	if(pcCnt > 0){
		$("#thumbnailList").append(blockPc);
	}
	//Mobile画像一覧
	var blockMobile = document.createElement('div');
	blockMobile.className = 'imageBlock';
	var mCnt = 0;
	var mHeight = 0;
	$.each(imageList[id][1], function(idNo, data){
		var divTag = document.createElement('div');
		if(!isNaN(idNo)){
			divTag.appendChild(document.createTextNode('携帯サムネイル' + idNo));
		}else{
			divTag.appendChild(document.createTextNode(idNo));
		}
		var brTag = document.createElement('br');
		divTag.appendChild(brTag);
		var imageTag = document.createElement('img');
		imageTag.src = data.src;
		imageTag.style.width = data.width + 'px';
		imageTag.style.height = data.height + 'px';
		divTag.appendChild(imageTag);
		blockMobile.appendChild(divTag);
		mCnt++;
		mHeight += parseInt(data.height) + 24;
	});
	if(mCnt > 0){
		$("#thumbnailList").append(blockMobile);
	}
	//閉じるリンク
	var closeTagDiv = document.createElement('div');
	closeTagDiv.className = 'colse';
	var closeTagA = document.createElement('a');
	closeTagA.appendChild(document.createTextNode('閉じる'));
	closeTagA.href = 'javascript:void(0)';
	closeTagA.onclick = function(){ hideImageList() };
	closeTagDiv.appendChild(closeTagA);
	$("#thumbnailList").append(closeTagDiv);

	//表示
	var position = $(obj).position();
	//$("#thumbnailList").css('top', parseInt(position.top) + 10);
	var height = pHeight;
	if(mHeight > height) height = mHeight;
	$("#thumbnailList").css('top', parseInt(position.top) - height - 10);
	$("#thumbnailList").css('left', parseInt(position.left) + 30);
	if(pcCnt > 0 && mCnt > 0){
		$("#thumbnailList").css('width', '220px');
	}else{
		$("#thumbnailList").css('width', '107px');
	}
	$("#thumbnailList").show();
	return false;
}

/*
 * 画像一覧を非表示にする
 */
function hideImageList(){
	$("#thumbnailList").hide();
	$("#thumbnailList").empty();
	return false;
}


/*
 * 全角→半角変換
 *（対象：英数字、カナ、2バイトカナ）
 */
function relapceMobileKana(text){

  //英数字
  var zen="１２３４５６７８９０ＡＢＣＤＥＦＧＨＩＪＫＬＭＮＯＰＱＲＳＴＵＶＷＸＹＺａｂｃｄｅｆｇｈｉｊｋｌｍｎｏｐｑｒｓｔｕｖｗｘｙｚー・";
  var han="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-･";

  //半角カナ
  var zen1="アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンャュョァィゥェォッ";
  var han1="ｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜｦﾝｬｭｮｧｨｩｪｫｯ";

  //2バイトカナ
  var han2="ｶﾞｷﾞｸﾞｹﾞｺﾞｻﾞｼﾞｽﾞｾﾞｿﾞﾀﾞﾁﾞﾂﾞﾃﾞﾄﾞﾊﾞﾋﾞﾌﾞﾍﾞﾎﾞﾊﾟﾋﾟﾌﾟﾍﾟﾎﾟ";
  var zen2="ガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポ";

  var str = "";
  for(var i=0; i<text.length ;i++){
	var c = text.charAt(i);
	var n = zen.indexOf(c,0);
	if(n>=0)c=han.charAt(n);
	str += c;
  }

  var str1 = "";
  for(var i=0; i<str.length; i++){
	var c = str.charAt(i);
	var n = zen1.indexOf(c,0);
	if(n>=0)c=han1.charAt(n);
	str1 += c;
  }

  var str2 = "";
  for(var i=0; i<str1.length; i++){
	var c = str1.charAt(i);
	var n = zen2.indexOf(c,0);
	var n2 = n * 2;
	if(n>=0)c=han2.charAt(n2)+han2.charAt(n2+1);
	str2 += c;
  }

  return str2;
}

