<!--
$(function(){
  // ユーザID
  var uid = $('#uid').val();
  var login = ($('#login').val()==='true');
  var return_url = $('#return_url').val();
  var actionName = $('#actionName').val();
  var searchId = $('#searchId').val();

  // ログイン判定
  var is_login = function () { if(! login) location.href = '/login?return_url='+return_url; }

  var favoriteKeywordCopy = function(){
    is_login();

    if(login){
      $.fn.okwave.ui.confirm.open('お気に入りキーワードに追加しますか？');
      $.fn.okwave.ui.confirm.onYesClicked(function(){
        $.ajax({
          type: 'POST',
          url : '/ajax_keyword/copy',
          data : {search_id: searchId, uid: uid},
          success : function(res) {
            $.fn.okwave.ui.notice.open(res);
          },
          error : function() {
            $.fn.okwave.ui.notice.open('追加できませんでした。');
          }
        });
      });
    }
  }

  // ユーザプロフィールの取得
  var load_user_info = function() {
    $.getJSON(
    '/ajax_user/getuserstats',
    {'uid' : uid},
    function(json){
      $('#thank_rate').text(json.thankRate);
      $('#totalanswer_count').text(json.totalanswerCount);
      $('#thank_count').text(json.thankCount);
      $('#bestanswer_rate').text(json.bestanswerRate);
      $('#answer_count').text(json.answerCount);
      $('#bestanswer_count').text(json.bestanswerCount);
      $('#evaluated_answer').text(json.evaluatedAnswerCount);
      $('#favorited_user').text(json.favoritedUserCount);
      $('#answer_point').text(json.answerPoint);
    });
  }

  var toplist = function() {
    var keys = ['qList', 'aList', 'tList'];

    var today = new Date();
    $.getJSON(
    '/ajax_profile/toplist',
    {'uid' : uid, 'time' : today.getTime()},
    function(json){
      $.each(keys, function() {
        var list = json[this];
        if(list != undefined){
          if(list.indexOf('notFound') < 1){
            $('ul', '#' + this).remove();
            list = list + $('#' + this).html();
          }
          $('#' + this).html(list);
        }
      });
    });
  }

  var topBlockList = function() {
    var keys = ['favoriteCategoryList', 'favoriteKeywordList', 'favoriteQuestionList'];

    var today = new Date();
    $.getJSON(
    '/ajax_profile/blockfavoritelist',
    {'uid' : uid, 'time' : today.getTime()},
    function(json){
      $.each(keys, function() {
        var list = json[this];
        if(list != undefined){
          if(list.indexOf('notFound') < 1){
            $('ul', '#' + this).remove();
            list = list + $('#' + this).html();
          }
          $('#' + this).html(list);
        }
      });
    });
  }

  $('.btn_sort').toggle(
    function () {
      $('#sortmenuDrop').show();
    },
    function () {
      $('#sortmenuDrop').hide();
    }
  );

  $('.btn_favkeyword').live('click', function(){
    favoriteKeywordCopy();
    return false;
  });

  switch(actionName){
    case 'top':
      load_user_info();
      toplist();
      topBlockList();
      break;
    default:
      break;
  }

});
//-->
