$(function() {
  
  //pagetop
  $().UItoTop({ easingType: 'easeOutQuart' });
  
  //preloader
  $('#gallery img').lazyload({
	  effect: 'fadeIn',
	  event : 'scroll'
  });
  
  var col = '';
  var inviewDiv = '';
  var ocol = $('#all').css('background-color');
  var bgColor = {
  gallery: '#000000',
  a09: '#000000',
  a08: '#122B54',
  a06: '#220640',
  a04: '#270304',
  a03: '#2F230D',
  a02: '#050F06',
  a01: '#222222',
  aboutIn: '#f9f9f9'
  };
   
  $(window).scroll(function () {
	  inviewDiv = $('#centerContents .ch > div:in-viewport:first').attr('id');
	  
	  $('#rightContents a.active').removeClass('active');
	  $('#rightContents a[href=#'+inviewDiv+']').addClass('active');
	  col = bgColor[inviewDiv];
	  
	  $('#all').stop().animate({backgroundColor: col}, 300);
	  
      //$(document).attr('title', $('.nav a[href=#'+inview+']').attr('title'));

  });
  /*$(document).cheatCode({
	code : '38,38,40,40,37,39,37,39,66,65',
	activated : function(){
		$('#all').append('<div id="overlay"><div id="fade"></div><div class="popup_block"><img src="images/newyear.jpg" alt="" width="800" height="620"><br /><a href="http://www.pixiv.net/member.php?id=22763">pixiv</a> <a href="http://twitter.com/itori666">twitter</a><br /><a href="/">-close-</a></div></div>');
	}
  });*/
  //scroller
  $('a[href*=#]').click(function () {
	  if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
		  var $target = $(this.hash);
		  $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
		  if ($target.length) {
			  var targetOffset = $target.offset().top;
			  $('html,body').animate({
				  scrollTop: targetOffset
			  }, 1000, 'easeOutQuart');
			  return false;
		  }
	  }
  });
});
