/**
 * @name main.js
 * @fileOverview
 * @version 1.1
 * @description
 * <p>(c) FOURDIGIT Inc. Licensed <a href="http://ja.wikipedia.org/wiki/GNU_General_Public_License">GNU General Public License</a>.</p>
 */

//他ライブラリと共存する場合、下の一行コメントアウト解除($無効化)
//jQuery.noConflict();

/**
 * config
 */
(function($){
  $(function() {
	//bodyのクラスにブラウザ情報を追加
		$.addClassUA();
	//easyOverのターゲット設定
		$("img.ahover, .ahoverArea img, .submitBtn input[type=image]").easyOver();
	//IE5,6にてPNG有効化 (pngfixの読み込みが必要)
		//$("img[src$=png],p.png").enablePNG();
	//Flash
		//$("object, embed").enableFlash();
  //HTML5タグ有効化
  	//$.enableHTML5();
	//ポップアップリンクに置換
		$(".commonPop").easyPop();
	//他ドメインリンク時にpageTracker有効化
		//$("a,area").blankLogToGoogle();
	//アンカーリンクをスムージング
		$(".pagetop a[href^=#],.subsubnavi a[href^=#],.areaNav a[href^=#]").smoothScroll();
	//対象の要素をスクロールに追従するようにする
		//$("#fixBox").fixPosition("stopperID","normal");
	//対象の要素がopenerを判別して挙動を変える
		//$("a.moveOpener, area.moveOpener").moveOpener();
	//heightline
	  //$(".separator").heightline('.box');
	  $(".separator").each(function(){
	    $(this).heightline('.box');
	  });
	  $(".memberPlanList").each(function(){
	    $(this).heightline('.title');
	  });
	  $(".wrapHeight").each(function(){
	    $(this).heightline('.boxSame');
	  });

  //toolTip
  	$('.toolTip').each(function(){
  	  var thisArea = $(this);
  	  var thisLink = $(thisArea).find('.toolTipSwitch');
  	  var toolTipAreaHtml = $(thisArea).find('.toolTipArea').html();
    	// toolTips append
    	$(thisArea).find('.toolTipSwitch').click(
    		function() {
    		  $('.toolTipWrapper').hide();
      		$(thisArea).append(
      			'<div class="toolTipWrapper">'
      				+'<div class="toolTipTop"></div>'
      				+'<div class="toolTipMid">'
      					+toolTipAreaHtml
      				+'<p class="toolTipClose"><a href="javascript:void(0);" onclick="$(\'.toolTipWrapper\').hide();">閉じる</a></p>'
        			+'</div>'
        			+'</div>'
      		);
      // toolTip show
					var qHeight = $(thisLink).height();
					var qOffset = $(thisLink).offset();
					var wWidth = $(window).width();
					var qPosition = $(thisLink).position();
					var aPosiY = qHeight + qPosition.top + 2;
					var aPosiX = qPosition.left - 10;
					var aPosiX2 = qPosition.left - 100;
					if(wWidth / 2 < qOffset.left) { //画面の半分より右の場合
        		$(thisArea)
        		  .find('.toolTipWrapper')
        		    .addClass('toolTipWrapper')
          		  .css('top',aPosiY)
          		  .css('left',aPosiX)
          		  .show()
          		.end()
          	.end();
					} else { //通常
        		$(thisArea)
        		  .find('.toolTipWrapper')
          		  .css('top',aPosiY)
          		  .css('left',aPosiX)
          		  .show()
          		.end()
          	.end();
					}
      	}
    	);
  	});

   //datePicker
   if($(".datePickerInput")[0]) {
     $(".datePickerInput")
       .focus(function(){
     	   $('.toolTipWrapper').hide();
       })
       .datepicker({
         duration: 0,
         minDate: new Date(),
         numberOfMonths: 2,
         showButtonPanel: true
       })
       .focus(function(){
         $('.ui-datepicker').append('<p class="title">チェックイン日を選択してください。</p>');
         $('.ui-datepicker .title:odd').hide();
         $('.ui-datepicker .ui-datepicker-calendar .ui-datepicker-unselectable span.ui-state-default').css('color','#ffffff');
       });
   }

    $('#ResearchAreaMain .roomSelectParentLink, #ResearchAreaMain .roomSelectParentSelect, #ResearchAreaMain .roomSelectChildLink').bind('click',function(){
    	$('#ResearchAreaMain,.resultSort .toolTip a').css('position','static');
    });
    $('#ResearchAreaMain .toolTipClose a').bind('click',function(){
    	$('#ResearchAreaMain,.resultSort .toolTip a').css('position','relative');
    });

  //.room
  $('.room').find('table:first').find('td').css('padding-top','16px');

  //DateYetLabel
  $('.dateYetArea').each(function(){
    var thisArea = $(this);
    $(this)
      .find('.dateYet').click(
        function(){
          if($(this).attr('checked') == true) {
            $(thisArea).find('.datePickerInput').attr('disabled','disabled').css('background','#f9f9f9');
          } else if($(this).attr('checked') == false) {
            $(thisArea).find('.datePickerInput').removeAttr('disabled').css('background','#ffffff');
          }
        }
      )
    .end();
    $(this).find('.date').click(
      function(){
        $(thisArea).find('.datePickerInput').removeAttr('disabled').css('background','#ffffff');
      }
    );
  });

  //toggleArea
  	$('.toggleArea').each(function(){
  	  var thisArea = $(this);
  	  $(thisArea).find('.toggleAdd').hide();
  	  $(thisArea).find('.toggleSwitch').click(function(){
    	    $(thisArea).find('.toggleAdd').slideDown().css('z-index','0');
    	    $(thisArea).find('.toggleSwitch').css('z-index','0');
    	    $('.toolTipWrapper').hide();
    	});
  	  $(thisArea).find('.toggleClose').click(function(){
    	    $(thisArea).find('.toggleAdd').slideUp().css('z-index','1');
    	    $(thisArea).find('.toggleSwitch').css('z-index','10');
    	    $('.toolTipWrapper').hide();
  	  });
  	});

  //submit[ruturn]
  	$('.btReturn').each(function(){
  	  var thisArea = $(this);
  	  $(thisArea).find('a').click(function(){
    	    $(thisArea).find('input.hidden').click();
    	});
  	});

    $('.textHide').hide(0);
  	$('#introTxt').each(function(){
  	  var thisArea = $(this);
  	  $(this).find('.textOpenSwitch').find('a').click(function(){
  	    $(thisArea)
  	      .find('.textOpenSwitch')
  	        .hide()
  	      .end()
  	      .find('.textHide')
  	        .slideDown()
  	      .end()
  	    .end();
  	  });
  	});

    $("#AsideLeftMember input[type=text]").focus(function() {
      if($(this).val() == $(this).attr('dfVal'))
        $(this).val('');
      }).blur(function() {
      if(jQuery.trim($(this).val()) == "") {
        $(this).val($(this).attr('dfVal'));
      }
    });

  //switchImgs
    $('.switchImgsList li:last').addClass('last');
    $('.switchImgsList li')
      .each(function(){
        $(this).css('opacity','0.7');
      })
      .hover(
        function(){
          $(this)
            .addClass('hover')
            .css('opacity','1.0');
        },
        function(){
          $(this)
            .removeClass('hover')
            .css('opacity','0.7');
        }
      )
      .click(function(){
        $(this)
            .addClass('on')
            .css('opacity','1.0');
      });
	});
})(jQuery);

