// JavaScript Document

// �f�t�H���g���S���W
var posY = 36.656508;  // �o�x
var posX = 137.218688; // �ܓx


var startCate = 0; // �ݒ�ŃX�^�[�g���̃J�e�S���[�w��

window.onload = function() {

  // wheelmouse
  wheelmouseInit();

  // GoogleMap
  map = new GMap2(document.getElementById("gmap"));
  map.setCenter(new GLatLng(posY, posX), 18);
  map.addControl(new GMapTypeControl());
  map.addControl(new GLargeMapControl());
  map.addControl(new GOverviewMapControl(new GSize(160,120)));
  map.addControl(new GScaleControl());

  /* �f�[�^�擾 */
  var msec = (new Date()).getTime();
  httpObj = GXmlHttp.create();
  httpObj.open("get", "mapdata.xml?cache="+msec);
  httpObj.onreadystatechange = function() {
    if((httpObj.readyState == 4) && (httpObj.status == 200)) {
      if(startCate != 0) { xmlDataAction(startCate); } else { xmlDataAction(0); }
    }
  }
  httpObj.send(null);

}


// �f�[�^����
function xmlDataAction(cate) {
  var xmlData = httpObj.responseXML;
  var pointData = xmlData.getElementsByTagName("point");

  //alert(pointData.length);
  map.clearOverlays();

  for ( var i=0; i<pointData.length; i++) {

    var point = pointData[i];

    wrking = point.getElementsByTagName("id")[0].firstChild;
    if(wrking) { tmpValue = wrking.nodeValue; } else { tmpValue = ""; }
    mid = tmpValue;

    wrking = point.getElementsByTagName("x")[0].firstChild;
    if(wrking) { tmpValue = wrking.nodeValue; } else { tmpValue = 0; }
    mx = tmpValue;

    wrking = point.getElementsByTagName("y")[0].firstChild;
    if(wrking) { tmpValue = wrking.nodeValue; } else { tmpValue = 0; }
    my = tmpValue;

    wrking = point.getElementsByTagName("name")[0].firstChild;
    if(wrking) { tmpValue = wrking.nodeValue; } else { tmpValue = ""; }
    mname = tmpValue;

    wrking = point.getElementsByTagName("cate")[0].firstChild;
    if(wrking) { tmpValue = wrking.nodeValue; } else { tmpValue = ""; }
    mcate = tmpValue;

    wrking = point.getElementsByTagName("addr")[0].firstChild;
    if(wrking) { tmpValue = wrking.nodeValue; } else { tmpValue = ""; }
    maddr = tmpValue;

    wrking = point.getElementsByTagName("tel")[0].firstChild;
    if(wrking) { tmpValue = wrking.nodeValue; } else { tmpValue = ""; }
    mtel = tmpValue;

    if(mx != 0 && my != 0) {
      if(cate == 0 || cate == mcate){ // �ΏۃJ�e�S���\��
        innerHtml = "<div><div><img src='img/gmap_icon" + mid + ".jpg' width='120' height='60' alt='" + mname + "' class='photo-border' /></div>";
        innerHtml += "<div><a href='shop" + mid + ".html'>" + mname + "</a></div>";
        innerHtml += "<div>" + maddr + "</div>";
        innerHtml += "<div>TEL : " + mtel + "</div>";
        addMarkerNormal(new GLatLng(my, mx), innerHtml, mname);
      }
    }
    if(cate == 0 ) {
      map.setCenter(new GLatLng(posY, posX), 18);
    } else if(cate == mcate) {
      map.setCenter(new GLatLng(my, mx), 18);
    }

  } // end of for i

}

// �}�[�J�[����
function addMarker(point, msg, name) {

  var compIcon = new GIcon();
  compIcon.image = "/map/img/gmap_icon.gif";
  compIcon.iconSize = new GSize(31, 31);
  compIcon.shadowSize = new GSize(50, 50);	
  compIcon.iconAnchor = new GPoint(15, 15);
  compIcon.infoWindowAnchor = new GPoint(15, 15);
  compIcon.infoShadowAnchor = new GPoint(0, 0);

  var marker = new GMarker(point, {title:name, icon:compIcon});
  map.addOverlay(marker);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(msg);
  });
}

// �}�[�J�[����
function addMarkerNormal(point, msg, name) {
  var marker = new GMarker(point, {title:name});
  map.addOverlay(marker);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(msg);
  });
}


/* ���[�N�΍� */
window.onunload = GUnload;

/* �z�C�[������ */
function wheelmouseInit(){
  if( navigator.userAgent.match( "MSIE"   ) ){ document.getElementById( "gmap" ).attachEvent( "onmousewheel" , mouseWheelZooming ); }
  if( navigator.userAgent.match( "Gecko"  ) ){ document.getElementById( "gmap" ).addEventListener( "DOMMouseScroll" , mouseWheelZooming , false ); }
  if( navigator.userAgent.match( "Safari" ) ){ document.getElementById( "gmap" ).onmousewheel = mouseWheelZooming; }
}

function mouseWheelZooming( event ){
  //�}�E�X�z�C�[���̏�^���̎擾�ƁA�X�N���[���̃L�����Z��
  if( navigator.userAgent.match( "MSIE"   ) ){ var delta = event.wheelDelta;   event.returnValue = false; }	//IE
  if( navigator.userAgent.match( "Gecko"  ) ){ var delta = event.detail * -1;  event.preventDefault();    }	//Gecko
  if( navigator.userAgent.match( "Safari" ) ){ var delta = event.wheelDelta;   event.returnValue = false; }	//Safari
  map.setZoom(map.getZoom() + ( delta < 0 ? -1 : 1 ) );
}

/* �z�C�[������ (Full��ʗp) */
/*
function wheelmouse(event){
  var delta = 0;
  if (!event) event = window.event;
  if (event.wheelDelta) {
    delta = event.wheelDelta / 120; 
    if (window.opera) { delta = -delta; }
  } else if (event.detail) {
    delta = -event.detail / 3;
  }
  if (delta) { map.setZoom(map.getZoom() + ( delta < 0 ? -1 : 1 ) ); }
}

if (window.addEventListener) {
  window.addEventListener('DOMMouseScroll', wheelmouse, false);
}
window.onmousewheel = document.onmousewheel = wheelmouse;
*/
