//Silverlight再生用ウィンドウ表示
function openSl(url){
	var data1 = url.split("?");
	var data2 = data1[1].split("&");
	var param = data2[0] + "&" + data2[1] + "&" + data2[2];
	wop("../silverlight/index.php?" + param, 'playmovie','800','600');
}

//配信方法選択モーダルダイアログ表示
function showSelectMethod(){
	$.blockUI({ message: $('#SelectMethod'),css: {left: '35%', width: '320px' } }); 
}

//指定の場所をブロックし、お待ちくださいメッセージを表示
function waiting_for(tgt){
	$(tgt).block({ 
		message: '<span style="font-size:14pt">しばらくお待ちください。</span>', 
		css: {backgroundColor:'#fff', width: '50%', border: '2px solid #a00' } ,
		overlayCSS:  {backgroundColor: '#000', opacity: 0.2}
	}); 
}


//カレンダー次月、来月表示
function calendar_move(month) {
waiting_for('#container');//ブロック
	$.get("./calendar.php", { calendarmove: 1, dt_calendarpoint: month ,pars: Math.random()},
	  function(data){
	    //alert("Data Loaded: " + data);
	    $("#calendar").html(data);
	    $("#calendar td").tooltip({
			track: true, 
			delay: 0, 
			showURL: false, 
			showBody: "<>", 
			extraClass:'fancy',
			fade:true});
	    caltd_click();
$('#container').unblock();//ブロック解除
	  });
}

//カレンダー日付のTDクリック時
function caltd_click(){
	$(".clickable").mouseover(function(){
		$(this).addClass("hover");
	}).mouseout(function(){
		$(this).removeClass("hover");
	}).click(function(){
		ahref = $("a",this).attr("href").split("\"");
		date_search(ahref[1]);
		return false;
	});
	$("td.clickable > a").click(function(){
		ahref = $(this).attr("href").split("\"");
		date_search(ahref[1]);
		return false;
	});
}

//今日の審議中継クリック時
function today_click(){
	$("#btnToday").click(function() {
		ahref = $(this).attr("href").split("\"");
		date_search(ahref[1]);
		return false;
	}); 
}


//ページ移動
function page_move(param) {
waiting_for('#container');//ブロック
	$.post("./result_selecter.php", param,
	  function(data){
	  	$("#result_area").html(data);
		play_click();
		detail_click();
$('#container').unblock();//ブロック解除
		meetingname_height("index.php => page_move");
	  });
}
//発言検索ページ移動
function opinion_page_move(param) {
waiting_for('#container');//ブロック
	$.post("./opinion_result.php", param,
	  function(data){
	  	$("#opinion_result_area").html(data);
		play_click();
$('#container').unblock();//ブロック解除
		$(".heightLine").equalHeights();//ブロック要素の高さをそろえる
	  });
}


//会議名から選択
function kaigi_search(kaigi) {
waiting_for('#container');//ブロック
	show_top();
	$.get("./result_selecter.php", { abskaigi: kaigi, searching: 1, absdate: "no", sel_pageline: 10 ,pars: Math.random()},
	  function(data){
	  	$("#result_area").html(data);
		play_click();
		detail_click();
$('#container').unblock();//ブロック解除
		meetingname_height("index.php => kaigi_search");
	  });
}
//カレンダー日付から選択
function date_search(date) {
waiting_for('#container');//ブロック
	show_top();
	$.get("./result_selecter.php", { abskaigi: "no", searching: 1, absdate: date, sel_pageline: 10 ,pars: Math.random()},
	  function(data){
	  	$("#result_area").html(data);
		play_click();
		detail_click();
$('#container').unblock();//ブロック解除
		meetingname_height("index.php => date_search");
	  });
}


//会議リスト高さ動的変更
function meetingname_height(point){
	var h = 0;
	var sh = 0;
	if($('#result_area').is(':visible')){
		h = $('#result_area').height();
		sh = $('#result_area').attr('scrollHeight');
	}else if($('#faq_area').is(':visible')){
		h = $('#faq_area').height();
		sh = $('#faq_area').attr('scrollHeight');
	}else if($('#howto_area').is(':visible')){
		h = $('#howto_area').height();
		sh = $('#howto_area').attr('scrollHeight');
	}
	var mh = $('#meetingname').height();
	var msh = $('#meetingname').attr('scrollHeight');
	var dif = sh - 190;
	if((dif)>0){
		$("#meetingname").height(345 + dif);
	}else{
		$("#meetingname").height(345);
	}
}


//ヘッダー画像クリックでトップ画面へ
function header_click(){
    $("#header_title").css("cursor","pointer").click(
    	function(e) {
	    location.href="./index.php";
	}
    );	
}

//参照用アイコンすべてoffに
function detailIcon_off(singicd){
	//会議の経過アイコン画像onであれば画像offに
        var imgsrc_on = $("#K-" + singicd).attr("src");   
        var dot = imgsrc_on.lastIndexOf('.'); 
	var undon = imgsrc_on.lastIndexOf('_on');
	if(undon > 0){
		var imgsrc = imgsrc_on.substr(0, undon) + imgsrc_on.substr(dot, 4);   
		$("#K-" + singicd).attr("src",imgsrc);
	}
        //発言者アイコン画像onであれば画像offに
	var imgsrc_on = $("#S-" + singicd).attr("src");   
        var dot = imgsrc_on.lastIndexOf('.'); 
	var undon = imgsrc_on.lastIndexOf('_on');
        if(undon > 0){
		var imgsrc = imgsrc_on.substr(0, undon) + imgsrc_on.substr(dot, 4);   
		$("#S-" + singicd).attr("src",imgsrc);
	}
        //両方アイコン画像onであれば画像offに
	var imgsrc_on = $("#B-" + singicd).attr("src");   
        var dot = imgsrc_on.lastIndexOf('.'); 
	var undon = imgsrc_on.lastIndexOf('_on');
        if(undon > 0){
	        var imgsrc = imgsrc_on.substr(0, undon) + imgsrc_on.substr(dot, 4);   
		$("#B-" + singicd).attr("src",imgsrc);
	}
}



//参照アイコンクリック時の共通処理
function detail_click(){
//    $(".detail_icon").toggle(
    $(".detail_icon").click(
    	function(e) {
		//id からアイコン種類と審議コードを取得
		var tid= $(this).attr('id');
		var singicd=tid.substr(2, tid.length);
		var md=tid.substr(0,1);

		//アイコンoffに
		detailIcon_off(singicd);

		//クリックされた画像onに
	        var imgsrc = $(this).attr("src");   
	        var dot = imgsrc.lastIndexOf('.');   
	        var imgsrc_on = imgsrc.substr(0, dot) + '_on' + imgsrc.substr(dot, 4);   
		this.src = imgsrc_on;

		
		var disprow="#row" + singicd;
		var cell="#cell" + singicd;
waiting_for('#container');//ブロック
		//詳細部分HTML取得
		$.get("./reference.php", {"cd":singicd ,pars: Math.random() ,"mode":md },function(data){
			$(cell).html(data);
			detail_play_click(cell);
			//開く
			$(disprow).show();
			meetingname_height("index.php => detail_click 1");
			//選択行へページ内リンク
			//var tgtr = $(e.target).closest("tr");
			//var tgid = "#" + $(tgtr).attr("id");
			//$.scrollTo(tgid, 0);//0指定でスクロールしない
			closeDetail_click();
$('#container').unblock();//ブロック解除
		});
		return false;
//	},
//	function(){
//		//画像offに
//	        var imgsrc_on = $(this).attr("src");   
//	        var dot = imgsrc_on.lastIndexOf('.'); 
//		var undon = imgsrc_on.lastIndexOf('_on');
//	        if(undon > 0){
//			var imgsrc = imgsrc_on.substr(0, undon) + imgsrc_on.substr(dot, 4);   
//			alert(imgsrc);
//			this.src = imgsrc;
//		}
//
//		//title から審議コードを取得
//		var tid= $(this).attr('id');
//		var singicd=tid.substr(2, tid.length);
//		//閉じる
//		$("#row" + singicd).hide();
//		meetingname_height("index.php => detail_click 2");
//
//		return false;
	}
    );
}

//開いた参照の[閉じる]クリック時の処理
function closeDetail_click(){
	$(".closeDetail").click(function() {
		var thisid=$(this).attr("id");
		//審議コード取得（idが「close##」のようになっている）
		var singicd=thisid.substr(5,thisid.length);
		var targetRowID = "row" + singicd;//開いている行<tr>のidを設定
		//閉じる
		$("#" + targetRowID).hide();

		//アイコンoffに
		detailIcon_off(singicd);

		return false;
	});
}


//再生リンククリック時の共通処理
function play_click(){
	//VODリンククリック時
	$('a.play').click(function() {  
		//alert("href=" + $(this).attr("href"));
		//クリックされたリンク先URLを隠しオブジェクトに保持
		$('#clicked_link').val($(this).attr("href"));
		//クッキーチェック
		if (!ck_check()){
			//配信方法選択モーダルダイアログ表示
			showSelectMethod();
			return false;
		}else{
			var COOKIE_NAME = "watching_method";
			var COOKIE_VAL = $.cookie(COOKIE_NAME);
			if((COOKIE_VAL=="WB")||(COOKIE_VAL=="WN")){
				location.href=$('#clicked_link').val();
			}
			if((COOKIE_VAL=="SB")||(COOKIE_VAL=="SN")){
				openSl($('#clicked_link').val());
			}
			return false;
		}
	});	
}


//詳細の再生リンククリック時の共通処理
function detail_play_click(cell){
	$("[class*=play]",cell).click(function() {  
		//alert("href=" + $(this).attr("href"));
		//クリックされたリンク先URLを隠しオブジェクトに保持
		$('#clicked_link').val($(this).attr("href"));
		//クッキーチェック
		if (!ck_check()){
			//配信方法選択モーダルダイアログ表示
			showSelectMethod();
			return false;
		}else{
			var COOKIE_NAME = "watching_method";
			var COOKIE_VAL = $.cookie(COOKIE_NAME);
			if((COOKIE_VAL=="WB")||(COOKIE_VAL=="WN")){
				location.href=$('#clicked_link').val();
			}
			if((COOKIE_VAL=="SB")||(COOKIE_VAL=="SN")){
				openSl($('#clicked_link').val());
			}
			return false;
		}
	});	
}


//配信方法クッキーチェック
function ck_check(){
	var COOKIE_NAME = "watching_method";
	var options = { path: '/', expires: 10 };

	if ($.cookie(COOKIE_NAME)==null){
		//alert("配信方法を選択してください");
		return false;
	}
	return true;
}



//メニューよくある質問クリック時の処理
function faq_click(){
	$(".menuFaq").click(function() {
		//よくある質問表示
		show_faq();
		return false;
	});
}

//メニューご利用方法クリック時の処理
function howto_click(){
	$(".menuHowto").click(function() {
		//ご利用方法表示
		show_howto();
		return false;
	});
}

//メニュー発言検索クリック時の処理
function opinion_click(){
	$(".menuOpinion").click(function() {
		//発言検索表示
		show_opinion_top();
		return false;
	});
}


//よくある質問ページ内リンククリック時のスクロール処理
function faqLink_click(){
	$(".faqLink").click(function() {
		//var tid= $(this).attr('href');
		//alert(tid);
		var lnk=$(this).attr('href').split("#");
		//alert(lnk[1]);
		var t = "#" + lnk[1];
		$.scrollTo(t, 800);
		return false;
	});
}

//メイン部分（ご利用方法）表示
function show_faq(){

	////発言検索結果非表示
	$("#opinion_result_area").html("");
	$("#opinion_result_area").hide();
	////発言検索フォーム非表示
	$("#opinion_search_area").html("");
	$("#opinion_search_area").hide();

	//ご利用方法部分取得
	init_faq();


	////よくある質問部分表示
	$("#faq_area").show();

	////ご利用方法部分非表示
	$("#howto_area").html("");
	$("#howto_area").hide();

	//メイン部分非表示
	$("#result_area").html("");
	$("#result_area").hide();
	//検索フォーム部分非表示
	$("#search_area").html("");
	$("#search_area").hide();
	//お知らせ部分非表示
	$("#news").html("");
	$("#news").hide();

	////左メニュー表示
	$("#leftarea").show();
	
	meetingname_height("index.php => show_howto");
}
//メイン部分（ご利用方法）表示
function show_howto(){

	////発言検索結果非表示
	$("#opinion_result_area").html("");
	$("#opinion_result_area").hide();
	////発言検索フォーム非表示
	$("#opinion_search_area").html("");
	$("#opinion_search_area").hide();

	//ご利用方法部分取得
	init_howto();

	////ご利用方法部分表示
	$("#howto_area").show();

	////よくある質問部分非表示
	$("#faq_area").html("");
	$("#faq_area").hide();

	//メイン部分非表示
	$("#result_area").html("");
	$("#result_area").hide();
	//検索フォーム部分非表示
	$("#search_area").html("");
	$("#search_area").hide();
	//お知らせ部分非表示
	$("#news").html("");
	$("#news").hide();

	////左メニュー表示
	$("#leftarea").show();
	
	meetingname_height("index.php => show_howto");
}

//メイン部分（お知らせ・検索結果・検索フォーム）表示
function show_top(){

	////発言検索結果非表示
	$("#opinion_result_area").html("");
	$("#opinion_result_area").hide();
	////発言検索フォーム非表示
	$("#opinion_search_area").html("");
	$("#opinion_search_area").hide();

	////ご利用方法部分非表示
	$("#howto_area").html("");
	$("#howto_area").hide();
	////よくある質問部分非表示
	$("#faq_area").html("");
	$("#faq_area").hide();

//	//検索結果部分取得
//	init_result();
	//検索フォーム部分取得
	init_search();
	//お知らせ部分取得
	init_news();
	
	//メイン部分
	////お知らせ表示
	$("#news").show();
	////検索結果表示
	$("#result_area").show();
	////検索フォーム表示
	$("#search_area").show();

	////左メニュー表示
	$("#leftarea").show();
	
	meetingname_height("index.php => show_top");

}


//メイン部分（発言検索結果・発言検索フォーム）表示
function show_opinion_top(){
	////左メニュー非表示
	$("#leftarea").hide();

	//メイン部分非表示
	$("#result_area").html("");
	$("#result_area").hide();
	//検索フォーム部分非表示
	$("#search_area").html("");
	$("#search_area").hide();
	//お知らせ部分非表示
	$("#news").html("");
	$("#news").hide();

	////ご利用方法部分非表示
	$("#howto_area").html("");
	$("#howto_area").hide();
	////よくある質問部分非表示
	$("#faq_area").html("");
	$("#faq_area").hide();


	//発言検索結果部分取得
	init_opinion_result();
	//発言検索フォーム部分取得
	init_opinion_search();

	////発言検索結果表示
	$("#opinion_result_area").show();
	////発言検索フォーム表示
	$("#opinion_search_area").show();

	
	
	meetingname_height("index.php => show_opinion_top");

}


function init_kaigilist(){
	//会議リスト部分初期表示
	$.ajax({
	  url: "./kaigi_list.php",
	  cache: false,
	  success: function(data){
			$("#meetingname").html(data);

			$("p.kaigi > a").mouseover(function(){
				$(this).addClass("hover");
			}).mouseout(function(){
				$(this).removeClass("hover");
			});

		}
	});
}

function init_calendar(){
	//カレンダー初期表示
	$.ajax({
	  url: "./calendar.php",
	  cache: false,
	  success: function(html){
			$("#calendar").html(html);
			$("#calendar td").tooltip({
			track: true, 
			delay: 0, 
			showURL: false, 
			showBody: "<>", 
			fade: 250});
			caltd_click();
		}
	});
}


function init_result(){
	//検索結果部分初期表示
	$.ajax({
	  url: "./result_selecter.php",
	  cache: false,
	  type: "get",
	  data:{"mode":"default"},
	  success: function(data){
	  		$("#opinion_result_area").html("");//発言検索結果HTMLを消去
			$("#result_area").html(data);
			play_click();
			detail_click();
			meetingname_height("index.php => init_result()");
			
		}
	});
}
function init_search(){	
	//検索フォーム部分初期表示
	$.ajax({
	  url: "./consider.php",
	  cache: false,
	  type: "get",
	  success: function(data){
			$("#opinion_search_area").html("");//発言検索用のフォームHTMLを消去
			$("#search_area").html(data);
			meetingname_height("index.php => init_search()");
		}
	});
}
function init_news(){
	//お知らせ部分初期表示
	$.ajax({
	  url: "./news.php",
	  cache: false,
	  type: "get",
	  success: function(data){
			$("#news").html(data);
			meetingname_height("index.php => init_news()");
		}
	});
}
function init_howto(){
	//ご利用方法初期表示
	$.ajax({
	  url: "./howto.php",
	  cache: false,
	  type: "get",
	  success: function(data){
			$("#howto_area").html(data);
			meetingname_height("index.php => init_howto()");
		}
	});
}
function init_faq(){
	//ご利用方法初期表示
	$.ajax({
	  url: "./faq.php",
	  cache: false,
	  type: "get",
	  success: function(data){
			$("#faq_area").html(data);
			faqLink_click();//ページ内リンククリック時の処理
			meetingname_height("index.php => init_faq()");
		}
	});
}


function init_opinion_result(){
	//発言検索結果部分初期表示
	$.ajax({
	  url: "./opinion_result.php",
	  cache: false,
	  type: "get",
	  success: function(data){
			$("#result_area").html("");//会議検索結果HTMLを消去
			$("#opinion_result_area").html(data);
			play_click();
		}
	});
}
function init_opinion_search(){	
	//発言検索フォーム部分初期表示
	$.ajax({
	  url: "./opinion_form.php",
	  cache: false,
	  type: "get",
	  success: function(data){
	  		$("#search_area").html("");//会議検索用のフォームHTMLを消去
			$("#opinion_search_area").html(data);
		}
	});
}




      $(function(){
	
	//検索結果部分取得
	init_result();
	//検索フォーム部分取得
	init_search();
	//お知らせ部分取得
	init_news();
	//会議リスト部分取得
	init_kaigilist();
	//カレンダー部分取得
	init_calendar();

	////ご利用方法部分非表示
	$("#howto_area").hide();
	////よくある質問部分非表示
	$("#faq_area").hide();

	////発言検索結果非表示
	$("#opinion_result_area").hide();
	////発言検索フォーム非表示
	$("#opinion_search_area").hide();

	//文字サイズ変更に対応
	$('a[href^=#]').click(function(){
		meetingname_height("index.php => a# Click!");
	});

	    //配信方法選択モーダルダイアログ表示
	    $(".trigger").click(function(){
	        //クリックしたリンク先URLをクリア
		$('#clicked_link').val("");
		showSelectMethod();
		//クッキー選択値であればラジオボタン選択済みで表示
		$("#SelectMethod :radio").each(function() {
			var val = $(this).val();
			var COOKIE_NAME = "watching_method";
			if($.cookie(COOKIE_NAME)==val){
				$(this).attr({ checked: "checked" });
			}else{
				$(this).attr({ checked: "" });
			}
		});
	    });

	    //配信方法選択時
	    $("input.set").click(function(){
		//クッキーに保存
		var COOKIE_NAME = "watching_method";
		var options = { path: '/', expires: 10 };
		var COOKIE_VAL = $("#SelectMethod :radio:checked").val();//ラジオボタン選択値

		$.cookie(COOKIE_NAME, COOKIE_VAL, options);
		//alert("配信方法を選択しました");
		
		//配信方法選択モーダルダイアログ閉じる
		$.unblockUI();

		//再生を試みてクリックしたURLがあればそれを再生
		if ($('#clicked_link').val()!=""){
			if((COOKIE_VAL=="WB")||(COOKIE_VAL=="WN")){
				location.href=$('#clicked_link').val();
			}
			if((COOKIE_VAL=="SB")||(COOKIE_VAL=="SN")){
				openSl($('#clicked_link').val());
			}
		}
            });


	//再生リンククリック時の共通処理
	play_click();
	//「参照」リンククリック時の共通処理
	detail_click();
	//メニュー「ご利用方法」クリック
	howto_click();
	//メニュー「よくある質問」クリック
	faq_click();
	//メニュー「発言検索」クリック
	opinion_click();
	//ヘッダー画像クリック時の処理
	header_click();
	//今日の審議中継画像クリック時の処理
	today_click();
	
	meetingname_height("index.php => INIT");


      });