$(document).ready(function () {

  $("#map_info_window").dialog({
    autoOpen: false,
    bgiframe: true,
    width:460,
    height:200,
    open: function() {
      return;
    },
    buttons: {
      Ok: function() {
        $(this).dialog('close');
      }
    },
    close: function() {
      return;
    }
  });


});

function MapMessageBox(marker,map_object) {
  _this = this;
  //Variables
  this.marker = marker;
  this.map_object = map_object;
}

MapMessageBox.prototype.get_content = function() {
  return this.content; 
}

MapMessageBox.prototype.set_content = function(_content) {
  $('#map_info_window_content').html(_content);
}


MapMessageBox.prototype.set_title = function(_content) {
  $('#map_info_window').dialog('option', 'title', _content);
}

MapMessageBox.prototype.close_message_box = function(icon_type) {
  $('#map_info_window').dialog("close");
}

MapMessageBox.prototype.open_message_box = function(icon_type) {
  var content = this.content;
  //$('#map_info_window').dialog('option', 'buttons', { "Save Apartment": function() { $(this).dialog("close"); }, "View Apartment": function() {} });
  $('#map_info_window').dialog('option', 'buttons', {});
  $('#map_info_window').dialog('open');

  $('#map_info_window').bind('dialogclose', function(event, ui) {
    if(typeof icon_type != "undefined"){
      _this.marker.setImage(_this.map_object.icons_package[icon_type].image);
      _this.map_object.set_active_marker(null);
    }
  });
}

MapMessageBox.prototype.setPosition = function(pos,location,map_width,map_height){
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  if (typeof window.innerWidth != 'undefined'){
   viewportwidth = window.innerWidth,
   viewportheight = window.innerHeight
  }
  // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
  else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
    viewportwidth = document.documentElement.clientWidth,
    viewportheight = document.documentElement.clientHeight
  }
  // older versions of IE
  else{
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
    viewportheight = document.getElementsByTagName('body')[0].clientHeight
  }

  this.open_message_box();
  var info_window_height = $('#map_info_window').dialog('option', 'height');
  var info_window_width = $('#map_info_window').dialog('option', 'width');
  
  pos = [pos[0]+location.x-20-info_window_width,pos[1]+location.y-25-info_window_height]
  pos = [pos[0]-$(window).scrollLeft(),pos[1]-$(window).scrollTop()]
  $("#map_info_window").dialog('option', 'position',pos);
}

