if(typeof wxtools == 'undefined') {
	var wxtools = {};
	var wxTools = wxtools;


}

// rudimentary logging - we should improve this A LOT
	wxtools.log = function(message) {
		if (document.getElementById('log_target')){
		document.getElementById('log_target').innerHTML = message + '<br />' + document.getElementById('log_target').innerHTML;
		}
	}


wxtools.FlashMap_SWF = 'http://i.uk.imwx.com/global/flash/interactive_maps/maps/v1_03/i_map.swf?cb=07282008';

wxtools.FlashMap_instances = {};
wxtools.FlashMapLoaded =function(id, state){wxtools.FlashMap_instances[id].onLoad(state)};
wxtools.FlashMapPan = function(id, latitude, longitude) { wxtools.FlashMap_instances[id].onPan(latitude, longitude); };
wxtools.FlashMapZoom = function(id, level) { wxtools.FlashMap_instances[id].onZoom(level); };
wxtools.FlashMapSetLayer = function(id, type, layer) {wxtools.FlashMap_instances[id].onSetLayer(type, layer); };
wxtools.FlashMapSetTrans = function(id, transparency) { wxtools.FlashMap_instances[id].onSetTransparency(transparency); };
wxtools.FlashMapPopUpMsg = function(id, message) { wxtools.FlashMap_instances[id].onPopUp(message); };
wxtools.FlashMapAnimate = function(id) { wxtools.FlashMap_instances[id].onAnimate(); };
wxtools.stopAnimate = function(id) { wxtools.FlashMap_instances[id].stopAnimate(); };
wxtools.animateStepBackward = function(id) { wxtools.FlashMap_instances[id].animateStepBackward(); };
wxtools.animateStepForward = function(id) { wxtools.FlashMap_instances[id].animateStepForward(); };
wxtools.animateOnToStart = function(id) { wxtools.FlashMap_instances[id].animateOnToStart(); };
wxtools.animateOnToEnd = function(id) { wxtools.FlashMap_instances[id].animateOnToEnd(); };
wxtools.FlashMapSetPoi = function(id, poi) { wxtools.FlashMap_instances[id].onSetPoiLayer(poi); };
wxtools.FlashMapPlotArbitrary = function(id) { wxtools.FlashMap_instances[id].onPlotArbitraryLayer(); };
wxtools.FlashMapIconClick = function(id) { wxtools.FlashMap_instances[id].onPoiIconClick();};



//add for page2flash call

wxtools.FlashMap = function(targetID, latitude, longitude, level, config) {
	var poi="";
	wxtools.FlashMap_instances[targetID] = this;
	
	this.targetID = targetID;
	this.targetElement = document.getElementById(this.targetID);	
	this.latitude = latitude;
	this.longitude = longitude;
	this.level = level;
	this.bounds=null;	
	this.layers = {basemap:'hybrid', wxlayer:'radar'};
	this.poi=poi;
	this.transparency = null;
	this.lastMessage = '';
	this.animated = false;
	
		
	this.mapObj = null;
	
	EventBroadcaster.initialize(this);
};
wxtools.FlashMap.prototype = {
	broadcastMessage:function() {},
	addListener:function() {},
	removeListener:function() {},
	
	getTargetID:function() { return this.targetID; },
	getCenter:function() { return {latitude:this.latitude, longitude:this.longitude}; },
	getZoom:function() { return this.level; },
	getLayers:function() { return this.layers; },
	getTransparency:function() { return this.transparency; },
	getLastMessage:function() { return this.lastMessage; },
	getAnimated:function() { return this.animated; },
	getPoi:function() { return this.poi; },
	getBounds:function() { return this.bounds; },
	setBounds:function(bounds) { this.bounds=bounds; },
	
	setSWFObject:function(){
		this.targetElement = swfobject.getObjectById(this.targetID + '_obj');

	},

	
	//page to Flash communication
	pointLayerSelect:function(dataURL,bubbleURL,iconString,what){
		this.targetElement.pointLayerSelected(dataURL,bubbleURL,iconString,what);
		this.broadcastMessage("deactivate");
	},
	
	
	weatherLayerSelect:function(layer){
               if (layer==null) layer="none";
		this.targetElement.weatherLayerSelected(layer);
	},
	
	turnOffAllPoint:function(){
		if (this.targetElement == null){
			this.setSWFObject();
		}
		this.targetElement.turnOffAllPoint(false);
		this.broadcastMessage("deactivate");
	},
	
	onAnimationChange:function(buttonId){
		if (this.targetElement == null){
				this.setSWFObject();
		}
		this.targetElement.onAnimationChange(buttonId);	
	},
	
	onTransparencyChange:function(number){
		if (this.targetElement == null){
			this.setSWFObject();
		}
		this.targetElement.onTransparencyChange(number);	
	},
	
	reCenterMap:function(lat,lon,zoom){
		if (this.targetElement == null){
			this.setSWFObject();
		}
		this.targetElement.setMapToLocation(lat,lon,zoom);
	},
	
	turnOffMyMarkers:function(){
		if (this.targetElement == null){
			this.setSWFObject();
		}
		this.targetElement.turnOffMyMarkers();
	},
	
	onUnitChange:function(unit){
		if (this.targetElement == null){
			this.setSWFObject();
		}
		this.targetElement.onUnitChange(unit);
	},
	
	turnOffCustomPoint:function(){
		if (this.targetElement == null){
					this.setSWFObject();
		}
		this.targetElement.turnOffCustomPoint();	
	},
	
	turnOffMyMarkers:function(){
		if (this.targetElement == null){
					this.setSWFObject();
		}
		this.targetElement.turnOffMyMarkers();
	},
	
	setMarkerOnMap:function(lat,lon,name){
		if (this.targetElement == null){
					this.setSWFObject();
		}
		this.targetElement.setMarkerOnMap(lat,lon,name);	
	},
	
	turnOnMyMarkers:function(bubbleUrl,lat1, long1, name1, temp1, locid1, lat2, long2, name2, temp2, locid2, lat3, long3, name3, temp3, locid3, lat4, long4,name4, temp4, locid4, lat5, long5, name5, temp5, locid5){
			if (this.targetElement == null){
						this.setSWFObject();
			}
			this.targetElement.turnOnMyMarkers(bubbleUrl,lat1, long1, name1, temp1, locid1, lat2, long2, name2, temp2, locid2, lat3, long3, name3, temp3, locid3, lat4, long4,name4, temp4, locid4, lat5, long5, name5, temp5, locid5);
	
	 	},
	
	
	
	
	resolveCustomPointSearch:function(lat, lon, searchString, bubbleURL,zoom, temp) {
		if (this.targetElement == null){
					this.setSWFObject();
		}
		this.targetElement.resolveCustomPointSearch(lat, lon, searchString, bubbleURL,zoom, temp) ;
	},
	
	
	onLoad:function(state){
			this.loaded=state;		
			
			this.targetElement = swfobject.getObjectById(this.targetID + '_obj');
			this.broadcastMessage("ready");
			
	},
	
	
	//Following are Flash to page calls and flash communicates to the page
	//that the event was thrown
	
	setLayer:function(type, layer){
		this.layers[type] = layer;
	},
	
	onPan:function(latitude, longitude) {
		this.latitude = latitude;
		this.longitude = longitude;		
	   	this.broadcastMessage("onPan", latitude, longitude);
	},
	onZoom:function(level) {
		this.level = level;
		this.broadcastMessage("onZoom", level);
	},
	onSetLayer:function(type, layer) {
		this.layers[type] = layer;
		this.broadcastMessage("onSetLayer", type, layer);
	},
	onSetTransparency:function(transparency) {
		this.transparency = transparency;
		this.broadcastMessage("onSetTransparency", transparency);
	},
	onPopUp:function(message) {
		this.lastMessage = message;
		this.broadcastMessage("onPopUp", message);
	},
	onAnimate:function() {
		this.animated = true;
		this.broadcastMessage("onAnimate");
	},
	stopAnimate:function() {
		this.animated = false;
		this.broadcastMessage("stopAnimate");
	},
	animateStepBackward:function() {
		this.broadcastMessage("animateStepBackward");
	},
	animateStepForward:function() {
		this.broadcastMessage("animateStepForward");
	},
	animateOnToStart:function() {
		this.broadcastMessage("animateOnToStart");
	},
	animateOnToEnd:function() {
		this.broadcastMessage("animateOnToEnd");
	},
	
	onSetPoiLayer:function(poi) {	
		this.poi=poi;
		this.broadcastMessage("onSetPoiLayer", poi);
	},
	
	onPlotArbitraryLayer:function() {
		this.broadcastMessage("onPlotArbitraryLayer");
	},

	onPoiIconClick:function() {
			this.broadcastMessage("onPoiIconClick");
	}
	
};
var FlashMap = wxtools.FlashMap;

