$(function() {
  initMenu();
  //Global Network Map
  $(".pop_effect").hover(pop_hover, erasePop).click(erasePop);
  //Global Menu
  $(".global_menu_effect").hover(
    function(){$(this).attr("src", $(this).attr("src").replace("_off", "_on"));},
    function(){$(this).attr("src", $(this).attr("src").replace("_on", "_off"));initMenu();}
  ).click(allOffMenu);
});

/***************************************/
/* global function
/***************************************/
function initMenu() {
  var url = String(location.href).split("/")[4];
  if ( url.indexOf(".") == -1 && url != "" ) {
    var newUrl = "/english/img/global_menu/" + url + "_on.jpg";
    $("img[id = '" + url + "']").attr("src", newUrl);
  }
}

function allOffMenu() {
  $(".global_menu_effect").each(function(){$(this).attr("src", $(this).attr("src").replace("_on", "_off"));initMenu();});
}

function  pop_hover() {
  var coords = $(this).attr("coords").split(",");
  $("#map_focus").css({
    "display": "block",
    "left"  : coords[0] + "px",
    "top"   : coords[1] + "px",
    "width" : String(parseInt(coords[2]) - parseInt(coords[0])) + "px",
    "height": String(parseInt(coords[3]) - parseInt(coords[1])) + "px"
  });
  var id = $(this).attr("id");
  var contents = $( 'dt.' + id ).length;
      $("#map_pop")
          .append($("<p></p>")
              .html($( 'dt.' + id + ':first').html())
              .addClass("global_term"))
          .append($( 'dd.' + id + ':first' ).html())
          .append($("<p></p>")
              .html($( 'dt.' + id + ':eq(1)').html())
              .addClass("global_term")
              .addClass("sukima"))
          .append($( 'dd.' + id + ':eq(1)' ).html());

      $("#map_pop").show();
      $("#map_pop_top").show();
      $("#map_pop_bottom").show();
      $("#map_pop_main").show();
/*
      $("#map_pop").fadeIn(400);
      $("#map_pop_top").fadeIn(400);
      $("#map_pop_bottom").fadeIn(400);
      $("#map_pop_main").fadeIn(400);
*/
}

function erasePop() {
    $("#map_pop_main").css("display", "none");
    $("#map_focus").css("display", "none");
    $("#map_pop").css("display", "none").empty();
}
