var lng = SURFPOINT.getCityLng();
var lat = SURFPOINT.getCityLat();
var lngsec = Math.round(lng * 60 * 60 * 1000);
var latsec = Math.round(lat * 60 * 60 * 1000);

window.onload = function() {
  
  childrenClose();
  
  $$("h3.Bgenre").each(function(obj){
    Event.observe(obj, "click", clickbig, false);
  });
  
  $$("span.Child").each(function(obj){
    Event.observe(obj, "mouseout", outsmall, false);
    Event.observe(obj, "mouseover", oversmall, false);
    Event.observe(obj, "mousedown", downsmall, false);
  });
}

function clickbig(event){
  var eID = Event.element(event);
  var childrenid = 'Sgenre_' + eID.id.replace('Bgenre_','');
  
  if($(childrenid).style.display == 'none'){
    childrenClose();
    $(childrenid).style.display = '';
    $(eID.id).style.backgroundPosition = '0 0';
  } else {
    $(childrenid).style.display = 'none';
    $(eID.id).style.backgroundPosition = '0 -20px';
  }
}
function childrenClose(){
  $$("ul.Sgenre").each(function(obj){
    $(obj.id).style.display = 'none';
  });
  $$("h3.Bgenre").each(function(obj){
    $(obj.id).style.backgroundPosition = '0 -20px';
  });
}
function outsmall(event){
  var eID = Event.element(event);
  $(eID.id).style.backgroundPosition = '0 0';
}
function oversmall(event){
  var eID = Event.element(event);
  $(eID.id).style.backgroundPosition = '0 -15px';
}
function downsmall(event){
  var eID = Event.element(event);
  $(eID.id).style.backgroundPosition = '0 -30px';
}

function SearchStation(){
  
  var stationjson = 'http://api.doko.jp/extlightv1/getLandmark.do?method=getLandmark&key=4717c7ae2d0458766258b888da8e243d&format=json&callback=nearstation&lon_jgd='+lng+'&lat_jgd='+lat+'&pn=%e9%a7%85&radius=5000&pagesize=20';
  
  var scriptTag = document.createElement("script");
  scriptTag.setAttribute("type", "text/javascript");
  scriptTag.setAttribute("src", stationjson);
  document.getElementsByTagName("head").item(0).appendChild(scriptTag);
}
function nearstation(data){
  var landmark = data.results.landmarks.landmark;
  var i = 0;
  if(data.results.totalcount > 0){
    while(landmark[i]){
      $("nearstation").innerHTML += '<a href="http://travel.navikun.jp/station/' + encodeURI(landmark[i].name) + '/">' + landmark[i].name + '</a> ';
      i++;
    }
  }
}

function jumpURL(url){
  window.open(url, null);
}