var map;
var geocoder;

function loadPage(){
 load_map(0, map_x, map_y, map_scale, 'Map');
 run_hotoffer();
}

function load_map(pos_state, map_pos_x, map_pos_y, map_scale, map_type) {
 if (GBrowserIsCompatible()) {
  map = new GMap2(document.getElementById("map"));
  geocoder = new GClientGeocoder();		
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.addControl(new GScaleControl());
  map.addControl(new GOverviewMapControl());

  var const_map_type = G_NORMAL_MAP;
  switch(map_type){
   case 'hybrid': const_map_type = G_HYBRID_MAP; break;
   case 'satellite': const_map_type = G_SATELLITE_MAP; break;
 }
  if (!isset_map){
   map.setCenter(new GLatLng(map_pos_x, map_pos_y), map_scale, const_map_type);
  }

  var newIcon = new GIcon(G_DEFAULT_ICON);
  newIcon.image = markerImage;
  newIcon.shadow = 'http://hodakrealestate.com/html/im/marker_shadow.png';
  newIcon.shadowSize = new GSize(9, 9);
  newIcon.iconSize = new GSize(28, 28);
  markerOptions = { icon:newIcon };
 }
}

function set_item_pos(id){
 if (id != -1){
  var map_pos_x = document.getElementById('map_pos_x' + id).value;
  var map_pos_y = document.getElementById('map_pos_y' + id).value;
  var map_scale = parseInt(document.getElementById('map_scale' + id).value);
  var map_type = document.getElementById('const_map_type' + id).value;

  if (GBrowserIsCompatible()){
   var const_map_type = G_NORMAL_MAP;
   switch(map_type){
    case 'hybrid': const_map_type = G_HYBRID_MAP; break;
    case 'satellite': const_map_type = G_SATELLITE_MAP; break;
   }
  map.setCenter(new GLatLng(map_pos_x, map_pos_y), map_scale, const_map_type);
  document.getElementById('map').focus();
  }
 }
}

function getHotOffer(){
 var req = new JsHttpRequest();
 req.onreadystatechange = function()
 {
  if (req.readyState == 4){
   if (req.responseJS){
    document.getElementById('hot_offer').innerHTML = req.responseJS.hot_offer_block;
   }
  }
 }

 req.open('GET', 'http://' + DOMAIN_NAME + '/index.php?module=object_list&country_id=1205505442', true);
 req.send({'action':'get_hotoffer_ajax'});
}

function run_hotoffer(){
 hot_offer_timer = setInterval(getHotOffer, 5000);
}
