// MAP HANDLING  CLASS - provides all manipulations with the map
// by Melnychuk Oleg  [http://my.opera.com/melnichuck]


function Map() {}

/****************************************
	PUBLIC METHODS
*****************************************/

Map.prototype.updateMap = function() {
	var response;
	
	$.ajax({
		data: { 
			mw:	$(CONFIG.layer.map).parent().width(),
			mh:	$(CONFIG.layer.map).parent().height()
		},
		success: function(JsonRespond) { response = JsonRespond; }
	});
	
	return response;
};

Map.getMini = function() {
	var response;
	
	$.ajax({
		url: CONFIG.host.name + CONFIG.host.minimap,
		success: function(JsonRespond) { response = JsonRespond}
	});
	
	return response;
};

Map.prototype.findObjects = function(query) {
	var foundObjList;
	
	// query isn't emtpy
	if (query !== "") {
		$.ajax({
			url: CONFIG.host.name + CONFIG.host.search,
			data: { s: query },
			success: function(ObjListResponse) { foundObjList = ObjListResponse; }
		});
	}
	// prevent form submission
	return foundObjList;
};

Map.prototype.zoomIn = function() {
	var respond;
	
	$.ajax({
		data: {
			b: 1,
			x: CONFIG.coords.mainX,
			y: CONFIG.coords.mainY
		},
		success: function(JsonRespond) { respond = JsonRespond; }
	});
	
	return respond;
};

Map.prototype.zoomOut = function() {
	var respond;
	
	$.ajax({
		data: {
			b: 2,
			x: CONFIG.coords.mainX,
			y: CONFIG.coords.mainY
		},
		success: function(JsonRespond) { respond = JsonRespond; }
	});
	
	return respond;
};

Map.dragMap = function(offset) {
	var respond;

	$.ajax({
		data: {
			b: 0,
			x: parseInt(offset.X, 10),
			y: parseInt(offset.Y, 10)
		},
		success: function(JsonRespond) { respond = JsonRespond; }
	});
	
	return respond;
};

Map.prototype.point = function(X, Y) {
	var objects;
	
	$.ajax({
		url: CONFIG.host.name + CONFIG.host.obj,
		data: {
			b: 4,
			x: X,
			y: Y
		},
		success: function(objResponse) { objects = objResponse; }
	});
	
	return objects;
};

// send the click coordinates and viewport
Map.showObject = function(layerType, objID) {
	var object;
	
	$.ajax({
		data: {
			layer: layerType,
			obj: objID
		},
		success: function(objResponse) { object = objResponse; }
	});
	
	return object;
};