﻿//------------------------------------------------------------
//jQueryを実行
//------------------------------------------------------------
$(function() {
		   

	//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

//  alert("スタート");

//	FlashHtml=$("#Flash_mainVisual").html();
//	$("#Flash_mainVisual").find("p")



	//------------------------------------------------------------
	//最初に実行
	//------------------------------------------------------------
	//JUGEMのCookieの設定っぽい
	//<body onload="javascript:initval();">
	//【【【JUGEMアップ時に有効にする、テスト時は無効にする】】】
	initval();
	
	
	//隠すのに使ってる
	//$("#wrapper").addClass("JS_run");

	
	
	//------------------------------	
	//JSで代入
	//------------------------------
	//最近のエントリーを代入
	tempHtml = $("#latest_entry").html();
	$("#JS_latest_entry").html(tempHtml);
	
	
	

	//------------------------------	
	//カテゴリを他の部分に代入
	//------------------------------	
	//独自タグで代入したカテゴリをulで保存
   	jugem_category=$("#category>ul").html();
	
	//関係カテゴリに代入
    $(".JS_caterory>ul").each(function(){
		$(this).html(jugem_category);
	});
	
	
	
	//------------------------------------------------------------
	//「このエントリーに関するリンク」を右カラムに代入
	//------------------------------------------------------------
	//eidの時だけ代入、それ以外は削除	
	/*
	if( $("body#eid")[0] ){
		tempHtml = $("body#eid #contents_clm div.entry_bottom").eq(0).html();
		$("#JS_entry_bottom").html(tempHtml);
	} else {
		$("#JS_entry_bottom").remove();
	}
	*/
		tempHtml = $("#contents_clm div.entry_bottom").eq(0).html();
		$("#JS_entry_bottom").html(tempHtml);



	//------------------------------------------------------------
	//「このエントリーに関するリンク」で関係のあるカテゴリだけを表示
	//------------------------------------------------------------
	//クリックしたら実装開始
	$("#contents .category_toggle").click(function () {
		//この記事のカテゴリを取得
		entryCategory=$(this).parent().find(".JS_category_name").find("a").text()

		//カッコの前を取得
		entryCategory_rep=entryCategory.replace(/\(.+/,"")
		//カッコの中を取得						   
		entryCategory_repNow=entryCategory.replace(/.*\((.*)\).*/,"$1")

		$(this).next(".JS_caterory").find("li").each(function(){
		tempHtml=$(this).html()
			//関係ないのは非表示
			if( tempHtml.match(entryCategory_rep)<1 ){
				$(this).css({
					"display":"none"
				})
				$(this).remove()

			}
			//この記事のカテゴリ
			if( (tempHtml.match(entryCategory_repNow)) && (tempHtml.match(/↑この記事のカテゴリ/)<1)){
				$(this).html(tempHtml+"<br />↑この記事のカテゴリ")
				temp_flg=true
				$(this).addClass("currentCategory")
			}
		})

		//クリックで開閉
		//$(this).siblings(".JS_caterory").toggle();
		//$(this).next(".JS_caterory").toggle();
		$(this).next(".JS_caterory").toggle();
		return false;
	});
	
	
	
		
	//------------------------------------------------------------
	//関係のあるカテゴリのJS_sectionを開く
	//------------------------------------------------------------
    $("#contents_clm .JS_category_name").each(function(){
		tempHtml=$(this).html();
		tempObj=$(this).parent().parent().parent().prev(".entry_top").find(".JS_section_outer");
		
		//関係するカテゴリ関係だけ表示
		if( tempHtml.match(/雑音調短文詩 noise/) ){
			tempObj.find(".JS_section_noise").css({
					"display":"block"													
			})
			tempObj.find(".JS_section_kashi").css({
					"display":"block"													
			})
		} else if( tempHtml.match(/VOCALOID/) ){
			tempObj.find(".JS_section_clb").css({
					"display":"block"													
			})
			tempObj.find(".JS_section_kashi").css({
					"display":"block"													
			})
		}
		
	});



	//------------------------------------------------------------
	//カテゴリ
	//------------------------------------------------------------
	txt_BF=""
	txt_now=""
	set_txt_now=""
	set_txt_array=new Array
	set_txt_array_cnt=-1
	

	set_obj=$("#category")
	//------------------------------
	//同じカテゴリを調べて表示
	//------------------------------
    set_obj.find("ul>li").each(function(cnt){
		///現在の値を取得
		txt_now = $(this).text()
		
		//カッコの前を取得
		txt_now=txt_now.replace(/\(.*/,"")
		
		//連続したカテゴリがあったら、大カテゴリとして配列に代入
		if( (txt_BF == txt_now) && (set_txt_now != txt_now) ){
			set_txt_array_cnt++
			set_txt_now = txt_now
			set_txt_array[set_txt_array_cnt]=txt_now

		}
		
		//次回、「前回の値」として使う
		txt_BF = txt_now
	});
	
	
	
	
	
	//------------------------------
	//ulだけを削除、/ulは再追加、あとで再利用
	//------------------------------
	set_obj.find("ul").each(function (){
		tempHtml=$(this).html();
		$(this).remove()
		//閉じタグ前に追加
		tempHtml=set_obj.append(tempHtml+"【【【/ul】】】");
		
	})
	
	
	
	//------------------------------
	//同属の数だけでまとめる
	//------------------------------
	forVar=set_txt_array.length
	for (sameCateCnt=0; sameCateCnt<forVar; sameCateCnt++){
		set_h2a=set_txt_array[sameCateCnt]
		set_obj.find("li:contains("+set_h2a+")").each(function(){
			$(this).addClass("setNo_"+sameCateCnt)
		});



		//同カテゴリ（同じclassを設定）の最初だけ
		set_obj_class=set_obj.find(".setNo_"+sameCateCnt+":first")
		
		//最上段はつけない
		if( sameCateCnt > 0 ){
			set_obj_class.before("【【【/ul】】】")
		}
		//
		set_obj_class.before("<h3><a href='#' class='AJS_category_a'>▼　"+set_h2a+"</a></h3>")
						.before("【【【ul class='AJS_category_ul JS_display_none'】】】")
		
	}


	
	//------------------------------
	//タグ化する
	//------------------------------
	tempHtml=set_obj.html()
	tempHtml=tempHtml.replace(/【【【(.+?)】】】/g,"<$1>")
	set_obj.html(tempHtml)
	tempHtml=""
	
	
	//------------------------------
	//クリックで開閉
	//------------------------------
	set_obj.find(".AJS_category_a").click(function () {
		//$(this).siblings("ul").toggle();
		$(this).parent().next("ul:first").toggle();
		return false;
	});
	
	
	//------------------------------
	

	
	//------------------------------------------------------------
	//コメント部　管理者用
	//------------------------------------------------------------
	tempTxt="空怜@master"
	tempObj=$("#comments").find("h3:contains("+tempTxt+")")
	
	//メール代入
	tempTxt="tuki@sorist.net"
	tempObj.find("a.JS_comment_email")
	.html(tempTxt)
	.attr("href","mailto:"+tempTxt)
	
	//URL代入
	tempTxt="http://tukilog.jugem.jp/"
	tempObj.find("a.JS_comment_url")
	.html(tempTxt)
	.attr("href",tempTxt)
	
	//CSS装飾
	tempObj.css({
		"background-color":"#EEF6FE"					  
	})
	.parent().css({
		"color":"#258DF5"
	})
	//キャンセル
	tempObj=""
	tempTxt=""

	
	
	//------------------------------------------------------------
	//コメント部　引用符行のハイライト
	//------------------------------------------------------------
	/*
	//IEで動かない(>_<) 
	set_obj=$("#comments .comment_description")
	set_obj.each(function (){
		tempHtml=$(this).html();
		tempHtml=tempHtml.replace(/(>.*\n)/g,"<span style='color:#A28500'>$1</span>")
		$(this).html(tempHtml);
	})
	//キャンセル
	tempObj=""
	tempHtml=""

	*/
	
	
	//------------------------------------------------------------
	//ページの前後リンクの「<<」「>>」に、テキストを含める
	//------------------------------------------------------------
	if( $("#page_NP")[0] ){
		tempObj=$("#page_NP")
		tempHtml=tempObj.html()

		//10件無い場合
		tempHtml=tempHtml.replace(/前ページ \[ 現1ページ \/ 全1ページ \] 次ページ/,"[ このページ内で全て（10件以内）です ]")
		
		//カッコの前を取得　大文字小文字を区別しない「i」これにしないとIEで動かない
		tempHtml=tempHtml.replace(/<\/a> 前ページ/i," 前ページ</a>")
		tempHtml=tempHtml.replace(/ 次ページ (<a href=.*?>)/i," $1次ページ ")
		
		//反映
		tempObj.html(tempHtml)
		tempObj=""
		tempHtml=""
		
		//同じものをフッタに代入
		tempHtml = $("#page_NP").html();
		$("#JS_page_NP").html(tempHtml);

	} else {
		//存在してなければ、代入先削除
		$("#JS_page_NP").remove();
	}
		
		
		
	//------------------------------------------------------------
	//最後に実行
	//------------------------------------------------------------
	//JSで非表示にする
	/*
	$(".JS_display_none").css({
		"display":"none"
	});
	*/
	
	
	//カテゴリ　VOCALOIDだけは開いておく
	$("#category .JS_display_none").eq(0).removeClass("JS_display_none");
	
	
	//アーカイブ　開閉
	tempObj=$("#archives")
	tempObj.find("h3>a").click(function (){
			$(this).parent().parent().find("ul").toggle()
			return false;
		})
	//アーカイブ　最初から閉じておく
	tempObj.find("ul").addClass("JS_display_none");
	tempObj=""
	
	
	
	//------------------------------------------------------------
	//droppy　万能版
	//------------------------------------------------------------
	//ここは「jquery.droppy.js」の中に直書きとかでもOK。
	//でも、class名設定を忘れないように。
	
	//万能版　親横サイズに合わせて、下階層を自動サイズ設定
	tempObj=$("#gnavi_1.naviPullDownTukilog");
	tempObj.find(">li img").each(function (){
										   
		//tempWidth=$(this).width();
		//統一
		tempWidth=300;
		//【調整】右余白追加分
		//tempWidth+=30;
		$(this).parent().next("ul").css({
			"width":+tempWidth+"px"
			/*,"background-color":"#FFAAAA"*/
		}).find("ul").css({
			"width":+tempWidth+"px",
			"left":+tempWidth+"px"
			/*,"background-color":"#FF00AA"*/
		})
		

		
		
	})
	
	//droppy設定
	//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
	tempObj.droppy()
	
	
	//------------------------------------------------------------
	//------------------------------------------------------------
	//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
	//英日付置換
	//------------------------------------------------------------
	/*
    $("#archives ul li").each(function(cnt){
		tempHtml = $(this).html()
		tempHtml=tempHtml.replace(/December/,"12・E)
		tempHtml=tempHtml.replace(/November/,"11・E)
		tempHtml=tempHtml.replace(/October/,"10・E)
		tempHtml=tempHtml.replace(/September/,"9・E)
		tempHtml=tempHtml.replace(/August/,"8・E)
		tempHtml=tempHtml.replace(/July/,"7・E)
		tempHtml=tempHtml.replace(/June/,"6・E)
		tempHtml=tempHtml.replace(/May/,"5・E)
		tempHtml=tempHtml.replace(/April/,"4・E)
		tempHtml=tempHtml.replace(/March/,"3・E)
		tempHtml=tempHtml.replace(/February/,"2・E)
		tempHtml=tempHtml.replace(/January/,"1・E)
		tempHtml=tempHtml.replace(/(.*20..)(.*)/,"$1年$2")
		$(this).html(tempHtml)
	})
	*/
	//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//  alert("エンド");
	// $("#JS_run").html("完了");


//	$("#Flash_mainVisual").html(FlashHtml);



/*
	$('#Flash_mainVisual').flash({
		 src: 'http://sorist.net/tuki/blog090417/tuki_load/images/mainFlash.swf',
		 width: 960,
		 height: 365
	});
*/



	
		
		
		
		
});
	




