var mouseover_lang_list_sel = false;
var mouseover_lang_list_other = false;
var active_tab;
function initiateUserDropdown() {
  $("#user-arrow").mouseover(function() {
    $("#user-dropdown-div").show();
  });
  $("#user-arrow").mouseout(function() {
    $("#user-dropdown-div").hide();
  });
}
function initiateMenuDropdowns(this_active_tab) {
  active_tab = this_active_tab;
  $("#overview_sm_trigger").click(function() {
    $("#overview_sm").toggle();
  });
  $("#find-providers_sm_trigger").click(function() {
    $("#find-providers_sm").toggle();
  });
  $("#translation-jobs_sm_trigger").click(function() {
    $("#translation-jobs_sm").toggle();
  });
  $("#community_sm_trigger").click(function() {
    $("#community_sm").toggle();
  });
  $("#my_sm_trigger").click(function() {
    $("#my_sm").toggle();
  });
  initiateMenuMouseover("overview");
  initiateMenuMouseover("find-providers");
  initiateMenuMouseover("translation-jobs");
  initiateMenuMouseover("community");
  initiateMenuMouseover("my");
  // Initiate mouseover for all the menus
}
function initiateMenuMouseover(id) {
  $("#tb_"+id+"").mouseover(function() {
    $("#tb_"+id).removeClass('tab-ul-off');
    $("#tb_"+id).removeClass('tab-ul-on');
    $("#tb_"+id).addClass('tab-ul-mouseover');
  });
  $("#tb_"+id+"").mouseout(function() {
    var sm_display = $("#"+id+"_sm").css('display');
    if (sm_display=='none' || sm_display == undefined) {
      $("#tb_"+id).removeClass('tab-ul-mouseover');
      $("#tb_"+id).removeClass('tab-ul-on');
      if (active_tab == id) $("#tb_"+id).addClass('tab-ul-on');
      else $("#tb_"+id).addClass('tab-ul-off');
    }
  });
}
function initateUserTable(entity_id, table_id) {
  $("#"+table_id).mouseover(function() {
    $("#"+table_id).removeClass('user_table');
    $("#"+table_id).addClass('user_table_hover');
  });
  $("#"+table_id).mouseout(function() {
    if ($("#"+table_id+"_dd").css('display') == 'none') {
      $("#"+table_id).removeClass('user_table_hover');
      $("#"+table_id).addClass('user_table');
    }
  });
  $("#"+table_id+"_trigger").click(function() {
    $("#"+table_id+"_dd").toggle();
  });
}
$(document).ready(function() {
  $("#selected_lang").click(function() {
    mouseover_lang_list_sel = true;
    closeNavMenuIfNeeded();
    $("#other_lang_list").toggle();
  });
});

function closeNavMenuIfNeeded() {
  return;
}
function toggleDiv(id) {
  $("#"+id).fadeToggle();
}
jQuery.fn.fadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle'}, speed, easing, callback);
};

function initiateTipMessage(tip_id) {
  $("#close_"+tip_id).click(function() {
    $.get("/ajax/ajax_tip_message?tip_id="+tip_id);
    toggleDiv("tip_"+tip_id);
  });
}
function initiateFeedbackEntry(entry_id) {
  $("#close_"+entry_id).click(function() {
    if (eid_s > 0) $.get("/ajax/ajax_ptc.php?action=hide_feedback&entry_id="+entry_id+"&entity_id="+eid_s);
    else $.get("/ajax/ajax_ptc.php?action=hide_feedback&entry_id="+entry_id);
    toggleDiv("feedback_"+entry_id);
  });
}
function ptcAlertArr(a) {
  var str="";
  for (var i in a) str += a[i] + "\n";
  alert(str);
}
function ptcAlertOb(o) {
  var str="";
  for (var i in o) str += i + " : " + o[i] + "\n";
  alert("Object: "+str)
}
/*--------------------------------------------------
Limit the number of characters for a textarea

$("#textarea_id").keyup(function(){
  limitChars("textarea_id", 3255, "div_id to display message");
})
--------------------------------------------------*/
function limitChars(textid, limit, infodiv) {
  var text = $('#'+textid).val();
  var textlength = text.length;
  if(textlength > limit) {
    $('#' + infodiv).html('You have reached the maximimum of '+limit+' characters!');
    $('#'+textid).val(text.substr(0,limit));
    return false;
  }
  else {
    $('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
    return true;
  }
}
function initiateEditableTags() {
  $(".edit_area").editable("/ajax/ajax_ptc.php?action=save_tags", {
    loadurl   : "/ajax/ajax_ptc.php?action=get_tags",
    cancel    : "Cancel",
    submit    : "OK",
    indicator : "<img src=\"/images/wikiwords/loading.gif\">",
    tooltip   : "Click to edit...",
    height     : "25px",
    width     : "300px",
    callback  : function(value, settings) {
      if (value != "Click here to enter tags") {
        $(this).removeClass("tags_gry");
        $(this).addClass("tags");
      }
    }
  });
}
function initiateSubStrShow(id) {
  $("#trig_"+id).click(function() {
    if ($("#str_"+id).css('display') == 'none') {
      $("#str_"+id).show();
      $("#dots_"+id).hide();
      $("#trig_"+id).html("Less");
      $("#trig_"+id).removeClass('icon-arrow-down-sm');
      $("#trig_"+id).addClass('icon-arrow-up-sm');
    }
    else {
      $("#str_"+id).hide();
      $("#dots_"+id).show();
      $("#trig_"+id).html("More");
      $("#trig_"+id).removeClass('icon-arrow-up-sm');
      $("#trig_"+id).addClass('icon-arrow-down-sm');
    }
  });
}
