//<![CDATA[
if (typeof jQuery == 'undefined') {
	alert("jQueryライブラリを読み込んで下さい");
}else{
	if (typeof Prototype != 'undefined') jQuery.noConflict();

	jQuery(document).ready(function(){
		if (jQuery("div#Comment").html() != undefined && jQuery("div#changeBox").html() != undefined) {
			dispCommentList(jQuery("input#i").val(), jQuery("input#g1").val(), jQuery("input#g2").val(), jQuery("input#t").val());
		}
		if (jQuery("div#Comment_i").html() != undefined && jQuery("dd#Comment03").html() != undefined) {
			dispCommentList_i(jQuery("input#i").val(), jQuery("input#g1").val(), jQuery("input#t").val());
		}
	});

	jQuery.postJSON = function(url, data, callback) {jQuery.post(url, data, callback, "json");};

	var entryComment = function(id) {
		var rating = '';
		var nickname = '';
		var comment = '';
		var err_msg = false;

		if (jQuery("input:radio[@name='rating']:checked").val() == undefined) {
			rating = '';
		} else {
			rating = jQuery("input:radio[@name='rating']:checked").val();
		}

		if (jQuery.trim(jQuery("input#nickname").val()) == '') {
			nickname = '';
		} else {
			nickname = jQuery("input#nickname").val();
		}
		if (jQuery.trim(jQuery("textarea#comment").val()) == '') {
			comment = '';
		} else {
			comment = jQuery("textarea#comment").val();
		}

		jQuery.postJSON('./bloc/entry_comment.php',{i:id,r:rating,n:nickname,c:comment}, function(jsonData) {
			if (jsonData.error == '') {
				jQuery("div#changeBox").html(jsonData.addhtml);
				dispCommentList(id, jQuery("input#g1").val(), jQuery("input#g2").val(), jQuery("input#t").val());
					jQuery("span#e_rating").html('');
					jQuery("span#e_nickname").html('');
					jQuery("span#e_comment").html('');
			} else {
				if (jsonData.rating != '') {
					jQuery("span#e_rating").html('※'+jsonData.rating);
                                }else{
					jQuery("span#e_rating").html('');
				}
				if (jsonData.nickname != '') {
					jQuery("span#e_nickname").html('※'+jsonData.nickname);
                                }else{
					jQuery("span#e_nickname").html('');
				}
				if (jsonData.comment != '') {
					jQuery("span#e_comment").html('※'+jsonData.comment);
                                }else{
					jQuery("span#e_comment").html('');
				}
			}
		});
	}

	var entryComment_i = function(id) {
		var nickname = '';
		var comment = '';
		var err_msg = false;

		if (jQuery("input#nickname").val() == '') {
			nickname = '';
		} else {
			nickname = jQuery("input#nickname").val();
		}
		if (jQuery("textarea#comment").val() == '') {
			comment = '';
		} else {
			comment = jQuery("textarea#comment").val();
		}

		jQuery.postJSON('./bloc/entry_comment.php',{i:id,r:1,n:nickname,c:comment}, function(jsonData) {
			if (jsonData.error == '') {
				jQuery("dd#Comment03").html('<img src="img_m/btn_comment_over.jpg" alt="投稿する" width="78" height="28" />');
				dispCommentList_i(id, jQuery("input#g1").val(), jQuery("input#t").val());
			} else {
				if (jsonData.nickname != '') {
					jQuery("span#e_nickname").html('※'+jsonData.nickname);
				}
				if (jsonData.comment != '') {
					jQuery("span#e_comment").html('※'+jsonData.comment);
				}
			}
		});
	}

	var dispCommentList = function(id, genre, game_genre, type) {
		jQuery.postJSON('./bloc/comment_list.php',{i:id,g1:genre,g2:game_genre,t:type}, function(jsonData) {
			if (jsonData.error == '') {
				jQuery("div#Comment").html(jsonData.addhtml);
			} else {
				alert(jsonData.error);
			}
		});
	}

	var dispCommentList_i = function(id, genre, type) {
		jQuery.postJSON('./bloc/comment_list_i.php',{i:id,g1:genre,t:type}, function(jsonData) {
			if (jsonData.error == '') {
				jQuery("div#Comment_i").html(jsonData.addhtml);
			} else {
				alert(jsonData.error);
			}
		});
	}

	// モードとキーを指定してSUBMITを行う。
	var fnModeSubmit = function(mode, keyname, keyid, action) {
		switch(mode) {
		default:
			break;
		}
		document.form1['fm'].value = mode;
		if(keyname != "" && keyid != "") {
			document.form1[keyname].value = keyid;
		}
		if (typeof action != 'undefined') {
			if (action != "") {
				document.form1.action = action;
			}
		}
		document.form1.submit();
	}

	var addFavorite = function(id, action) {
		jQuery.postJSON('./bloc/add_favorite.php',{i:id}, function(jsonData) {
			if (jsonData.error == '') {
				if (typeof action != 'undefined') {
					if (action != "") {
						document.form1.action = action;
					}
				}
				document.form1.submit();
			} else {
				alert(jsonData.error);
			}
		});
	}

	var delFavorite = function(id, action) {
		jQuery.postJSON('./bloc/del_favorite.php',{i:id}, function(jsonData) {
			if (jsonData.error == '') {
				if (typeof action != 'undefined') {
					if (action != "") {
						document.form1.action = action;
					}
				}
				document.form1.submit();
			} else {
				alert(jsonData.error);
			}
		});
	}

	var prevImage = function() {
		for (i = 0; i < jQuery('img[class="small_image"]').length; i++) {
			if (jQuery('img[id="big_image"]')[0].src == jQuery('img[class="small_image"]')[i].src) {
				if (i == 0) {
					jQuery('img[id="big_image"]')[0].src = jQuery('img[class="small_image"]')[4].src;
				} else {
					jQuery('img[id="big_image"]')[0].src = jQuery('img[class="small_image"]')[i-1].src;
				}
				break;
			}
		}
	}

	var nextImage = function() {
		for (i = 0; i < jQuery('img[class="small_image"]').length; i++) {
			if (jQuery('img[id="big_image"]')[0].src == jQuery('img[class="small_image"]')[i].src) {
				if (i == jQuery('img[class="small_image"]').length - 1) {
					jQuery('img[id="big_image"]')[0].src = jQuery('img[class="small_image"]')[0].src;
				} else {
					jQuery('img[id="big_image"]')[0].src = jQuery('img[class="small_image"]')[i+1].src;
				}
				break;
			}
		}
	}

	var addGood = function(id, action) {
		jQuery.postJSON('./bloc/add_good.php',{i:id}, function(jsonData) {
			if (jsonData.error == '') {
				if (typeof action != 'undefined') {
					if (action != "") {
						document.form1.action = action;
					}
				}
				document.form1.submit();
			} else {
				alert(jsonData.error);
			}
		});
	}

	var addBad = function(id, action) {
		jQuery.postJSON('./bloc/add_bad.php',{i:id}, function(jsonData) {
			if (jsonData.error == '') {
				if (typeof action != 'undefined') {
					if (action != "") {
						document.form1.action = action;
					}
				}
				document.form1.submit();
			} else {
				alert(jsonData.error);
			}
		});
	}
}
//]]>

