/**
 * Class "ModelLocator"
 * Fully qualified class name: "com.globalsolarcenter.inquote.flexmap.ModelLocator"
 */
function ModelLocator(obj) {
	if (arguments.length > 0) {
		this.obj = arguments[0];
	} else {
		this.obj = FABridge["gscmap"].
			create("com.globalsolarcenter.inquote.flexmap.ModelLocator");
	}
}

ModelLocator.prototype = {
	getGeocoder : function () {
		return this.obj.getGeocoder();
	},
	setGeocoder : function (value) {
		this.obj.setGeocoder(value);
	},
	
	getLocation : function () {
		return this.obj.getLocation();
	},
	setLocation : function (value) {
		this.obj.setLocation(value);
	},

	getShowMeasureObject : function () {
		return this.obj.getShowMeasureObject();
	},
	setShowMeasureObject : function (value) {
		this.obj.setShowMeasureObject(value);
	},

	getEnableMeasureTool : function () {
		return this.obj.getEnableMeasureTool();
	},
	setEnableMeasureTool : function (value) {
		this.obj.setEnableMeasureTool(value);
	},

	getStates : function () {
		return this.obj.getStates();
	},
	setStates : function (value) {
		this.obj.setStates(value);
	},
	getMeasureTool : function () {
		return this.obj.getMeasureTool();
	}
}

/**
 * Callbacks
 */

function setGSCMapAddress(addr) {
	flexApp.doGeocode(addr);
}
function setCenterByLatLng(lat, lng, zoom) {
	flexApp.setCenterByLatLng(lat, lng, zoom);
}
function setCenterByAddress(addr, zoom) {
	flexApp.setCenterByAddress(addr, zoom);
}

var MapMoveStartCallback = function(event) {
	//alert("MapMoveStartCallback:"+event);
}
var MapMoveEndCallback = function(event) {
	//alert("MapMoveEndCallback:"+event);
}

var MapReadyCallback = function(event) {
	mapReady = true;
}

var MapClickCallback = function(event) {
	//alert("MapClickCallback:"+event);
	//alert("lat:"+flexModel.getLocation().getLat() + "\n long:" + flexModel.getLocation().getLng());
}
var MeasureToolResizedCallback = function(event) {
	//alert("MapMoveEndCallback:"+event);
	//alert("x:"+flexModel.getMeasureTool().getX() + "\ny:" + flexModel.getMeasureTool().getY() + "\nwidth:" + flexModel.getMeasureTool().getWidth() + "\nheight:" + flexModel.getMeasureTool().getHeight() + "\nangle:" + flexModel.getMeasureTool().getRotation() + "\narea:" + flexModel.getMeasureTool().getArea());
}

function getMapLocationObject() {
	//flexModel.getLocation().setAddress("from js");
	//alert("address:"+flexModel.getLocation().getAddress()+"\n,lat:"+flexModel.getLocation().getLat() + "\n long:" + flexModel.getLocation().getLng());
}



/**
 * Listen for the instantiation of the Flex application over the bridge
 */
var flexApp;
var flexModel;
var mapReady = false;
FABridge.addInitializationCallback("gscmap", initializeFABridge);
function initializeFABridge() {
	flexApp = FABridge["gscmap"].root();
	flexModel = flexApp.getModelLocator();
	// Register callbacks
	flexApp.getMeasureTool().addEventListener("objectResizedEvent",MeasureToolResizedCallback);
	flexApp.getMap().addEventListener("mapevent_mapready",MapReadyCallback);
	flexApp.getMap().addEventListener("mapevent_movestart",MapMoveStartCallback);
	flexApp.getMap().addEventListener("mapevent_moveend",MapMoveEndCallback);
	flexApp.getMap().addEventListener("mapevent_click",MapClickCallback);
	
	
	
}




