// JavaScript Document
$(function(){

  /*========================================================*/
  //PopUpWindow
   $(".popupwindow").popupwindow(profiles);


  /*========================================================*/
  //ページ別制御
  var body_id = $('body').attr('id');

  //「新築・リフォーム施工事例」
  if(body_id == 'cnt_jirei'){
  	
  	/*--------------------------------------------------------*/
  	// サイドメニュー生成
  	// ページに表示されている記事情報を取得して配列に格納
  	// 順に出力してメニューを生成する

  	var length = $('#cont_jirei > li').length;
  	//alert(length);
  	
  	var tags = $('#cont_jirei h3.entry_tag').map(function(){
  		return $(this).text();
  	});
  	
  	var titles = $('#cont_jirei h4.entry_title').map(function(){
  		return $(this).text();
  	});
  	
  	var ids = $('#cont_jirei > li > a').map(function(){
  		return $(this).attr('id');
  	});
  	
  	for( i=0 ; i<length ; i++ ) {
  		$('#jirei_menu').append('<dt>'+tags[i]+'</dt><dd><a title="'+ids[i]+'">'+titles[i]+'</a></dd>');
  	}
  }

  //「イベント・キャンペーン」
  if(body_id == 'cnt_event'){

  	var length = $('#cont_event > li').length;
  	//alert(length);
  	
  	var event_date = $('#cont_event p.event_date').map(function(){
  		return $(this).text();
  	});
  	
  	var titles = $('#cont_event input[name="entry_title"]').map(function(){
  		return $(this).attr('value');
  	});
  	
  	var ids = $('#cont_event > li[id]').map(function(){
  		return $(this).attr('id');
  	});
  	
  	for( i=0 ; i<length ; i++ ) {
  		$('#side_menu2 > dl').append('<dt>'+event_date[i]+'</dt><dd><a title="'+ids[i]+'">'+titles[i]+'</a></dd>');
  	}
  }

  //「終了イベント・キャンペーン報告」
  if(body_id == 'cnt_event_end'){

  	var length = $('#cont_event > li').length;

  	var event_date = $('#cont_event p.event_date').map(function(){
  		return $(this).text();
  	});
  	
  	var titles = $('#cont_event input[name="entry_title"]').map(function(){
  		return $(this).attr('value');
  	});
  	
  	var ids = $('#cont_event > li[id]').map(function(){
  		return $(this).attr('id');
  	});
  	
  	for( i=0 ; i<length ; i++ ) {
  		$('#side_menu > dl').append('<dt>'+event_date[i]+'</dt><dd><a title="'+ids[i]+'">'+titles[i]+'</a></dd>');
  	}
  }

	/*--------------------------------------------------------*/
	// ページネーション整形
	var sp = $('#side_pagenavi');

	var pb = $('.pagenavi_back');
	if( pb.size() > 0 ){
		//alert(pb.html());
		pb.html( pb.html().replace(/[\[\]]/ig, "") );
		sp.append( pb.html().replace(/を見る/ig, "") );
	}

	var pn = $('.pagenavi_next');
	if( pn.size() > 0 ){
		//alert(pn.html());
		pn.html( pn.html().replace(/[\[\]]/ig, "") );
		sp.append( pn.html().replace(/を見る/ig, "") );
	}


  /*========================================================*/
  // 動的生成オブジェクトのページスクロール対応
  $("#side_menu a[title], #side_menu2 a[title]").live("click" , function(){
    coliss.toAnchor($(this).attr('title'));
  });


});


/*========================================================*/
//PopUpWindow設定
var profiles = {};

function unloadcallback(){
	alert("unloaded");
};

