function MMRouterClient(){

var _logger=log4javascript.getLogger("IWRoutingClient");
var _routeOptions=new MMRouteOptions();
this.setRouteOptions=function(routeOptions){
_routeOptions=routeOptions;
};
this.getRouteOptions=function(){
return _routeOptions;
};
this.route=function(start,destination,interstations){

var params='';
params=params.concat('&X1=').concat(start.getX());
params=params.concat('&Y1=').concat(start.getY());
params=params.concat('&X2=').concat(destination.getX());
params=params.concat('&Y2=').concat(destination.getY());
if((interstations !=null)&&(typeof interstations !='undefined')){
for(var i=0,n=1;
i<interstations.length;
i++,n++){
params=params.concat('&IX').concat(n).concat('=').concat(interstations[i].getX());
params=params.concat('&IY').concat(n).concat('=').concat(interstations[i].getY());
}
}
if(_routeOptions !=null){
params=params.concat('&LANG=').concat(_routeOptions.getLanguage());
params=params.concat('&MODE=').concat(_routeOptions.getRoutingMode());
params=params.concat('&SPEED_CI=').concat(_routeOptions.getCitySpeed());
params=params.concat('&SPEED_CO=').concat(_routeOptions.getCountryRoadSpeed());
params=params.concat('&SPEED_HI=').concat(_routeOptions.getHighwaySpeed());
params=params.concat('&SHAPE=').concat(_routeOptions.isShapeEnabled()? "1":"0");
}
var url=iwconst.LOCAL_APP_URL + '/servlet/FrontController' +'?cmd=route' +'&app=ms' +'&VNR=' + IWAccessFilter.getCNR()+'&PNR=' + IWAccessFilter.getPNR()+params;
var xmlHttp=new IWXMLHttpRequest();
xmlHttp.open('GET',url,true);
xmlHttp.onreadystatechange=function(){
routeCallback(this,xmlHttp, start, destination, interstations);
}.iwclosure(this);
xmlHttp.send(null);
};
this.toString=function(){
return '[IWRouterClient]' +(_routeOptions !=null ? _routeOptions.toString():'null');
};
this.onRouteEvent=function(event){
IWEventManager.trigger(this,'onroute',event);
};

    this.getTravelBreaks = function(self, start, destination, interstations){
    
    	var ORG_GLOBAL_APP_URL = '';
    	var url = ORG_GLOBAL_APP_URL+'standorteXML/?action=doAjax';
    	
    	var interstaionsString = '';
        if ((interstations != null) && (typeof interstations != "undefined")) {
           for (var i = 0; i < interstations.length; i++) {
           		if (i > 0){
           			interstaionsString = interstaionsString + ',';
           		}
               interstaionsString = interstaionsString + ((interstations[i].getX() + '|' + interstations[i].getY()));
           }
        }
        
		$.post(url, { startX: start.getX(), 
					  startY: start.getY(), 
					  destX: destination.getX(), 
					  destY: destination.getY(),
					  type: _routeOptions.getRoutingMode(),
					  cityspeed: _routeOptions.getCitySpeed(),
					  countryspeed: _routeOptions.getCountryRoadSpeed(),
					  hightspeed: _routeOptions.getHighwaySpeed(),
					  profile: _routeOptions.getProfile(),
					  drivingTime: _routeOptions.getDrivingTime(),
					  interstation: interstaionsString },
		  			  
		  			  function(data){
		  				 IWEventManager.trigger(self, 'onroutestandort', data);
		  			  });

    }


function routeCallback(self,xmlHttp, start, destination, interstations){
if(xmlHttp.readyState==4){
if(xmlHttp.statusText=='OK'){
if(xmlHttp.responseText.length>0){
var root=xmlHttp.responseXML.documentElement;
var shape='';
var coordNW=null;
var coordSE=null;
var route=new Array();
if(root.getElementsByTagName('fail').length==0){
shape=IWXMLHelper.getNodeValue(root.getElementsByTagName('shape')[0]);
var directions=root.getElementsByTagName('dir');
var segments=directions.length;
if(segments>0){
var instructions=root.getElementsByTagName('text');
var xCoordinates=root.getElementsByTagName('x');
var yCoordinates=root.getElementsByTagName('y');
var routelengths=root.getElementsByTagName('routelength');
var routetimes=root.getElementsByTagName('routetime');
var routetotallengths=root.getElementsByTagName('routetotallength');
var routetotaltimes=root.getElementsByTagName('routetotaltime');
for(var i=0;
i<segments;
i++){
var segment=new IWRouteSegment();
segment.setInstruction(IWXMLHelper.getNodeValue(instructions[i]));
segment.setDirection(IWXMLHelper.getNodeValue(directions[i]));
segment.setCoordinate(new IWCoordinate(parseFloat(IWXMLHelper.getNodeValue(xCoordinates[i])),parseFloat(IWXMLHelper.getNodeValue(yCoordinates[i]))));
segment.setLength(IWXMLHelper.getNodeValue(routelengths[i]));
segment.setTime(IWXMLHelper.getNodeValue(routetimes[i]));
segment.setRouteLength(IWXMLHelper.getNodeValue(routetotallengths[i]));
segment.setRouteTime(IWXMLHelper.getNodeValue(routetotaltimes[i]));
var newCoord=segment.getCoordinate();
if(coordNW==null){
coordNW=new IWCoordinate(newCoord.getX(),newCoord.getY());
}
else
{
if(newCoord.getY()>coordNW.getY()){
coordNW=new IWCoordinate(coordNW.getX(),newCoord.getY());
}
if(newCoord.getX()<coordNW.getX()){
coordNW=new IWCoordinate(newCoord.getX(),coordNW.getY());
}
}
if(coordSE==null){
coordSE=new IWCoordinate(newCoord.getX(),newCoord.getY());
}
else
{
if(newCoord.getY()<coordSE.getY()){
coordSE=new IWCoordinate(coordSE.getX(),newCoord.getY());
}
if(newCoord.getX()>coordSE.getX()){
coordSE=new IWCoordinate(newCoord.getX(),coordSE.getY());
}
}
route.push(segment);
}
}
}
}
else
{
alert("Response text is empty.");
}
}
else if(xmlHttp.status==401){
alert(xmlHttp.statusText);
}
else
{
alert('Projection failed:' + xmlHttp.statusText);
}
}
else
{
throw 'Error. ReadyState:' + xmlHttp.readyState + ',Status:' + xmlHttp.statusText + ',Content-length:' + xmlHttp.responseText.length;
}



self.getTravelBreaks(self, start, destination, interstations);
var event=new IWRoutingEvent();
event.statusCode=xmlHttp.statusText;
event.shape=shape;
event.bounds=new IWBounds(coordNW,coordSE);
event.route=route;
self.onRouteEvent(event);
}
}




function MMRouteOptions(){
    var _profile=0;
    var _drivingTime=150;
	var _routingMode=0;
	var _citySpeed=50;
	var _countryRoadSpeed=70;
	var _highwaySpeed=120;
	var _language='en';
	var _shapeEnabled=false;
	this.SHORTEST_ROUTE=0;
	this.FASTEST_ROUTE=1;
	this.MOST_ECONOMIC_ROUTE=2;
	
	this.setShapeEnabled=function(shapeEnabled){
		if(shapeEnabled==true||shapeEnabled==false){
		_shapeEnabled=shapeEnabled;
		}
	};

	this.isShapeEnabled=function(){
		return _shapeEnabled;
	};
	
	   
    this.setProfile=function(profile){
        _profile=profile;
    };

    this.getProfile=function(){
        return _profile;
    };

    this.setDrivingTime=function(inDrivingTime){
        _drivingTime=inDrivingTime;
    };

    this.getDrivingTime=function(){
        return _drivingTime;
    };
    	
	this.setRoutingMode=function(routingMode){
		var intVal=parseInt(routingMode);
		if(intVal>=0&&intVal<=2){
			_routingMode=intVal;
		}else{
			throw "Unkown routing mode:" + routingMode + ". The routing mode must be between 0 and 2.";
		}
	};
	
	this.getRoutingMode=function(){
		return _routingMode;
	};
	
	this.setCitySpeed=function(citySpeed){
		var intVal=parseInt(citySpeed);
		if(intVal>0){
			_citySpeed=intVal;
		}else{
			throw "The average driving speed in cities must be greater than 0.";
		}
	};
	
	this.getCitySpeed=function(){
		return _citySpeed;
	};
	
	this.setCountryRoadSpeed=function(countryRoadSpeed){
		var intVal=parseInt(countryRoadSpeed);
		if(intVal>0){
			_countryRoadSpeed=intVal;
		}else{
			throw "The average driving speed on country roads must be greater than 0.";
		}
	};
	
	this.getCountryRoadSpeed=function(){
		return _countryRoadSpeed;
	};
	
	this.setHighwaySpeed=function(highwaySpeed){
		var intVal=parseInt(highwaySpeed);
		if(intVal>0){
			_highwaySpeed=intVal;
		}else{
			throw 'The average driving speed on highways must be greater than 0.';
		}
	};
	
	this.getHighwaySpeed=function(){
		return _highwaySpeed;
	};
	
	this.setLanguage=function(language){
		_language=language;
		var event=new IWLanguageChangedEvent();
		event.language=_language;
		this.afterLanguageChanged(event);
	};

	this.getLanguage=function(){
		return _language;
	}
	
	this.toString=function(){
		return '[MMRouteOptions]' +'Routing mode:' +(_routingMode==0 ? 'shortest route':(_routingMode==1 ? 'fastes route':'most economic'))+ ',' +'Average driving speed in cities:' + _citySpeed + ',' +'Average driving speed on country roads:' + _countryRoadSpeed + ',' +'Average driving speed on highways:' + _highwaySpeed;
	};
	
	this.afterLanguageChanged=function(event){
		IWEventManager.trigger(this,'afterlanguagechanged',event);
	};
}






function MMOverlaySelectionControl(map){
	IWControl.call(this,map);
	var _self=this;
	var _treeview=null;
	var _translations=new Object();
	_translations['de']=new Object();
	_translations['en']=new Object();
	_translations['es']=new Object();
	_translations['fr']=new Object();
	_translations['tr']=new Object();
	_translations['de']['POI_SELECTION']='POI-Auswahl';
	_translations['en']['POI_SELECTION']='POI selection';
	_translations['es']['POI_SELECTION']='Selecci\u00F3n de POI';
	_translations['fr']['POI_SELECTION']='S\u00E9lection de POI';
	_translations['tr']['POI_SELECTION']='POI Se\u00E7enekleri';
	var _lang=map.getOptions().getLanguage();
	if(!_translations[_lang])_lang='en';
		var _divHeader=iw.create('div');
		var _divClose=iw.create('div');
		this.getTreeView=function(){
		return _treeview;
	}

	this.setCloseable=function(closeable){
		if(closeable==true){
			_divClose.style.display='block';
		}else if(closeable==false){
			_divClose.style.display='none';
		}
	};
	
	this.isCloseable=function(){
		return(_divClose.style.display !='none');
	};
	
	function buildGUI(container){
		container.id='IWOverlaySelectionControl';
		container.className='iwoverlayselectioncontrol';
		container.style.left='103px';
		container.style.top='5px';
		container.style.width='220px';
		//container.style.height='294px';
		container.style.backgroundColor='white';
		container.appendChild(_divHeader);
		_divHeader.style.font='bold 12px Arial';
		_divHeader.style.color='#ffffff';
		//_divHeader.style.backgroundColor='#689acd';
		_divHeader.style.padding='4px';
		_divHeader.style.border='1px solid #ffffff';
		iw.append(_divHeader,_translations[_lang]['POI_SELECTION']);
		_divHeader.appendChild(_divClose);
		_divClose.style.display='none';
		_divClose.style.position='absolute';
		_divClose.style.right='4px';
		_divClose.style.top='6px';
		var imgClose=iw.create('img');
		_divClose.appendChild(imgClose);
		imgClose.align='right';
		imgClose.src=iwconst.GLOBAL_APP_URL + 'img/close.png';
		imgClose.style.cursor='pointer';
		
		IWEventManager.addDOMListener(imgClose,'onclick',function(event){
			_self.setVisible(false);
		});
		
		var divBody=iw.create('div');
		container.appendChild(divBody);
		divBody.style.backgroundColor='white';
		divBody.style.overflowX='hidden';
		divBody.style.overflowY='auto';
		//divBody.style.height='265px';
		divBody.style.border='1px solid #ffffff';
		_treeview=new IWTreeView(divBody);
	}
	
	this.setDragButton(IWButton.LEFT);
	this.setDraggableContainer(_divHeader);
	this.allowDraggingOutsideParent(false);
	this.setDraggable(true);
	buildGUI(this.getContainer());
	this.setCloseable(true);
	_treeview.addNodes(map.getLayers());
	_treeview.build();
	
	IWEventManager.addListener(_treeview,'afternodeclicked',function(e){
		map.redraw();
	});
}

function MMToolboxControl(map,tools,inResourceFolder,inSpecialFunction){
	IWControl.call(this,map);
	var _sTools=tools;
	var _map=map;
	var _div=this.getContainer();
	var _xPosition=0;
	var _resourceFolder = inResourceFolder;
	var _specialFunction = inSpecialFunction;
	var _isActive = false;
	
	var _translations=new Object();
	_translations['de']=new Object();
	_translations['en']=new Object();
	_translations['de']['Karte']='Stra\u03B2enkarte';
	_translations['de']['Luftbild']='Luftbild';
	_translations['de']['Hybrid']='Hybrid';
	_translations['de']['Vogelperspektive']='Schr\u00E4gansichten';
	_translations['de']['Vollbild']='Vollbild';
	_translations['de']['POI']='POI-Auswahl';
	_translations['de']['Verkehrsinfo']='Verkehrsinformation';
	_translations['de']['Route']='Route berechnen';
	_translations['de']['Adresse_Suchen']='Adresse suchen';
	_translations['de']['Verschieben']='Karte verschieben';
	_translations['de']['Ausschnitt']='Ausschnitt w\u00E4hlen';
	_translations['de']['Messen']='Entfernung messen';
	_translations['de']['Drucken']='Karte drucken';
	_translations['de']['Speichern']='Route Speichern';
	_translations['de']['DruckenImage']='drucken.png';
	_translations['de']['SpeichernImage']='speichern.png';
	_translations['en']['Karte']='Road map';
	_translations['en']['Luftbild']='Aerial view';
	_translations['en']['Hybrid']='Hybrid view';
	_translations['en']['Vogelperspektive']='Birds\' eye view';
	_translations['en']['Vollbild']='Full screen';
	_translations['en']['POI']='POI selection';
	_translations['en']['Verkehrsinfo']='Traffic Information';
	_translations['en']['Route']='Routing';
	_translations['en']['Adresse_Suchen']='Search address';
	_translations['en']['Verschieben']='Move map';
	_translations['en']['Ausschnitt']='Zoom map';
	_translations['en']['Messen']='Distance measrurement';
	_translations['en']['Drucken']='Print map';
	_translations['en']['Speichern']='Save Route';
	_translations['en']['DruckenImage']='speichern_en.png';
	_translations['en']['SpeichernImage']='speichern_en.png';
	
	var TOOLS=new Array(14);
	TOOLS[0]=new Object();
	TOOLS[0].Name='Karte';
	TOOLS[0].Group=0;
	TOOLS[0].Logo='karte.gif';
	TOOLS[0].Function=function(){
		if(map.getCurrentMapType().getType()!="map")map.setMapType(new IWMapTypeNormal(map));
	};
	TOOLS[1]=new Object();
	TOOLS[1].Name='Luftbild';
	TOOLS[1].Group=0;
	TOOLS[1].Logo='luftbild.gif';
	TOOLS[1].Function=function(){
		if(map.getCurrentMapType().getType()!="air")map.setMapType(new IWMapTypeAir(map));
	};
	TOOLS[2]=new Object();
	TOOLS[2].Name='Hybrid';
	TOOLS[2].Group=0;
	TOOLS[2].Logo='hybrid.gif';
	TOOLS[2].Function=function(){
		if(map.getCurrentMapType().getType()!="hybrid")map.setMapType(new IWMapTypeHybrid(map));
	};
	TOOLS[3]=new Object();
	TOOLS[3].Name='Vogelperspektive';
	TOOLS[3].Group=0;
	TOOLS[3].Logo='birdsview.gif';
	TOOLS[3].Function=function(){
		if(map.getCurrentMapType().getType()!="birds-eye")map.setMapType(new IWMapTypeBirdsView(map));
	};
	TOOLS[4]=new Object();
	TOOLS[4].Name='Vollbild';
	TOOLS[4].Group=-1;
	TOOLS[4].Logo='vollbild.gif';
	TOOLS[4].Function=function(){
	alert("Nicht implementiert:Vollbild");
	};
	TOOLS[5]=new Object();
	TOOLS[5].Name='POI';
	TOOLS[5].Group=-1;
	TOOLS[5].Logo='poi.png';
	TOOLS[5].Function=function(){
		overlaySelectionControl.setVisible(!overlaySelectionControl.isVisible());
	};
	TOOLS[6]=new Object();
	TOOLS[6].Name='Verkehrsinfo';
	TOOLS[6].Group=-1;
	TOOLS[6].Logo='tmc.png';
	TOOLS[6].tmpApplicationCopyright=map.getOptions().getApplicationCopyright();
	TOOLS[6].Info=false;
	TOOLS[6].Function=function(){
		if(map.getCurrentMapType().getType()=="map"||map.getCurrentMapType().getType()=="hybrid"){
			if(TOOLS[6].Info){
				TOOLS[6].Info=false;
			}else{
				TOOLS[6].Info=true;
			}
		}
	};
	TOOLS[7]=new Object();
	TOOLS[7].Name='Route';
	TOOLS[7].Group=-1;
	TOOLS[7].Logo='route.gif';
	TOOLS[7].Function=function(){
		routingMenu.expand();
	};
	TOOLS[8]=new Object();
	TOOLS[8].Name='Adresse_Suchen';
	TOOLS[8].Group=-1;
	TOOLS[8].Logo='adresse_suchen.gif';
	TOOLS[8].Function=function(){
		alert("Nicht implementiert:Adresse suchen");
	};
	TOOLS[9]=new Object();
	TOOLS[9].Name='Verschieben';
	TOOLS[9].Group=1;
	TOOLS[9].Logo='verschieben.gif';
	TOOLS[9].Function=function(){
		measuringTool.stop();
		map.getOptions().setLeftMouseAction(IWMapOptions.CONTROL_MOVE);
	};
	TOOLS[10]=new Object();
	TOOLS[10].Name='Ausschnitt';
	TOOLS[10].Group=1;
	TOOLS[10].Logo='ausschnitt.gif';
	TOOLS[10].Function=function(){
		measuringTool.stop();
		map.getOptions().setLeftMouseAction(IWMapOptions.CONTROL_ZOOM);
	};
	TOOLS[11]=new Object();
	TOOLS[11].Name='Messen';
	TOOLS[11].Group=1;
	TOOLS[11].Logo='messen.png';
	TOOLS[11].Function=function(){
	if(measuringTool.isActive())
		measuringTool.stop();
	else
		measuringTool.start();
	};
	TOOLS[12]=new Object();
	TOOLS[12].Name='Speichern';
	TOOLS[12].Group=-2;
	TOOLS[12].Logo='speichern.png';
	if (_specialFunction != undefined && _specialFunction.SaveRoute != null && _specialFunction.SaveRoute != ''){
		TOOLS[12].Function=_specialFunction.SaveRoute;
	}else{
		TOOLS[12].Function=function(){
			alert('Not implementet!!');
		};
	};		
	TOOLS[13]=new Object();
	TOOLS[13].Name='Drucken';
	TOOLS[13].Group=-2;
	TOOLS[13].Logo='drucken.png';
	if (_specialFunction != undefined && _specialFunction.Drucken != null && _specialFunction.Drucken != ''){
		TOOLS[13].Function=_specialFunction.Drucken;
	}else{
		TOOLS[13].Function=function(){
			oTileset.Print();
		};
	};

	
	var _sLanguage=map.getOptions().getLanguage();
	if(!_translations[_sLanguage])_sLanguage='en';
	
	IWEventManager.addListener(map,'afterlanguagechanged',setLanguage.iwclosure(this));
	
	_div.id='divToolbox';
	IWEventManager.addDOMListener(_div,"onmousedown",function(event){
	if(!event)event=window.event;
		return noPropagation(event);
	});
	_div.style.height='58px';
	//_div.style.opacity='0.85';
	//_div.style.filter='alpha(opacity=85)';
	var aTools=new Array();

	for(var nTool=0;nTool<TOOLS.length;nTool++){
		if(_sTools.indexOf(TOOLS[nTool].Name)>-1){
			var nLeft=-1;
			var nRight=-1;
			for(var nIndex=nTool - 1;nIndex>=0;	nIndex--){
				if(_sTools.indexOf(TOOLS[nIndex].Name)>-1){
					nLeft=nIndex;
					break;
				}
			}

			for(var nIndex=nTool + 1;nIndex<=TOOLS.length - 1;nIndex++){
				if(_sTools.indexOf(TOOLS[nIndex].Name)>-1){
					nRight=nIndex;
					break;
				}
			}

			var sSelectedLeft=null;
			if(nLeft>-1)sSelectedLeft=TOOLS[nLeft + 1].SelectedLeft;
			var sSelectedRight=null;
			if(nRight>-1)sSelectedRight=TOOLS[nRight - 1].SelectedRight;
				var tool=new iwTool(TOOLS[nTool].Name,_translations[_sLanguage][TOOLS[nTool].Name],TOOLS[nTool].Logo,TOOLS[nTool].Group,TOOLS[nTool].Function);
			if(TOOLS[nTool].Name=='Messen')toolboxMeasuringTool=tool;
				aTools.push(tool);
		}
	}

	var imgLeftBorder=document.createElement('img');
	_div.appendChild(imgLeftBorder);
	imgLeftBorder.id='imgToolbarLeft';
	//imgLeftBorder.src=iwconst.GLOBAL_APP_URL + 'img/toolbox/links.gif';
	imgLeftBorder.src=_resourceFolder + 'button_tools_zu.png';
	imgLeftBorder.style.position='absolute';
	imgLeftBorder.style.bottom='0px';
	imgLeftBorder.style.left=_xPosition+'px';
	IWEventManager.addDOMListener(imgLeftBorder,"onclick",function(event){
		this.toggle();
		
	}.iwclosure(this));
			
	_xPosition +=56;

	/*if(TOOLS[6].Info){
		map.getOptions().setApplicationCopyright(TOOLS[6].tmpApplicationCopyright + ',TMCpro');
	}else{
		map.getOptions().setApplicationCopyright(TOOLS[6].tmpApplicationCopyright);
	}*/

	var toolsDiv=document.createElement('div');
	_div.appendChild(toolsDiv);
	toolsDiv.id='toolsDiv';
	toolsDiv.style.display = 'none';
	toolsDiv.style.position = 'absolute';
	toolsDiv.style.left = '56px';
	toolsDiv.style.top = '-4px';
	toolsDiv.style.width = '200px';
			
	for(var nTool=0;nTool<aTools.length;nTool++){
		var tool=aTools[nTool];
		var neighbourLeft=null;
		var neighbourRight=null;
		if(nTool>0)neighbourLeft=aTools[nTool - 1];

		if(nTool<(aTools.length - 1));
			neighbourRight=aTools[nTool + 1];
		tool.setNeighbours(neighbourLeft,neighbourRight);
		//_div.appendChild(tool.imgButton);
		toolsDiv.appendChild(tool.imgButton);
		tool.imgButton.src=tool.sImageNormal;

		if(tool.sName=='Verkehrsinfo'){
			if(TOOLS[6].Info)tool.imgButton.src=tool.sImageActive;
		}

		//tool.imgButton.style.position='absolute';
		//tool.imgButton.style.bottom='0px';
		//tool.imgButton.style.left=_xPosition+'px';
		_xPosition +=23;
		/*if(nTool<aTools.length - 1){
			if(tool.nGroup !=aTools[nTool + 1].nGroup){
				var imgSeparator=document.createElement('img');
				tool.separatorRight=imgSeparator;
				aTools[nTool+1].separatorLeft=imgSeparator;
				_div.appendChild(imgSeparator);
				imgSeparator.src=iwconst.GLOBAL_APP_URL + 'img/toolbox/trennlinie.gif';
				imgSeparator.style.position='absolute';
				imgSeparator.style.bottom='0px';
				imgSeparator.style.left=_xPosition+'px';
				_xPosition++;
			}
		}*/
	}
	
	var imgRightBorder=document.createElement('img');
	toolsDiv.appendChild(imgRightBorder);
	imgRightBorder.id='imgToolbarRight';
	imgRightBorder.src=_resourceFolder +  'rand_re_flaeche.png';
	imgRightBorder.style.width='13px';
	imgRightBorder.style.height='62px';
	//imgRightBorder.style.position='absolute';
	imgRightBorder.style.bottom='0px';
	//imgRightBorder.style.left=_xPosition+'px';
	_xPosition +=23;
	_div.style.width=_xPosition+'px';

	this.toggle = function(){
		if (_isActive){
			imgLeftBorder.src=_resourceFolder + 'button_tools_zu.png';
			_isActive = false;
			document.getElementById('toolsDiv').style.display = 'none';
//			document.getElementById('imgToolbarRight').style.display='none';
		}else{
			imgLeftBorder.src=_resourceFolder + 'button_tools_offen.png';
			_isActive = true;
			document.getElementById('toolsDiv').style.display = 'block';
//			document.getElementById('imgToolbarRight').style.display='block';
		}
	}
	
	function setLanguage(event){
		if(_translations[event.language]){
			_sLanguage=event.language;
			for(var i=0;i<aTools.length;i++){
				var sTitle=_translations[_sLanguage][aTools[i].sName];
				aTools[i].imgButton.alt=aTools[i].imgButton.title=sTitle;
			}
		}
	}
	
	function iwTool(sName,sTitle,sLogo,nGroup,sFunction){
		this.sName=sName;
		this.sLogo=sLogo;
		this.nGroup=nGroup;
		this.sFunction=sFunction;
		this.available=true;
		this.bActive=false;
		this.toolLeft=null;
		this.toolRight=null;
		this.separatorRight=null;
		this.separatorLeft=null;
		var _sLanguage=map.getOptions().getLanguage();
		if(!_translations[_sLanguage])_sLanguage='de';
		/*this.sImageNormal=iwconst.GLOBAL_APP_URL + 'img/toolbox/normal/' + sLogo;
		this.sImageSmall=iwconst.GLOBAL_APP_URL + 'img/toolbox/klein/' + sLogo;
		this.sImageLarge=iwconst.GLOBAL_APP_URL + 'img/toolbox/gross/' + sLogo;
		this.sImageActive=iwconst.GLOBAL_APP_URL + 'img/toolbox/aktiv/' + sLogo;*/
			this.sImageNormal=_resourceFolder + 'poi/normal/' + sLogo;
			this.sImageSmall=_resourceFolder + 'poi/klein/' + sLogo;
			
			 switch (sLogo) {
			    case "drucken.png": ((_sLanguage=='en')? this.sImageLarge=_resourceFolder + 'poi/gross/drucken_en.png':this.sImageLarge=_resourceFolder + 'poi/gross/' + sLogo);
			            break;
			    case "speichern.png": ((_sLanguage=='en')? this.sImageLarge=_resourceFolder + 'poi/gross/speichern_en.png':this.sImageLarge=_resourceFolder + 'poi/gross/' + sLogo);
			            break;
			    case "tmc.png": ((_sLanguage=='en')? this.sImageLarge=_resourceFolder + 'poi/gross/tmc_en.png':this.sImageLarge=_resourceFolder + 'poi/gross/' + sLogo);
			            break;
			    default: this.sImageLarge=_resourceFolder + 'poi/gross/' + sLogo;
			}

			this.sImageActive=_resourceFolder + 'poi/aktiv/' + sLogo;
		
		if(sName=='Vogelperspektive'){
			var mapTypes=map.getOptions().getMapTypes();
			for(var i=0;i<mapTypes.length;i++){
				if(mapTypes[i].getType()=='birds-eye'){
					if(!mapTypes[i].isAvailable()){
						this.available=false;
						//this.sImageNormal=iwconst.GLOBAL_APP_URL + 'img/toolbox/inaktiv/' + sLogo;
						this.sImageNormal=_resourceFolder + 'poi/inaktiv/' + sLogo;
					}
					break;
				}
			}
		}

		this.imgButton=document.createElement('img');
		this.imgButton.id='Button' + sName;
		this.imgButton.name='Button' + sName;
		this.imgButton.border='0';
		this.imgButton.alt=this.imgButton.title=sTitle;
		this.imgButton.style.margin='0px';
		
		if(sName=='Vogelperspektive'){
			IWEventManager.addListener(map,'ontypeavailabilitychange',function(event){
				if(event.type=='birds-eye'){
					if(event.available){
						this.available=true;
						//this.imgButton.src=this.sImageNormal=iwconst.GLOBAL_APP_URL + 'img/toolbox/normal/' + sLogo;
						this.imgButton.src=this.sImageNormal=_resourceFolder + 'poi/normal/' + sLogo;
					}else{
						this.available=false;
						//this.imgButton.src=this.sImageNormal=iwconst.GLOBAL_APP_URL + 'img/toolbox/inaktiv/' + sLogo;
						this.imgButton.src=this.sImageNormal=_resourceFolder + 'poi/inaktiv/' + sLogo;
					}
				}
			}.iwclosure(this));
		}

		IWEventManager.addDOMListener(this.imgButton,"onclick",function(event){
			if(!this.available)return;
			if(!event){
				event=window.event;
			}
			if(this.sName=='POI'){
				this.bActive=!this.bActive;
			}else if(this.sName=='Verkehrsinfo'){
				this.bActive=!this.bActive;
			}
			
			if(this.nGroup>=0){
				this.bActive=true;
				var tool=this.toolLeft;

				while(tool !=null){
					if(tool.nGroup==this.nGroup){
						tool.bActive=false;
						tool.imgButton.src=tool.sImageNormal;
					}
					tool=tool.toolLeft;
				}
			
				tool=this.toolRight;
			
				while(tool !=null){
					if(tool.nGroup==this.nGroup){
						tool.bActive=false;
						tool.imgButton.src=tool.sImageNormal;
					}
					tool=tool.toolRight;
				}
			}
			
			sFunction();
			
			if(map.getCurrentMapType().getType()=="map"||map.getCurrentMapType().getType()=="hybrid"){
				if(TOOLS[6].Info){
					var layerTMC_LINIEN=new IWLayer(map,'TMC_LINIEN','TMC_LINIEN')
					layerTMC_LINIEN.addShape(new IWShape('tmc'));
					var layerTMC_PFEILE=new IWLayer(map,'TMC_PFEILE','TMC_PFEILE')
					layerTMC_PFEILE.addShape(new IWShape('tmc'));
					var layerTMC_SYMBOLE=new IWLayer(map,'TMC_SYMBOLE','TMC_SYMBOLE')
					layerTMC_SYMBOLE.addShape(new IWShape('tmc_p'));

					var requestLayer = new IWRequestLayer(layerTMC_SYMBOLE);
					requestLayer.registerEvent('onclick');
				
					map.getLayerInfoManager().addRequestLayer(requestLayer);
				
					var removeListener = IWEventManager.addListener(layerTMC_SYMBOLE, 'onremove', function(e)
						{
							map.getLayerInfoManager().removeRequestLayer(requestLayer);
							IWEventManager.removeListener(requestListener);
							IWEventManager.removeListener(removeListener);
						}
					);	
					
					map.addLayer(layerTMC_LINIEN);
					map.addLayer(layerTMC_PFEILE);
					map.addLayer(layerTMC_SYMBOLE);
					if (this.sName=='Verkehrsinfo'){
						//map.getOptions().setApplicationCopyright(TOOLS[6].tmpApplicationCopyright + ',&nbsp;TMCpro');
						//aTools[5].bActive=true;
						theCopyright = $('#IWCopyrightControl > div > span').html() + ',&nbsp;TMCpro';
				   		var theCopyrightOldValue = $('#IWCopyrightControl').css('left').replace('px', '');
				   		theCopyrightNewValue = (parseInt(theCopyrightOldValue) - 50);
						$('#IWCopyrightControl').css('left',theCopyrightNewValue + 'px');
	
				   		var theCopyrightOldValue = $('#IWCopyrightControl').css('width').replace('px', '');
				   		theCopyrightNewValue = (parseInt(theCopyrightOldValue) + 50);
						$('#IWCopyrightControl').css('width',theCopyrightNewValue+'px');
						$('#IWCopyrightControl > div > span').html(theCopyright);
					}
				}else{
					map.removeLayerByName('TMC_LINIEN');
					map.removeLayerByName('TMC_PFEILE');
					map.removeLayerByName('TMC_SYMBOLE');
					
					if (this.sName=='Verkehrsinfo'){
						theCopyright = $('#IWCopyrightControl > div > span').html();
						theCopyright = theCopyright.substr(0,theCopyright.lastIndexOf(','));
					
				   		var theCopyrightOldValue = $('#IWCopyrightControl').css('left').replace('px', '');
				   		theCopyrightNewValue = (parseInt(theCopyrightOldValue) + 50);
						$('#IWCopyrightControl').css('left',theCopyrightNewValue + 'px');
	
				   		var theCopyrightOldValue = $('#IWCopyrightControl').css('width').replace('px', '');
				   		theCopyrightNewValue = (parseInt(theCopyrightOldValue) - 50);
						$('#IWCopyrightControl').css('width',theCopyrightNewValue+'px');
						
						$('#IWCopyrightControl > div > span').html(theCopyright);
					}
					//map.getOptions().setApplicationCopyright(TOOLS[6].tmpApplicationCopyright);
					//aTools[5].bActive=false;
				}

				if(this.sName=="Verkehrsinfo"){
					map.redraw();
				}
			}else{
				map.removeLayerByName('TMC_LINIEN');
				map.removeLayerByName('TMC_PFEILE');
				map.removeLayerByName('TMC_SYMBOLE');
				//map.getOptions().setApplicationCopyright(TOOLS[6].tmpApplicationCopyright);
			}
			
			return noPropagation(event);
		}.iwclosure(this));
	
		IWEventManager.addDOMListener(this.imgButton,"onmouseover",function(event){
			if(!this.available)return;
			if(!event){
				event=window.event;
			}
			
			noPropagation(event);
			this.imgButton.src=this.sImageLarge;
			this.imgButton.style.width="46px";
			this.imgButton.style.height="62px";
			//this.imgButton.style.bottom="0px";
			//this.imgButton.style.zIndex="100";
			//this.imgButton.style.left=(parseInt(this.imgButton.style.left)-1)+"px";
			if(this.separatorRight !=null)this.separatorRight.style.left=parseInt(this.separatorRight.style.left)+23+'px';
			else if(this.separatorLeft !=null)this.separatorLeft.style.left=parseInt(this.separatorLeft.style.left)-23+'px';
			
			if(this.toolLeft !=null){
				this.toolLeft.imgButton.src=this.toolLeft.sImageSmall;
				this.toolLeft.imgButton.style.width="23px";
				this.toolLeft.imgButton.style.height="62px";
			}else{
				var imgToolbarLeft=document.getElementById('imgToolbarLeft');
				//imgToolbarLeft.src=iwconst.GLOBAL_APP_URL + 'img/toolbox/links_schmal.gif';
				imgToolbarLeft.src=_resourceFolder + 'button_tools_offen.png';
				
				imgToolbarLeft.style.width="56px";
				imgToolbarLeft.style.height="62px";
			}

			if(this.toolRight !=null){
				this.toolRight.imgButton.src=this.toolRight.sImageSmall;
				this.toolRight.imgButton.style.width="23px";
				this.toolRight.imgButton.style.height="62px";
				//this.toolRight.imgButton.style.left=parseInt(this.toolRight.imgButton.style.left)+23+"px";
			}else{
				var imgToolbarRight=document.getElementById('imgToolbarRight');
				imgToolbarRight.src=_resourceFolder +   'rand_re_flaeche.png';
				imgToolbarRight.style.width="13px";
				imgToolbarRight.style.height="62px";
				//imgToolbarRight.style.left=parseInt(imgToolbarRight.style.left)+4+"px";
			}
		}.iwclosure(this));
	
		IWEventManager.addDOMListener(this.imgButton,"onmouseout",function(event){
			if(!this.available)return;
			if(!event){
				event=window.event;
			}
			noPropagation(event);
			
			this.imgButton.style.width='23px';
			this.imgButton.style.height='62px';
			//this.imgButton.style.bottom='0px';
			//this.imgButton.style.zIndex="0";
			if(this.bActive)this.imgButton.src=this.sImageActive;
			else
			this.imgButton.src=this.sImageNormal;
			
			//this.imgButton.style.left=parseInt(this.imgButton.style.left)+4+"px";
			
			/*if(this.separatorRight !=null)this.separatorRight.style.left=parseInt(this.separatorRight.style.left)-23+'px';
			else if(this.separatorLeft !=null)this.separatorLeft.style.left=parseInt(this.separatorLeft.style.left)+23+'px';*/
			
			if(this.toolLeft !=null){
				if(this.toolLeft.bActive){
					this.toolLeft.imgButton.src=this.toolLeft.sImageActive;
					this.toolLeft.imgButton.style.width="23px";
					this.toolLeft.imgButton.style.height="62px";
				}else{
					this.toolLeft.imgButton.src=this.toolLeft.sImageNormal;
					this.toolLeft.imgButton.style.width="23px";
					this.toolLeft.imgButton.style.height="62px";
				}
			}else{
				var imgToolbarLeft=document.getElementById('imgToolbarLeft');
				//imgToolbarLeft.src=iwconst.GLOBAL_APP_URL + 'img/toolbox/links.gif';
				imgToolbarLeft.src=_resourceFolder + 'button_tools_offen.png';
				imgToolbarLeft.style.width="56px";
				imgToolbarLeft.style.height="62px";
			}
			
			if(this.toolRight !=null){
				if(this.toolRight.bActive){
					this.toolRight.imgButton.src=this.toolRight.sImageActive;
					this.toolRight.imgButton.style.width="23px";
					this.toolRight.imgButton.style.height="62px";
				}else{
					this.toolRight.imgButton.src=this.toolRight.sImageNormal;
					this.toolRight.imgButton.style.width="23px";
					this.toolRight.imgButton.style.height="62px";
				}
			
				//this.toolRight.imgButton.style.left=parseInt(this.toolRight.imgButton.style.left)-23+"px";
			}else{
				var imgToolbarRight=document.getElementById('imgToolbarRight');
				imgToolbarRight.src=_resourceFolder +  'rand_re_flaeche.png';
				imgToolbarRight.style.width="13px";
				imgToolbarRight.style.height="62px";
				//imgToolbarRight.style.left=parseInt(imgToolbarRight.style.left)-4+"px";
			}
		}.iwclosure(this));

		this.setNeighbours=function(toolLeft,toolRight){
			this.toolLeft=toolLeft;
			this.toolRight=toolRight;
		};
	}
	
	this.toString=function(){
		return 'IWToolboxControl(' + _sTools + ')';
	};
}









function MMNavigationControl(map, inResourceFolder){
	IWControl.call(this,map);
	var _resourceFolder = inResourceFolder;
	var _map=map;
	var _container=this.getContainer();
	var _self=this;
	var _areaUp=iw.create('area');
	var _areaRight=iw.create('area');
	var _areaDown=iw.create('area');
	var _areaLeft=iw.create('area');
	var _t=new Object();
	_t['de']=new Object();
	_t['en']=new Object();
	_t['es']=new Object();
	_t['tr']=new Object();
	_t['de']['UP']='Karte nach oben verschieben';
	_t['de']['RIGHT']='Karte nach rechts verschieben';
	_t['de']['DOWN']='Karte nach unten verschieben';
	_t['de']['LEFT']='Karte nach links verschieben';
	_t['de']['NAV']='navikreuz.png';
	_t['de']['NAV_N']='navikreuz_rollover_n.png';
	_t['de']['NAV_S']='navikreuz_rollover_s.png';
	_t['de']['NAV_W']='navikreuz_rollover_w.png';
	_t['de']['NAV_E']='navikreuz_rollover_o.png';
	_t['en']['UP']='Move map up';
	_t['en']['RIGHT']='Move map right';
	_t['en']['DOWN']='Move map down';
	_t['en']['LEFT']='Move map left';
	_t['en']['NAV']='navikreuz_en.png';
	_t['en']['NAV_N']='navikreuz_rollover_n_en.png';
	_t['en']['NAV_S']='navikreuz_rollover_s_en.png';
	_t['en']['NAV_W']='navikreuz_rollover_w_en.png';
	_t['en']['NAV_E']='navikreuz_rollover_o_en.png';
	_t['es']['UP']='Desplazar el mapa hacia arriba';
	_t['es']['RIGHT']='Desplazar el mapa hacia la derecha';
	_t['es']['DOWN']='Desplazar el mapa hacia abajo';
	_t['es']['LEFT']='Desplazar el mapa hacia la izquierda';
	_t['tr']['UP']='Haritayi yukari kaydir';
	_t['tr']['RIGHT']='Haritayi saga kaydir';
	_t['tr']['DOWN']='Haritayi asagi kaydir';
	_t['tr']['LEFT']='Haritayi sola kaydir';
	
	var _sLanguage=map.getOptions().getLanguage();
	if(!_t[_sLanguage])_sLanguage='de';

	this.toString=function(){
		return 'IWNavigationControl';
	};

	function buildGUI(){
	
		_container.id='divNavigationControl';
		_container.style.width='62px';
		_container.style.height='62px';
		//_container.style.marginLeft='308px';
		var imgNaviCross=iw.create('img');
		iw.append(_container,imgNaviCross);
		
		imgNaviCross.onload=function(){
			correctPNG(this);
		}.iwclosure(imgNaviCross);

		imgNaviCross.src=_resourceFolder + _t[_sLanguage]['NAV'];
		imgNaviCross.width='62';
		imgNaviCross.height='62';
		imgNaviCross.border='0';
		imgNaviCross.useMap='#mapNaviCross';
		
		var mapNaviCross=iw.create('map');
		iw.append(_container,mapNaviCross);
		mapNaviCross.id='mapNaviCross';
		mapNaviCross.name='mapNaviCross';
		
		_areaUp.shape='rect';
		_areaUp.coords='18,4,38,18';
		_areaUp.alt=_t[_sLanguage]['UP'];
		_areaUp.title=_t[_sLanguage]['UP'];
		
		IWEventManager.addDOMListener(_areaUp,'onmousedown',function(event){
			var offset=new IWPoint(0,Math.floor(this.getOptions().getSize().getHeight()/2));
			this.panBy(offset);
		}.iwclosure(_map));

		IWEventManager.addDOMListener(_areaUp,'onmouseover',function(e){
			this.style.cursor='pointer';
			imgNaviCross.src=_resourceFolder + _t[_sLanguage]['NAV_N'];
		}.iwclosure(_areaUp));

		IWEventManager.addDOMListener(_areaUp,'onmouseout',function(e){
			imgNaviCross.src=_resourceFolder + _t[_sLanguage]['NAV'];
		}.iwclosure(_map));
		
		iw.append(mapNaviCross,_areaUp);	

		iw.append(mapNaviCross,_areaLeft);
		_areaLeft.shape='rect';
		_areaLeft.coords='4,18,18,38';
		_areaLeft.alt=_t[_sLanguage]['LEFT'];
		_areaLeft.title=_t[_sLanguage]['LEFT'];
		
		IWEventManager.addDOMListener(_areaLeft,'onmousedown',function(event){
			var offset=new IWPoint(Math.floor(this.getOptions().getSize().getWidth()/2),0);
			this.panBy(offset);
			}.iwclosure(_map)
		);
	
		IWEventManager.addDOMListener(_areaLeft,'onmouseover',function(e){
			this.style.cursor='pointer';
			imgNaviCross.src=_resourceFolder + _t[_sLanguage]['NAV_W'];
		}.iwclosure(_areaLeft));

		IWEventManager.addDOMListener(_areaLeft,'onmouseout',function(e){
			imgNaviCross.src=_resourceFolder + _t[_sLanguage]['NAV'];
		}.iwclosure(_map));
			
			
		iw.append(mapNaviCross,_areaRight);
		_areaRight.shape='rect';
		_areaRight.coords='38,18,50,38';
		_areaRight.alt=_t[_sLanguage]['RIGHT'];
		_areaRight.title=_t[_sLanguage]['RIGHT'];
		
		IWEventManager.addDOMListener(_areaRight,'onmousedown',function(event){
			var offset=new IWPoint(-Math.floor(this.getOptions().getSize().getWidth()/2),0);
			this.panBy(offset);
		}.iwclosure(_map));
		
		IWEventManager.addDOMListener(_areaRight,'onmouseover',function(e){
			this.style.cursor='pointer';
			imgNaviCross.src=_resourceFolder + _t[_sLanguage]['NAV_E'];
		}.iwclosure(_areaRight));

		IWEventManager.addDOMListener(_areaRight,'onmouseout',function(e){
			imgNaviCross.src=_resourceFolder + _t[_sLanguage]['NAV'];
		}.iwclosure(_map));		
		
		
		iw.append(mapNaviCross,_areaDown);
		_areaDown.shape='rect';
		_areaDown.coords='18,38,38,50';
		_areaDown.alt=_t[_sLanguage]['DOWN'];
		_areaDown.title=_t[_sLanguage]['DOWN'];
		
		IWEventManager.addDOMListener(_areaDown,'onmousedown',function(event){
			var offset=new IWPoint(0,-Math.floor(this.getOptions().getSize().getHeight()/2));
			this.panBy(offset);
		}.iwclosure(_map));
		
		IWEventManager.addDOMListener(_areaDown,'onmouseover',function(e){
			this.style.cursor='pointer';
			imgNaviCross.src=_resourceFolder + _t[_sLanguage]['NAV_S'];
		}.iwclosure(_areaDown));

		IWEventManager.addDOMListener(_areaDown,'onmouseout',function(e){
			imgNaviCross.src=_resourceFolder + _t[_sLanguage]['NAV'];
		}.iwclosure(_map));		
		
		IWEventManager.addListener(_map.getOptions(),'afterlanguagechanged',setLanguage);
	}
	
	function setLanguage(event){
		if(_t[event.language]){
			_sLanguage=event.language;
			_areaUp.alt=_areaUp.title=_t[_sLanguage]['UP'];
			_areaLeft.alt=_areaLeft.title=_t[_sLanguage]['LEFT'];
			_areaRight.alt=_areaRight.title=_t[_sLanguage]['RIGHT'];
			_areaDown.alt=_areaDown.title=_t[_sLanguage]['DOWN'];
		}
	}

	buildGUI();
}


function MMScalarControl(map, inResourceFolder){
	IWControl.call(this,map);
	var _resourceFolder = inResourceFolder;
	var _map=map;
	var _container=this.getContainer();
	var _left=5;
	var _width=0;
	var _scaleUnits=[20,50,100,200,500,1000,2000,5000,10000,20000,50000,100000,200000,500000,1000000,2000000,5000000];
	var _scaleUnitsText=['20 m','50 m','100 m','200 m','500 m','1 km','2 km','5 km','10 km','20 km','50 km','100 km','200 km','500 km','1000 km','2000 km','5000 km'];
	
	this.afterAppend=function(){
		redraw();
	};
	
	function buildGUI(container){
		container.id='IWScalarControl';
		with(container.style){
			width='120px';
			height='25px';
			//marginLeft='308px';
		}

		var divBackground=iw.create('div');
		iw.append(container,divBackground);
		iw.backgroundImage(divBackground,iwconst.GLOBAL_APP_URL + 'img/background_white_transparency.png');
	
		with(divBackground.style){
			position='absolute';
			top='0px';
			left='0px';
			width='120px';
			height='25px';
			zIndex='3';
			//border='1px solid #dddddd';
		}
	
		var divForeground=iw.create('div');
		iw.append(container,divForeground);
	
		with(divForeground.style){
			position='absolute';
			textAlign='center';
			top='0px';
			left='0px';
			zIndex='3';
		}
	
		var divText=iw.create('div');
		iw.append(_container.lastChild,divText);
	
		with(divText.style){
			fontSize='9px';
			textAlign='center';
			width=divText.parentNode.style.width;
		}
	
		iw.append(_container.lastChild,createSeperator());
		iw.append(_container.lastChild,createBlueBox());
		iw.append(_container.lastChild,createSeperator());
		iw.append(_container.lastChild,createWhiteBox());
		iw.append(_container.lastChild,createSeperator());
		iw.append(_container.lastChild,createBlueBox());
		iw.append(_container.lastChild,createSeperator());
		iw.append(_container.lastChild,createWhiteBox());
		iw.append(_container.lastChild,createSeperator());
	}

	function createSeperator(){
		var div=iw.create('div');
		iw.append(_container.lastChild,div);
		with(div.style){
			position='absolute';
			//borderBottom='1px solid #000';
			width='1px';
			height='8px';
			top='15px';
		}
		iw.backgroundImage(div,_resourceFolder + 'massstab_splitter.gif');
		return div;
	}
	
	function createBlueBox(){
		var div=createBox();
		iw.backgroundImage(div,_resourceFolder + 'massstab_filled.gif');
		return div;
	}
	
	function createWhiteBox(){
		var div=createBox();
		iw.backgroundImage(div,iwconst.GLOBAL_APP_URL + '/img/background_white.jpg');
		return div;
	}
	
	function createBox(){
		var div=iw.create('div');
		with(div.style){
			position='absolute';
			//borderBottom='1px solid #000';
			height='5px';
			top='18px';
		}
		return div;
	}
	
	function redraw(){
		var meter=Math.round(map.getMapWidthInMeter()/8);
		var i=0;
		
		while(meter>_scaleUnits[i]&&i<_scaleUnits.length){
			i++;
		}

		var left=5;
		var width=Math.round(_scaleUnits[i]*map.getOptions().getSize().getWidth()/map.getMapWidthInMeter()/4)- 5;
		_container.style.width=_container.firstChild.style.width=_container.lastChild.style.width=(4*width + 15)+ 'px';
		var nodes=_container.lastChild.childNodes;
		nodes[0].innerHTML=_scaleUnitsText[i];
		nodes[1].style.left=left + 'px';
		left=left + 1;
		nodes[2].style.left=left + 'px';
		nodes[2].style.width=width + 'px';
		left=left + width;
		nodes[3].style.left=left + 'px';
		left=left + 1;
		nodes[4].style.left=left + 'px';
		nodes[4].style.width=width + 'px';
		left=left + width;
		nodes[5].style.left=left + 'px';
		left=left + 1;
		nodes[6].style.left=left + 'px';
		nodes[6].style.width=width + 'px';
		left=left + width;
		nodes[7].style.left=left + 'px';
		left=left + 1;
		nodes[8].style.left=left + 'px';
		nodes[8].style.width=width + 'px';
		left=left + width;
		nodes[9].style.left=left + 'px';
	}
	
	this.setPrintable(true);
	
	buildGUI(_container);
	
	IWEventManager.addListener(map,'afterzoom',function(event){
		redraw();
	});
}



function MMSliderControl(map, inResourceFolder){
	IWControl.call(this,map);
	var _resourceFolder = inResourceFolder;
	var _map=map;
	var _self=this;
	var _tilesizeArray=iwconst.A_TILESIZE_METER;
	var _lowValue=_map.getCurrentMapType().getMaxLevel();
	var _highValue=_map.getCurrentMapType().getMinLevel();
	var _offsetX=24;
	var _offsetY=23;
	var _maxSlide=114 - _offsetY;
	var _currentPos=_map.getZoom();
	var _zoomFinished=true;
	var _mouseAdapter=new IWMouseAdapter();
	var _container=this.getContainer();
	var _divSliderButton=iw.create('div');

	this.getValue=function(round){
		if(typeof(round)=="undefined"){
			round=true;
		}
	
		var value=_lowValue +(_highValue-_lowValue)*(parseInt(_divSliderButton.style.top)-_offsetY)/_maxSlide;
		if(round){
			return Math.round(value);
		}else{
			return value;
		}
	};
	
	this.setValue=function(value,ignore){
		if(typeof(ignore)=="undefined")ignore=false;
		if(typeof(value)=="string")value=parseInt(value);
		var rangeValue=Math.min(Math.max(value,_lowValue),_highValue)- _lowValue;
		_divSliderButton.style.top=_maxSlide*rangeValue/(_highValue-_lowValue)+ _offsetY + 'px';
		_currentPos=value;

		if(!ignore){
			_zoomFinished=false;
			_map.setZoom(value);
		}
	};
	
	function _fromSteptoPixel(step){
		return parseInt(_maxSlide/_highValue)*step + _offsetY;
	}
	
	function buildGUI(){

		_container.id='MMSliderControl';
		_container.style.width='62px';
		_container.style.height='158px';
		//_container.style.marginLeft='308px';
		var mapSlider=null;
		try{
			mapSlider=iw.create('<map name="mapSlider">');

		}catch(e){
			mapSlider=iw.create('map');
			mapSlider.name='mapSlider';

		}	
		
		var imgSliderButton=iw.create('img');
		imgSliderButton.src=_resourceFolder + 'transp_horizontal.png';
		imgSliderButton.style.position = 'absolute';
		imgSliderButton.style.top = '158px';
		imgSliderButton.style.left = '0px';
	
		/* Slider */
		var imgSlider=iw.create('img');
		iw.append(_container,mapSlider);
		var areaPlus=iw.create('area');
		iw.append(mapSlider,areaPlus);
		areaPlus.shape='rect';
		areaPlus.coords='8,1,45,20';
		areaPlus.alt='Vergr\u00F6\u00DFern';
		
				
		IWEventManager.addDOMListener(areaPlus,'onmouseover',function(e){
			this.style.cursor='pointer';
			imgSlider.src=_resourceFolder + 'sliderber_rollover_plus.png';
		}.iwclosure(areaPlus));

		IWEventManager.addDOMListener(areaPlus,'onmouseout',function(e){
			imgSlider.src=_resourceFolder + 'sliderbereich.png';
		}.iwclosure(_self));
	
		IWEventManager.addDOMListener(areaPlus,'onmousedown',function(event){
			if(_zoomFinished&&(_map.getCurrentMapType().getMaxLevel()<_currentPos)){
				_zoomFinished=false;
				_currentPos--;
				this.setValue(_currentPos,true);
				_map.zoomIn();
			}
		}.iwclosure(_self));
		
		var areaMinus=iw.create('area');
		iw.append(mapSlider,areaMinus);
		areaMinus.shape='rect';
		areaMinus.coords='8,140,45,158';
		areaMinus.alt='Verkleinern';
		
		IWEventManager.addDOMListener(areaMinus,'onmouseover',function(e){
			this.style.cursor='pointer';
			imgSlider.src=_resourceFolder + 'sliderber_rollover_minus.png';
			
		}.iwclosure(areaMinus));
	
		IWEventManager.addDOMListener(areaMinus,'onmouseout',function(e){
			imgSlider.src=_resourceFolder + 'sliderbereich.png';
		}.iwclosure(_self));
			
		IWEventManager.addDOMListener(areaMinus,'onmousedown',function(event){
			if(_zoomFinished&&(_map.getCurrentMapType().getMinLevel()>_currentPos)){
				_zoomFinished=false;
				_currentPos++;
				this.setValue(_currentPos,true);
				_map.zoomOut();
			}
		}.iwclosure(_self));
		
		var areaPanel=iw.create('area');
		iw.append(mapSlider,areaPanel);
		areaPanel.shape='rect';
		areaPanel.coords='20,21,35,138';
		IWEventManager.addDOMListener(areaPanel,'onmousedown',function(event){
			if(!_zoomFinished)return;
			if(!event)event=window.event;
			
			var _mouseAdapter=new IWMouseAdapter();
			var mouseEvent=_mouseAdapter.toMouseEvent(event,_container);
			var y=mouseEvent.position.getY()- 20;
			
			if(y>=0&&y<=135){
				_zoomFinished=false;
				var idx=Math.min(Math.round((y/135)*_highValue),_highValue);
				_map.setZoom(idx);
			}
		}.iwclosure(_self));
		
		
		iw.append(_container,imgSlider);
		iw.append(_container,imgSliderButton);	
		imgSlider.useMap='#mapSlider';
		
		imgSlider.onload=function(){
			correctPNG(this);
		}.iwclosure(imgSlider);
		
		imgSlider.src=_resourceFolder + 'sliderbereich.png';
		
		imgSlider.width='62';
		imgSlider.height='158';
		imgSlider.border='0';
		iw.append(_container,_divSliderButton);
		
		_divSliderButton.style.position='absolute';
		_divSliderButton.style.left=_offsetX + 'px';
		_divSliderButton.style.top=_offsetY + 'px';
		_divSliderButton.style.width='14px';
		_divSliderButton.style.height='24px';
		
		IWEventManager.addDOMListener(_divSliderButton,'onmouseover',function(e){
			this.style.cursor='pointer';
		}.iwclosure(_divSliderButton));
		
	IWEventManager.addDOMListener(_divSliderButton,'onmousedown',function(event){
		if(!event){
			event=window.event;
		}
		
		if(event.cancelable){
			event.preventDefault();
		}
		
		event.cancelBubble=false;
		event.returnValue=false;
		var mouseEvent=_mouseAdapter.toMouseEvent(event,_container);
		if((mouseEvent.button !=IWButton.LEFT)||!_zoomFinished||!map.startOpticalZoom())return;
		
		limitHigh=_offsetY;
		limitLow=_maxSlide+_offsetY;
		var oldPosY=mouseEvent.position.getY();
		var onMouseMoveListener=IWEventManager.addListener(document.body,'onmousemove',function(event){
		if(!event)event=window.event;
		
		var mouseEvent=_mouseAdapter.toMouseEvent(event,_container);
		var mouseY=mouseEvent.position.getY();
		
		if(event.cancelable)event.preventDefault();
		
		event.cancelBubble=false;
		event.returnValue=false;
		var y=parseInt(_divSliderButton.style.top)+ mouseY - oldPosY;
		
		if((limitHigh<y)&&(y<limitLow)){
			_divSliderButton.style.top=y +'px';
			oldPosY=mouseY;
			var alpha=this.getValue(false)- this.getValue()+1;
			var meter;

			if(this.getValue()==_lowValue)
				meter=alpha*_tilesizeArray[this.getValue()];
			else
				meter=alpha*_tilesizeArray[this.getValue()]+(1-alpha)*_tilesizeArray[this.getValue()-1];
				
			_map.setOpticalZoomStep(meter);
		}
	}.iwclosure(this));
	
	var onMouseUpListener=IWEventManager.addListener(document.body,'onmouseup',function(event){
		_currentPos=this.getValue();
		_map.endOpticalZoom(_currentPos);
		IWEventManager.removeListener(onMouseMoveListener);
			IWEventManager.removeListener(onMouseUpListener);
			}.iwclosure(this));
		}.iwclosure(_self));
		
		var imgButton=iw.create('img');
		iw.append(_divSliderButton,imgButton);
		imgButton.src=_resourceFolder + 'slider.png';
		imgButton.style.width='14px';
		imgButton.style.height='24px';
	}

	buildGUI();

	this.setValue(_map.getZoom(),true);

	IWEventManager.addListener(_map,'onmousewheel',function(event){
		if(!_zoomFinished)return;
		_currentPos=Math.min(Math.max(_currentPos - event.delta,_map.getCurrentMapType().getMaxLevel()),_map.getCurrentMapType().getMinLevel());
		this.setValue(_currentPos,true);
	}.iwclosure(this));

	IWEventManager.addListener(_map,'afterzoom',function(event){
		this.setValue(_map.getZoom(),true);
		_zoomFinished=true;
	}.iwclosure(this));
	
	IWEventManager.addListener(_map,'aftercentered',function(event){
		this.setValue(_map.getZoom(),true);
		_zoomFinished=true;
	}.iwclosure(this));

	IWEventManager.addListener(_map,'aftermaptypechanged',function(event){
		_currentPos=_map.getZoom();
		_lowValue=_map.getCurrentMapType().getMaxLevel();
		_highValue=_map.getCurrentMapType().getMinLevel();
		this.setValue(_currentPos,true);
	}.iwclosure(this));
}



function MMInfoBalloon(map,coordinate,content,inResourcePath, size){
	var _map=map;
	var _content=content;
	var _coordinate=coordinate;
	var _size= (size == null) ? new IWSize(251,285) : size;
	var _border=5;
	var _self=this;
	var _divMain=iw.create('div');
	var _divContent=iw.create('div');
	var _divTopBorder=iw.create('div');
	var _divRightBorder=iw.create('div');
	var _divBottomBorder=iw.create('div');
	var _divLeftBorder=iw.create('div');
	var _imgArrow=iw.create('img');
	var _imgClose=iw.create('img');
	var _resourcePath = inResourcePath;
	var hasCloseAppendFunction = false;
	var closeAppendFunction = null;
	
	IWWindowOverlay.call(this,map,coordinate);
		this.getContent=function(){
		return _content;
	};

		
	this.setContent=function(content){
		_content=content;
	};
	
	this.afterAppend=function(){
		_container.style.visibility='visible';
		var position=iw.absolute(_container,_map.getContainer());
		var offsetRight=position.getX()+ _size.getWidth()+ _border - _map.getOptions().getSize().getWidth();
		var offsetLeft=position.getX()- _border;
		var offsetTop=position.getY()- _border;
		var offsetBottom=position.getY()+ _size.getHeight()+ _border - _map.getOptions().getSize().getHeight();
		if(offsetRight>0||offsetLeft<0||offsetTop<0||offsetBottom>0){
			var x=0;
			var y=0;
			
			if(offsetRight>0){
				x=-offsetRight;
			}else if(offsetLeft<0){
				x=-offsetLeft;
			}
	
			if(offsetTop<0){
				y=-offsetTop;
			}else if(offsetBottom>0){
				y=-offsetBottom;
			}
	
			_map.panBy(new IWPoint(x,y),true);
		}
	};
		
	this.setSize=function(size){
		iw.strict([IWSize],[size]);
		_size=size;
		resize();
		this.setAnchor(new IWPoint(-(_size.getWidth()/2),-(_size.getHeight())));
	};
	
	this.getSize=function(){
		return _size;
	};
	
	this.destroy=function(){
		IWEventManager.clearInstanceListeners(this);
		IWEventManager.clearInstanceListeners(_imgClose);
		this.destroyWindowOverlay();
		_divMain=null;
		_divContent=null;
		_divTopBorder=null;
		_divRightBorder=null;
		_divBottomBorder=null;
		_divLeftBorder=null;
		_imgArrow=null;
		_imgClose=null;
		_container=null;
		_content=null;
	};

	this.toString=function(){
		return '[IWInfoBalloon]';
	};
	
	function buildGUI(){
		_container.style.height=_size.getHeight()+ 'px';
		_container.style.width=_size.getWidth()+ 'px';
		_container.style.visibility='hidden';
		iw.append(_container,_divMain);
		_divMain.style.position='absolute';
		_divMain.style.top='0px';
		_divMain.style.left='0px';
		_divMain.style.width=_size.getWidth() + 'px';
		_divMain.style.height=_size.getHeight()- 51 + 'px';

		var imgTopLeft=iw.create('img');
		iw.append(_divMain,imgTopLeft);
		imgTopLeft.src=iwconst.GLOBAL_APP_URL + 'img/infoballoon/etl2.gif';

		with(imgTopLeft.style){
			position='absolute';
			top='0px';
			left='0px';
			height='21px';
			width='21px';
		}

		var imgTopRight=iw.create('img');
			iw.append(_divMain,imgTopRight);
			imgTopRight.src=iwconst.GLOBAL_APP_URL + 'img/infoballoon/etr2.gif';
			with(imgTopRight.style){
			position='absolute';
			top='0px';
			right='0px';
			height='21px';
			width='21px';
		}
	
		var imgBottomLeft=iw.create('img');
		iw.append(_divMain,imgBottomLeft);
		imgBottomLeft.src=iwconst.GLOBAL_APP_URL + 'img/infoballoon/ebl2.gif';
	
		with(imgBottomLeft.style){
			position='absolute';
			bottom='0px';
			left='0px';
			height='21px';
			width='21px';
		}
	
		var imgBottomRight=iw.create('img');
		iw.append(_divMain,imgBottomRight);
		imgBottomRight.src=iwconst.GLOBAL_APP_URL + 'img/infoballoon/ebr2.gif';
	
		with(imgBottomRight.style){
			position='absolute';
			bottom='0px';
			right='0px';
			height='21px';
			width='21px';
		}
	
		iw.append(_divMain,_divTopBorder);
		iw.backgroundImage(_divTopBorder,iwconst.GLOBAL_APP_URL + '/img/background_white.jpg');
	
		with(_divTopBorder.style){
			position='absolute';
			borderTop='1px solid #cfcfd1';
			top='0px';
			left='21px';
			height='21px';
			width=_size.getWidth()- 42 + 'px';
		}
	
		iw.append(_divMain,_divRightBorder);
		iw.backgroundImage(_divRightBorder,iwconst.GLOBAL_APP_URL + '/img/background_white.jpg');
		with(_divRightBorder.style){
			position='absolute';
			borderRight='1px solid #cfcfd1';
			top='21px';
			right='0px';
			width='21px';
			height=_size.getHeight()- 51 - 42 + 'px';
		}
	
		iw.append(_divMain,_divBottomBorder);
		iw.backgroundImage(_divBottomBorder,iwconst.GLOBAL_APP_URL + '/img/background_white.jpg');
	
		with(_divBottomBorder.style){
			position='absolute';
			borderBottom='1px solid #cfcfd1';
			bottom='0px';
			left='21px';
			height='21px';
			width=_size.getWidth()- 42 + 'px';
		}
	
		iw.append(_divMain,_divLeftBorder);
		iw.backgroundImage(_divLeftBorder,iwconst.GLOBAL_APP_URL + '/img/background_white.jpg');
	
		with(_divLeftBorder.style){
			borderLeft='1px solid #cfcfd1';
			position='absolute';
			top='21px';
			left='0px';
			width='21px';
			height=_size.getHeight()- 51 - 42 + 'px';
		}
	
		iw.append(_divMain,_divContent);
		iw.backgroundImage(_divContent,iwconst.GLOBAL_APP_URL + '/img/background_white.jpg');
		with(_divContent.style){
			position='absolute';
			top='2px';
			left='5px';
			width=_size.getWidth()- 10 + 'px';
			height=_size.getHeight()- 53 - 5 + 'px';
			overflow='hidden';
		}
	
		
		var div=iw.create('div');
		div.style.position='absolute';
		iw.append(_divContent,div);
		iw.append(div,_content);
		iw.append(_divMain,_imgClose);
		_imgClose.src=_resourcePath + 'close_klein.gif';
		
		with(_imgClose.style){
			position='absolute';
			top='8px';
			right='16px';
			cursor='pointer';
			width='11px';
			height='10px';
			zIndex='100';
		}
	
		iw.append(_container,_imgArrow);
		_imgArrow.src=iwconst.GLOBAL_APP_URL + 'img/infoballoon/arrow7.gif';
	
		with(_imgArrow.style){
			position='absolute';
			bottom='0px';
			height='53px';
			width='105px';
			left=Math.round(_size.getWidth()/2)+ 'px';
		}
	
		IWEventManager.addDOMListener(_imgClose,'onclick',function(e){
			_map.removeWindowOverlay(_self);
			if (_self.hasCloseAppendFunction){
				_self.closeAppendFunction();
			}
		});
		
	}
	
	function resize(){
		_container.style.height=_size.getHeight()+ 'px';
		_container.style.width=_size.getWidth()+ 'px';
		_divMain.style.width=_size.getWidth()+ 'px';
		_divMain.style.height=_size.getHeight()- 51 + 'px';
		_divContent.style.width=_size.getWidth()- 30 + 'px';
		_divContent.style.height=_size.getHeight()- 53 - 5 + 'px';
		_divTopBorder.style.width=_size.getWidth()- 42 + 'px';
		_divRightBorder.style.height=_size.getHeight()- 51 - 42 + 'px';
		_divBottomBorder.style.width=_size.getWidth()- 42 + 'px';
		_divLeftBorder.style.height=_size.getHeight()- 51 - 42 + 'px';
		_imgArrow.style.left=Math.round(_size.getWidth()/2)+ 'px';
	}

	var _container=this.getContainer();
	buildGUI();
	this.setAnchor(new IWPoint(-(_size.getWidth()/2),-(_size.getHeight())));
}



