if(typeof(SetCookie)!="function")
	function SetCookie(cookieName,cookieValue) {
		document.cookie = cookieName+"="+escape(cookieValue) + ";";
	}

if(typeof(ReadCookie)!="function")
	function ReadCookie(cookieName) {
		 var theCookie=""+document.cookie;
		 var ind=theCookie.indexOf(cookieName);
		 if (ind==-1 || cookieName=="") return ""; 
		 var ind1=theCookie.indexOf(';',ind);
		 if (ind1==-1) ind1=theCookie.length; 
		 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	}
	
	
/*
	Available functions through FlashMap.map:
		getMapX, setMapX
		getMapY, setMapY
		getMapZ, setMapZ
		getMapXYZ, setMapXYZ
		showMetro(cityID)
*/	

var FlashMap = (function(){
	
	function FlashMap(){
		var I = this;
		
	}
	
	FlashMap.prototype = {
		elementID:"",
		src:"map_1.swf",
		width:"492",
		height:"290",
		flashVars:{
			FlashMapXmlFeederUrl:"city.xml",
			//FlashMapExtraXMLUrl:"mapextra.xml",
			isEditMode:"false",
			disableControls:"false",
			debugMode:"0",
			FlashMapPostBack:ReadCookie('MAPZOOM')
		},
		flashParams:{
			allowScriptAccess:"always",
			quality:"high",
			//scale:"noscale",
			menu:"false",
			wmode:"transparent"			
		},
		map:null, 
		create:function(){
			var I = this;
			
			var flashVars = [];
			for(var prop in I.flashVars){
				flashVars.push(prop+"="+I.flashVars[prop].toString());
			}
			//console.dir(flashVars);
			var fo = new FlashObject(I.src, "mapswf", I.width, I.height, "9", "#FFFFFF");
			for(var prop in I.flashParams){
				fo.addParam(prop, I.flashParams[prop].toString());
			}
			fo.addParam("FlashVars", flashVars.join("&"));
			fo.write(I.elementID);
			
			I.map = document.getElementById("mapswf");
			//I.map.style.visibility="hidden";
			var loadInterval = setInterval(function(){
				if(typeof(I.map.setMapX)=="function"){
					I.map.style.visibility="visible";
					clearInterval(loadInterval);
					I.onReady();
				}
			}, 200);
		},
		onReady:function(){},
		
		
		setBookmark:function(bkmrk){
			SetCookie('MAPZOOM', bkmrk);
			var hField = document.getElementById( 'hFlashMapPostBack' );
			if(hField!=null) hField.value = bkmrk;
		},
		
	
		
		showMetroPos:{
			txtX:"tbMapMetroXCoord",
			txtY:"tbMapMetroYCoord",				
			x:function(xpos){
				document.getElementById(this.txtX).value=xpos;
			},
			y:function(ypos){
				document.getElementById(this.txtY).value=ypos;
			},
			xy:function(xpos,ypos){
				this.x(xpos);
				this.y(ypos);
			}
		},
		
		showCityPos:{
			txtX:"tbMapCityXCoord",
			txtY:"tbMapCityYCoord",				
			x:function(xpos){
				document.getElementById(this.txtX).value=xpos;
			},
			y:function(ypos){
				document.getElementById(this.txtY).value=ypos;
			},
			xy:function(xpos,ypos){
				this.x(xpos);
				this.y(ypos);
			}
		},
		
		showRegionConstraints:{
			txtX:"tbMapRegionXCoord",
			txtY:"tbMapRegionYCoord",	
			txtWidth:"tbMapRegionWidth",
			txtHeight:"tbMapRegionHeight",
			x:function(xpos){
				document.getElementById(this.txtX).value=xpos;
			},
			y:function(ypos){
				document.getElementById(this.txtY).value=ypos;
			},
			width:function(w){
				document.getElementById(this.txtWidth).value=w;
			},
			height:function(h){
				document.getElementById(this.txtHeight).value=h;
			},
			all:function(xpos,ypos,w,h){
				this.x(xpos);
				this.y(ypos);
				this.width(w);
				this.height(h);
			}
		
		}
		
	
	}
	
	return FlashMap;

})();






			
			
/* LEGACY FUNCTION STILL REQUIRED BY SOME MAP INSTANCES */
			
function setFlashMapPos(posTo, mapObj){
	//console.log("setFlashMapPos("+posTo+", "+mapObj+")");
	//mapObj.SetVariable('posTo', posTo);
	var posTo = posTo.split(",");				
	mapObj.setMapXYZ(parseInt(posTo[0]),parseInt(posTo[1]), parseInt(posTo[2]));
}



function setFlashMapPostBack( args )
{ 
	SetCookie('MAPZOOM',args);
}



function setAllProps() {				
	//arguments may be
		//x,y for non-edit instances
		//x,y,bkmrk for city
		//x,y,width,height,bkmrk
	var x = arguments[0],
		y = arguments[1],
		width,
		height,
		bkmrk = [arguments.length-1];
	
	//for editing map instances only
	if(arguments.length == 3){
		setXpos(x);
		setYpos(y);
	}else if(arguments.length == 5){
		width = arguments[2];
		height = arguments[3];
		setXpos(x);
		setYpos(y);
		setWidth(width);
		setHeight(height);						
	}
	
	//for all instances
	setFlashMapPos(x+","+y);
	setFlashMapPostBack(bkmrk);	
	
}












/*
function setXpos(args) { 
	var tbMapXCoord = document.getElementById( 'tbMapXCoord' ),
		tbULCX = document.getElementById( 'tbULCX' )
	if(tbMapXCoord)tbMapXCoord.value = args;
	if(tbULCX) tbULCX.value = args;
}
function setYpos(args) {
	var tbMapYCoord = document.getElementById( 'tbMapYCoord' ),
		tbULCY = document.getElementById( 'tbULCY' )
	if(tbMapYCoord)tbMapYCoord.value = args;
	if(tbULCY) tbULCY.value = args;
}

function setWidth(args) {document.getElementById( 'tbWidth' ).value = args; }
function setHeight(args) {document.getElementById( 'tbHeight' ).value = args; }

function setFlashMapPostBack(args) { document.getElementById( 'hFlashMapPostBack' ).value = args;   }*/
			