var mojiSize = '';
$(function() {
  $('#nav').droppy();

  if (window['pageid']) {
    $('#nav'+pageid).removeClass('on');
    var src = $('#nav'+pageid).attr('src').replace("_off", "_on");
    $('#nav'+pageid).attr('src', src);
  }

  $('img.on').hover(
    function() {
      var src = $(this).attr('src').replace("_off", "_on");
      $(this).attr('src', src);
    },
    function() {
      var src = $(this).attr('src').replace("_on", "_off");
      $(this).attr('src', src);
    }
  );

  $('#toppic').fadeIn(1000);

  var scrollSpeed = 40;
  var direction = 'h';
  var current = Math.floor(Math.random() * 960);
  function bgscroll(){
    current -= 1;
    $('#toppic').css("backgroundPosition", (direction == 'h') ? current+"px 0" : "0 " + current+"px");
  }
  var init = setInterval(bgscroll, scrollSpeed);
  //setTimeout(function() { clearInterval(init); }, 5000);

  mojiSize = $.cookie('mojiSize');
  if (mojiSize == 'large') {
    large();
  } else if (mojiSize == 'middle') {
    middle();
  } else if (mojiSize == 'small') {
    small();
  }
});
function changeMojiButton(id) {
  var src;
  $('.moji').each(function() {
    src = $(this).attr('src').replace("_on", "_off");
    $(this).attr('src', src);
  });
  src = $('#'+id).attr('src').replace("_off", "_on");
  $('#'+id).attr('src', src);

  $.cookie('mojiSize',id);
}
function large() { $('#contents, td, th, p').css('font-size', '18px'); changeMojiButton('large'); }
function middle() { $('#contents, td, th, p').css('font-size', '14px'); changeMojiButton('middle'); }
function small() { $('#contents, td, th, p').css('font-size', '12px'); changeMojiButton('small'); }

