// 検索バーをデフォルトで隠す
window.addEventListener('load',
	function(){
		setTimeout(function(){
			scrollTo(0,1);
		},100);
	}, false);

//クリックしてスライド
$(function() {
  var winWidth = window.innerWidth;
  
  /**
   * ページ内リンクのクリックイベント
   */
  $('a[href^=#]').click(function() {  
    if ($(this).attr('href') == '#index') {
    	goIndex();
    } else {
      $('#index').animate({
        left: (winWidth * -1) + 'px'
      }, 500, function() { $(this).removeClass('active') });
      
      $($(this).attr('href')).css('left', winWidth).addClass('active').animate({
        left: 0
      }, 500);

      return false;
    }
  });
  
  /**
   * フリックでの戻る
   */
  document.addEventListener("touchstart", start, false);
  document.addEventListener("touchmove", move, false);
  document.addEventListener("touchend", end, false);

  var startX, endX;

  function start() {
    startX = event.touches[0].pageX;
  }
  
  function move(e) {
    endX = event.touches[0].pageX;
  }
  
  function end(e) {
    if (endX - startX > 100) {
      goIndex();
    }
  }


  /**
   * 戻る
   */
  function goIndex() {
  	if ($('div.active').attr('id') == 'index') return false;
  
    $('div.active').animate({
      left: winWidth + 'px'
    }, 500, function() { $(this).removeClass('active'); });
    $('#index').css('left', (winWidth * -1) + 'px').addClass('active').animate({
      left: 0
    }, 500);
  }
});


