﻿if (!iMap){
	var iMap=new Object();
}

var _st=setTimeout;
var _ct=clearTimeout;
var _G1=GMarker;
var _G2=GLatLng;
var _sht=-1;
var _mit=-1;
var _sit=-1;
var _bit=-1;
var ctrlDown=false;

iMap.map=null;
iMap.dataTimer=-1;
iMap.panDelay=420;
iMap.overDelay=800;
iMap.transID=0;
iMap.startIndex=0;
iMap.infoPane=null;
iMap.imagePane=null;
iMap.keepSession=false;
iMap.filterSettings="";
iMap.wantsFacts=false;
iMap.miniMapZoom=17;
iMap.zindex=90000000;
iMap.markerlist=new Array();
iMap.windowKey='';
iMap.sessionId='';
iMap.pingTimer=0;
iMap.countrystoreLoaded=false;
iMap.chOverlay=null;
iMap.chOverlayBounds=new GLatLngBounds(new GLatLng(36.29,2),new GLatLng(56.25,13));

iMap.currentCountry=0;

iMap.infoWidth=244;
iMap.selectionMarker=null;
iMap.selectionFaceMarker=null;
iMap.layerOverlays=new Array();
iMap.activeOverlays=0;

iMap.resetLayers=function(){

    iMap.map.clearOverlays();
     iMap.layerOverlays=new Array();
    iMap.activeOverlays=0;
    iMap.layerstoreLoaded=false;
    iMap.UpdateKontrast(null);
  
 try {
        clearLayers();
    }catch(e){}
 
}
iMap.resizePanels=function(p){
	
	try {
		var rx=x($("redRight"));
		var by=y($("bottomLine"));
		var mt=y($("map"));
		var el=$("map");
		var h=(by-mt-4);
		var w=(rx-this.infoWidth-16);
		el.style.width=w + "px";
		el.style.height=h + "px";
		$("rightPanel").style.height=el.style.height;
		$("factsPanelContent").style.height=(h-3*28-320) + "px";
		iMap.map.checkResize();
		
		
		if (p==1){
		setTimeout("iMap.resizePanels(0)",20);}
		}catch(e){
		
	}
	if (p==0){
	    iMap.resizeFilterPanel(0);
	    iMap.resizeLayerPanel(0);
	}

	try{
	    var temp=$("tempLang");
	    temp.style.top=(by) + 'px';
	}
	catch(e){}
	
}

iMap.showSelectionMarker=function(lat,lng,iconId){
    iMap.removeSelectionMarker();
    var selicon= new GIcon();
    if (Ext.isIE){
        selicon.image ="icons/selection_IE.gif";
    } else {
        selicon.image ="icons/selection.gif";
	}
	selicon.shadow = null;
	selicon.iconSize = new GSize(27, 27);
	selicon.shadowSize = new GSize(0, 00);
	selicon.iconAnchor = new GPoint(13, 13);
	selicon.infoWindowAnchor = new GPoint(13,13);
	
    iMap.selectionMarker=new  _G1(new _G2(lat,lng),{icon:selicon,zIndexProcess:selectionZIndex});
  
    iMap.selectionFaceMarker=new  _G1(new _G2(lat,lng),{icon:iMap.icons[iconId],zIndexProcess:selectionZIndex});
    iMap.map.addOverlay(iMap.selectionFaceMarker);
    iMap.map.addOverlay(iMap.selectionMarker);
     return;
 
    
}
function selectionZIndex(marker,b){
    iMap.zindex+=1;
    return iMap.zindex;
}
iMap.removeSelectionMarker=function(){

    if (iMap.selectionMarker!=null){
        iMap.map.removeOverlay(iMap.selectionMarker);
        iMap.selectionMarker=null;
  }
    if (iMap.selectionFaceMarker!=null){
        iMap.map.removeOverlay(iMap.selectionFaceMarker);
    }
    iMap.selectionFaceMarker=null;
}

iMap.resizeFilterPanel=function(dy){

try {iMap.imm_filterGrid.setHeight(y($("bottomLine"))-100-dy);}
	catch(e){}
		
}
iMap.resizeLayerPanel=function(dy){

try {
    var maxHeight=y($("bottomLine"))-100-dy;
  
    iMap.imm_layerGrid.setValue("maxHeight",maxHeight);
   // iMap.imm_layerGrid.maxHeight=maxHeight;
    iMap.imm_layerGrid.doLayout();
  /*  if (iMap.imm_layerGrid.getHeight()>maxHeight){
        iMap.imm_layerGrid.setHeight(maxHeight);}*/
	}
	catch(e){} 
		
}


iMap.setBounds=function(lat1,lng1,lat2,lng2){
	var b=new GLatLngBounds();
	b.extend(new _G2(lat1,lng1));
	b.extend(new _G2(lat2,lng2));
	var z=this.map.getBoundsZoomLevel(b) ;
	this.map.setCenter(b.getCenter(), z);
}
iMap.setInfomap=function(lat,lng,icon){
	var b=new GLatLngBounds();
	b.extend(new _G2(lat-0.00001,lng-0.00001));
	b.extend(new _G2(lat+0.00001,lng + 0.00001));
	var z=this.miniMap.getBoundsZoomLevel(b)
	//neu Version 2
	z=iMap.miniMapZoom;
	this.miniMap.setCenter(b.getCenter(), z);
	this.miniMap.clearOverlays();
	var infoMarker=new _G1(new _G2(lat,lng),this.ai(icon));
	this.miniMap.addOverlay(infoMarker);
}

iMap.showMarkers=function(){
if (iMap.inClear){
    _sht=_st("iMap.showMarkers()",10);
    return;
}
	var i;
	var c=80;
	var endindex=0;
		(iMap.startIndex+c>=(iMap.Markers.markers.length))?endIndex=iMap.Markers.markers.length:endIndex=iMap.startIndex+c;
	
	
	for (var i = iMap.startIndex; i < endIndex; i++) {
		try {
			with (iMap.Markers){
				cm( markers[i][0],markers[i][1],markers[i][2],markers[i][3],markers[i][4],markers[i][5]);
				if (markers[i][6]==1){
				iMap.getMarkerInfo(markers[i][0],markers[i][1],0);
				}
			}
		}
		catch (e){
		}
	}
	iMap.startIndex=endIndex;
	if (iMap.startIndex<iMap.Markers.markers.length){
		_sht=_st("iMap.showMarkers()",10);
	} else { _sht=-1;iMap.showOverlays();}
}

iMap.showOverlays=function(){
if(iMap.addressSearch.marker){
    iMap.map.addOverlay(iMap.addressSearch.marker);
    sHB("search_panel",false);
}

}
iMap.moveEnd=function(){
	clearTimeout(iMap.dataTimer);
	iMap.dataTimer=setTimeout("iMap.getData()",iMap.panDelay);
	//iMap.showHideChOverlay();
	
}
iMap.Markers=null;
iMap.drawMarkers=function(response){
    iMap.map.checkResize();
	iMap.Markers=eval("(" + response.responseText + ")");
	if (iMap.Markers.markers){
		iMap.startIndex=0;
		iMap.showMarkers();
	}
	if (iMap.Markers.nosession){
		eval(iMap.Markers.nosession);
		
	}
	if (iMap.Markers.wrongSession){
		eval(iMap.Markers.wrongSession);
		
	}
}
iMap.failedRequest=function(response){
	//alert(response.responseText);
}
iMap.onMouseOver=function(m){
	if( ctrlDown){
		_ct(_mit);
		_mit=_st("iMap.getMarkerInfo(" + m.transId + "," + m.faceIndex + ",0)",iMap.overDelay);
	}
}

iMap.listOver=function(tid,id){
	_ct(_sit);
	_sit=_st("iMap.getMarkerInfo(" + tid + "," + id + ",1)",iMap.overDelay/2);
	
}
iMap.listOut=function(){
	
	_ct(_sit);
	
}
iMap.onMouseOut=function(m){
	if( ctrlDown){
		_ct(_mit);
		iMap.infoPane.innerHTML="" ;
	}
}
iMap.imageLoadingTimer=0;
iMap.contentLoadingTimer=0;

iMap.getMarkerInfo=function(tid,fid,fns){
    //Layer panel 
    sHB('layer_panel',false);
    
    iMap.removeSelectionMarker();
	if (fns==0){$("same").innerHTML="";}
	_ct(iMap.imageLoadingTimer);
	iMap.imageLoadingTimer=_st(iMap.showImageLoading,150);
	_ct(iMap.contentLoadingTimer);
	iMap.contentLoadingTimer=_st(iMap.showContentLoading,150);
this.miniMap.clearOverlays();
	sHB('adPanel',false);
    Ext.Ajax.request({
			url: 'markerInfo.ashx',
			success: this.onMarkerInfo,
			method:'GET',
			failure: this.failedRequest,
			headers: {'iMap-header': 'iMap'},
			params: { tid: tid, fid:fid,fns:fns,windowKey:iMap.windowKey,sessionId:iMap.sessionId }
	});
}
iMap.showImageLoading=function(){
    iMap.imagePane.innerHTML='<img src="images/loading.gif" border="0" />';
	
}
iMap.showContentLoading=function(){
   iMap.infoPane.innerHTML='<img src="images/loading.gif" border="0" />';

}

iMap.getContentInfo=function(panel){
	Ext.Ajax.request({
			url: 'contentHandler.ashx',
			success: this.onContentInfo,
			method:'GET',
			failure: this.failedRequest,
			headers: {'iMap-header': 'iMap'},
			params: { panel: panel }
	});
}
iMap.getNetworkInfo=function(){
	Ext.Ajax.request({
			url: 'cmdHandler.ashx',
			success: this.onGetNetworkInfo,
			method:'GET',
			failure: this.failedRequest,
			headers: {'iMap-header': 'iMap'},
			params: { cmd: 'networkInfo' }
	});
}
iMap.networkInfoHtml="";
iMap.onGetNetworkInfo=function(response){
	var xml= GXml.parse(response.responseText);
	iMap.infoPane.innerHTML=""
	if (xml.documentElement.getElementsByTagName("info").length>0){
		var info=xml.documentElement.getElementsByTagName("info")[0].firstChild.nodeValue;
		iMap.networkInfoHtml=info;
		sHB('adPanel',false);
	iMap.infoPane.innerHTML=info;
		}
	if (xml.documentElement.getElementsByTagName("js").length>0){
		var js=xml.documentElement.getElementsByTagName("js")[0].firstChild.nodeValue;
		if (js!=''){
			try{
				eval(js);
			}
			catch(e){}
		}
	}
}

iMap.onContentInfo=function(response){
     var xml= GXml.parse(response.responseText);
       _ct(iMap.contentLoadingTimer);

     var ele=null
     if (xml.documentElement.getElementsByTagName("ele").length>0){
        ele=xml.documentElement.getElementsByTagName("ele")[0].firstChild.nodeValue;
        
     }
     if (xml.documentElement.getElementsByTagName('html').length>0){
        $(ele).innerHTML=xml.documentElement.getElementsByTagName('html')[0].firstChild.nodeValue;
     }
	 if (xml.documentElement.getElementsByTagName("js").length>0){
		var js=xml.documentElement.getElementsByTagName("js")[0].firstChild.nodeValue;
		if (js!=''){
			try{
				eval(js);
			}
			catch(e){}
		}
	}
}

iMap.onMarkerInfo=function(response){
	_ct(iMap.imageLoadingTimer);
    _ct(iMap.contentLoadingTimer);

	var xml= GXml.parse(response.responseText);
	lastresult=xml;
	iMap.infoPane.innerHTML=iMap.networkInfoHtml;
	if (xml.documentElement.getElementsByTagName("wrongSession").length>0){
		eval(xml.documentElement.getElementsByTagName("wrongSession")[0].firstChild.nodeValue);
		
	}
	if (xml.documentElement.getElementsByTagName("attr").length>0){
		var info=xml.documentElement.getElementsByTagName("attr")[0].firstChild.nodeValue
		iMap.infoPane.innerHTML=info;
	}
	if (xml.documentElement.getElementsByTagName("images").length>0){
		var info=xml.documentElement.getElementsByTagName("images")[0].firstChild.nodeValue
		iMap.imagePane.innerHTML=info;
	}
	if (xml.documentElement.getElementsByTagName("same").length>0){
		var info=xml.documentElement.getElementsByTagName("same")[0].firstChild.nodeValue
		$("same").innerHTML=info;
	}
	if (xml.documentElement.getElementsByTagName("near").length>0){
		var info=xml.documentElement.getElementsByTagName("near")[0].firstChild.nodeValue
		$("same").innerHTML +=info;
	}
	if (xml.documentElement.getElementsByTagName("js").length>0){
		var js=xml.documentElement.getElementsByTagName("js")[0].firstChild.nodeValue;
		if (js!=''){
			try{
				eval(js);
			}
			catch(e){}
		}
	}
}

iMap.setSelectionMarker=function(lat,lng){
alert(lat);
}

iMap.onCmd=function(response){
	var s= response.responseText ;
	//  alert(s);
	try {
		eval(s);
	}
	catch(e){
	}
}

iMap.showBig=function(imgUrl){
	_ct(_bit);
	$("bigImage").innerHTML='<img onclick="iMap.hideBig()" src="' + imgUrl + '" border="0" />';
	$("bigImage").style.display="block";
	_bit=_st("iMap.hideBig()",10000);
}
iMap.hideBig=function(){
	$("bigImage").style.display="none";
}
iMap.doCmd=function(cmd,args){
	Ext.Ajax.request({
			url: 'cmdHandler.ashx',
			success: this.onCmd,
			method:'GET',
			failure: this.failedRequest,
			headers: {'iMap-header': 'iMap'},
			params: { cmd: cmd, args:args,windowKey:iMap.windowKey,sessionId:iMap.sessionId,filterInfo:iMap.filterSettings }
	});
}
iMap.ping=function(){
    _ct(iMap.pingTimer);
   iMap.pingTimer= _st("iMap.doCmd('ping')",20000);
}

iMap.getData=function(){
	_ct(_sht);
	iMap.transID +=1;
	this.clearPanels();
	var bounds=iMap.map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	Ext.Ajax.request({
			url: 'getMarkers.ashx',
			success: this.drawMarkers,
			method:'GET',
			failure: this.failedRequest,
			headers: {'iMap-header': 'iMap'},
			params: { transId: iMap.transID, lat1: southWest.y,lng1:southWest.x,lat2:northEast.y,lng2:northEast.x ,filters:iMap.filterSettings,windowKey:iMap.windowKey,sessionId:iMap.sessionId}
	});
	iMap.clearMarkers();
	iMap.showHideChOverlay();
	
	
}
iMap.inClear=false;
iMap.clearMarkers=function(){
    if (iMap.activeOverlays>0){
        iMap.removeSelectionMarker();
        var i;
        iMap.inClear=true;
        for (i=0;i<iMap.markerlist.length;i++){
      //  GEvent.clearInstanceListeners(iMap.markerlist[i]);
            iMap.map.removeOverlay(iMap.markerlist[i]);
            GEvent.clearNode(iMap.markerlist[i]);
            iMap.markerlist[i]=null;
        }
     } else {
        iMap.map.clearOverlays();
        iMap.UpdateKontrast(null);
        
     }
     iMap.markerlist=new Array();
     if(iMap.addressSearch.marker){
            iMap.map.removeOverlay(iMap.addressSearch.marker);
     }

   // iMap.map.clearOverlays();
   iMap.inClear=false;

}
iMap.checkOverlays=function(oldZoom, newZoom){
var hiddenHint='<div title="' + iMap.lang.hiddenHint + '"><img src="css/images/layerHidden.png" height="16" /></div>';
    for  (var item in iMap.layerOverlays)
    { try{
        if (iMap.layerOverlays[item]!=null && iMap.layerOverlays[item].minZoom!=undefined){
            if (!(iMap.layerOverlays[item].minZoom<=newZoom && iMap.layerOverlays[item].maxZoom>=newZoom)){
                   iMap.layerOverlays[item].hide(); 
                   iMap.imm_layerLayerHint(item,hiddenHint);
                 } else {
                   iMap.layerOverlays[item].show(); 
                   iMap.imm_layerLayerHint(item,'');
              
                }
            }
     }catch(e){}
            
        
    }
}
iMap.showOverlay=function(url,minZoom,maxZoom){
    if (!iMap.layerOverlays[url]){
        iMap.layerOverlays[url]=new GGeoXml(url);
        iMap.layerOverlays[url].minZoom=minZoom;
        iMap.layerOverlays[url].maxZoom=maxZoom;
	    iMap.map.addOverlay(iMap.layerOverlays[url]);
    }
    iMap.checkOverlays(iMap.map.getZoom(),iMap.map.getZoom());
}
iMap.hideOverlay=function(url){
    if (iMap.layerOverlays[url]){
        iMap.map.removeOverlay(iMap.layerOverlays[url]);
        iMap.layerOverlays[url]=null;
    }
    iMap.imm_layerLayerHint(url,'');
}
iMap.clearPanels=function(){
	$("same").innerHTML="";
	iMap.infoPane.innerHTML="";
	iMap.infoPane.innerHTML=iMap.networkInfoHtml;
	
	iMap.imagePane.innerHTML="";
	iMap.miniMap.clearOverlays();
}

iMap.ui=new Object();
iMap.ui.setLanguage=function(lang){
	
}

iMap.init=function(map,minimap,language,infoPane,imagePane){
	iMap.map=map;
	iMap.miniMap=minimap;
	iMap.language=language;
	iMap.infoPane=infoPane;
	iMap.imagePane=imagePane;
	//this.doCmd("init");
	_st('iMap.delayedInit()',150);
	_st('iMap.addOverviewControl()',2000);
	_st('iMap.imm_layerStore.load()',2000);
}
iMap.delayedInit=function(){
this.doCmd("init");
 iMap.kontrastSlider.setValue(iMap.MapOpacity*100,true);
 
}

iMap.onMaptypeChanged=function(){
    var mt=iMap.map.getCurrentMapType();
    switch (mt){
        case G_NORMAL_MAP:
            minMapScale=minNmapScale;
            maxMapScale=maxNmapScale;
            iMap.kontrastSlider.setValue(iMap.MapOpacity*100,true);
            break;
         case G_SATELLITE_MAP:
            minMapScale=minSmapScale;
            maxMapScale=maxSmapScale;
            iMap.kontrastSlider.setValue(iMap.SatelliteOpacity*100,true);
  
            break;
         case G_HYBRID_MAP:
            minMapScale=minHmapScale;
            maxMapScale=maxHmapScale;
            iMap.kontrastSlider.setValue(iMap.HybridOpacity*100,true);
  
            break;            
            
    }
    
}
iMap.MapControl=function (text,action,x,y,gmapref){
	this.x=x;
	this.y=y;
	this.text=text;
	this.action=action;
	this.el=null;
	return this;
	
	
}
iMap.MapControl.prototype = new GControl(false,false);


iMap.MapControl.prototype.getDefaultPosition = function() {
	var res= new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(this.x,this.y));
	return res;
};
iMap.MapControl.prototype.setText=function(newText){
	this.text=newText;
	this.el.innerHTML=newText;
}
iMap.MapControl.prototype.show=function(){
	this.el.style.display="block";
}
iMap.setText =function(id, newText){
	var el=document.getElementById(id);
	el.firstChild.nodeValue=newText;
}

iMap.SliderControl=function (text,x,y,gmapref){
	this.x=x;
	this.y=y;
	this.text=text;
    this.el=null;
	return this;
	
	
}
iMap.SliderControl.prototype = new GControl(false,false);
iMap.SliderControl.prototype.getDefaultPosition = function() {
	var res= new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(this.x,this.y));
	return res;
};

iMap.SliderControl.prototype.initialize=function(gmapref)
{
	
	var container=gmapref.getContainer();
	var c = document.createElement('div' );
	c.className="immMapSliderControl";
	c.style.width="120px";
	c.style.display="block";
	c.style.overflow="hidden";
	c.id="_kontrastSlider";
	iMap.kontrastSlider.render(c);
	container.appendChild(c);
	this.el=c;
	return c;
}

iMap.MapControl.prototype.initialize = function(gmapref)
{
	
	var container=gmapref.getContainer();
	var c = document.createElement('div' );
	c.className="immMapControl";
	c.style.width="80px";
	c.style.display="none";
	c.action=this.action;
	c.innerHTML=this.text;
	c.onmouseover=function(){this.style.backgroundPosition='0px 20px';};
	c.onmouseout=function(){this.style.backgroundPosition='0px 0px';};
	c.onclick= function(){ iMap.MapControlAction(this.action);}
	container.appendChild(c);
	this.el=c;
	return c;
}

iMap.MapControlAction=function(action){
	iMap.map.setMapType(action);
}


function cm(tid,index,lat,lng,icon,a){
	if (tid==iMap.transID){
		var marker=new _G1(new _G2(lat,lng),iMap.icons[icon]);
		marker.faceIndex=index;
		marker.transId=tid;
		marker.fcount=a;
		GEvent.addListener(marker, "click", function(){iMap.getMarkerInfo(this.transId,this.faceIndex,0);});
		if (a==1){
			GEvent.addListener(marker, "mouseover", function(){iMap.onMouseOver(this);});
			GEvent.addListener(marker, "mouseout", function(){iMap.onMouseOut(this);});
		}
		iMap.markerlist.push(marker);
		iMap.map.addOverlay(marker);
		
	}
}
var _G2=GLatLng;
iMap.LargeMapControl1=null;
iMap.setLargemapControl=function(){

    if (iMap.LargeMapControl1!=null){
        iMap.map.removeControl(iMap.LargeMapControl1);
    }
    var opts2 = {
        zoomInBtnTitle : iMap.lang.zoomInBtnTitle,
        zoomOutBtnTitle : iMap.lang.zoomOutBtnTitle,
        moveNorthBtnTitle : iMap.lang.moveNorthBtnTitle,
        moveSouthBtnTitle : iMap.lang.moveSouthBtnTitle,
        moveEastBtnTitle : iMap.lang.moveEastBtnTitle,
        moveWestBtnTitle : iMap.lang.moveWestBtnTitle,
        homeBtnTitle : iMap.lang.homeBtnTitle
        };
        iMap.LargeMapControl1=new ExtLargeMapControl(opts2);
        iMap.map.addControl(iMap.LargeMapControl1);
}
function mapLoad() {
	_map=document.getElementById("map");
	_miniMap=document.getElementById("miniMap");
	if (GBrowserIsCompatible()) {
		var map;
		var miniMap;
		map = new GMap2(_map);
		miniMap = new GMap2(_miniMap);
		map.setCenter(new GLatLng(0, 0), 1);
		var center = map.getCenter();
		
		
        
    	//map.addControl(new GLargeMapControl());
		//map.addControl(new GOverviewMapControl());
		map.enableScrollWheelZoom();
		miniMap.enableScrollWheelZoom();
		
	    GEvent.addListener(map, "moveend",function(){iMap.moveEnd();});
		GEvent.addListener(map, "maptypechanged",function(){iMap.onMaptypeChanged();});
	  	
		map.enableContinuousZoom();
		iMap.init(map,miniMap,'',document.getElementById("factsPanelContent"),document.getElementById("imageContent"));
		//V2
		iMap.setLargemapControl();
	    GEvent.addListener(map, "zoomend",function(a,b){iMap.checkOverlays(a,b)});
	
		document.onkeydown = handleKeyDown;
		document.onkeyup = handleKeyUp;
		iMap.mapControlMap=new iMap.MapControl(iMap.lang.control_map,G_NORMAL_MAP,196,8);
		iMap.mapControlMap.initialize(map);
		map.addControl(iMap.mapControlMap,iMap.mapControlMap.getDefaultPosition());
		iMap.mapControlSatelite=new iMap.MapControl(iMap.lang.control_satelite,G_SATELLITE_MAP,102,8);
		iMap.mapControlSatelite.initialize(map);
		map.addControl(iMap.mapControlSatelite,iMap.mapControlSatelite.getDefaultPosition());
		
		iMap.mapControlHybrid=new iMap.MapControl(iMap.lang.control_hybrid,G_HYBRID_MAP,8,8);
		iMap.mapControlHybrid.initialize(map);
		map.addControl(iMap.mapControlHybrid,iMap.mapControlHybrid.getDefaultPosition());
		iMap.mapControlSatelite.show();
		iMap.mapControlMap.show();
		iMap.mapControlHybrid.show();
		iMap.createContextMenu();
		iMap.translateContextMenu();
		map.addControl(new GScaleControl());
		
		iMap.Kontrast=new GTileLayerOverlay(iMap.kontrastLayer,{zPriority:0});
		iMap.KontrastControl=new iMap.SliderControl("Kontrast",290,8);
		map.addControl(iMap.KontrastControl);

	}
}
iMap.onSliderChange=function(sld,value){
    //alert("change:" + value);
    iMap.UpdateKontrast(value/100);
}
iMap.UpdateKontrast=function(value){
    if (value!=null){
        switch (iMap.map.getCurrentMapType()){
            case G_NORMAL_MAP:
                iMap.MapOpacity=value;
                break;
            case G_SATELLITE_MAP:
                iMap.SatelliteOpacity=value;
                break;
            case G_HYBRID_MAP:
                iMap.HybridOpacity=value;
                break;
        
        }
    }
    iMap.map.removeOverlay(iMap.Kontrast);
    iMap.map.addOverlay(iMap.Kontrast);
}
//Kartenkontrast
iMap.Copyright = new GCopyrightCollection("© ");
iMap.Copyright.addCopyright(new GCopyright('intermediamap',
  new GLatLngBounds(new GLatLng(-90,-180), new GLatLng(90,180)),
  0,'©2010 intermediamap'));
iMap.MapOpacity=0.3;
iMap.SatelliteOpacity=0.0;
iMap.HybridOpacity=0.0;

// Create the tile layer overlay and 
// implement the three abstract methods                 
iMap.kontrastLayer = new GTileLayer(this.Copyright);
iMap.kontrastLayer.getTileUrl = function() { return "css/images/whiteTile.gif"; };
iMap.kontrastLayer.isPng = function() { return false;};
iMap.kontrastLayer.getOpacity = function() { 
            switch (iMap.map.getCurrentMapType()){
            case G_NORMAL_MAP:
                return iMap.MapOpacity;
                break;
            case G_SATELLITE_MAP:
                return iMap.SatelliteOpacity;
                break;
            case G_HYBRID_MAP:
                return iMap.HybridOpacity;
                break;
        
        }
         };


iMap.addOverviewControl=function(){
    iMap.map.addControl(new GOverviewMapControl());
	
}
//Kontext menu
iMap.contextMenu;
iMap.contextPixel;
 iMap.hideContextMenu=function(){
   iMap.contextMenu.style.visibility="hidden";
 }
iMap.createContextMenu=function()
   {
        
      iMap.contextMenu = document.createElement("div");
      iMap.contextMenu.style.background="#ffffff";
      iMap.contextMenu.style.border="1px solid #8888FF";
      var html="";
      html += '<div class="contextMenuItem" onClick="iMap.zoomIn()" id="contextZoomIn">Zoom in</div>';
      html += '<div class="contextMenuItem" onClick="iMap.zoomOut()" id="contextZoomOut">Zoom out</div>';
      html += '<div class="contextMenuItem" onClick="iMap.zoomInHere()" id="contextZoomInHere">  Zoom in here  </div>';
      html += '<div class="contextMenuItem" onClick="iMap.zoomOutHere()" id="contextZoomOutHere">  Zoom out here  </div>';
      html += '<div class="contextMenuItem" onClick="iMap.centerMapHere()" id="contextCenterMapHere">  Center map here  </div>';
      iMap.contextMenu.innerHTML =html;
     iMap.contextMenu.style.visibility = "hidden";
      iMap.map.getContainer().appendChild(iMap.contextMenu);
      setTimeout('  iMap.hideContextMenu();',30);
      GEvent.addListener(iMap.map,"singlerightclick",function(pixel,tile){
            iMap.translateContextMenu();
          iMap.contextPoint = iMap.map.fromContainerPixelToLatLng(pixel)
          var x=pixel.x;
          var y=pixel.y;
          var testWidth=iMap.contextMenu.offsetWidth;
          if (testWidth==iMap.map.getSize().width){
            testWidth=160;
          }
          if ( (x > iMap.map.getSize().width - testWidth)) 
          { 
            x = iMap.map.getSize().width - testWidth;
          }
          if (y > iMap.map.getSize().height - 100) 
          { 
            y = iMap.map.getSize().height - 100 
          }
          var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x,y));  
          pos.apply(iMap.contextMenu);
          iMap.contextMenu.style.visibility = "visible";
        
         
     });
     GEvent.addListener(iMap.map, "click", function() 
     {
            iMap.hideContextMenu();
     });
 }
 iMap.translateContextMenu=function(){
  
    iMap.setText('contextZoomIn',iMap.lang.contextZoomIn);
    iMap.setText('contextZoomOut',iMap.lang.contextZoomOut);
    iMap.setText('contextZoomInHere',iMap.lang.contextZoomInHere);
    iMap.setText('contextZoomOutHere',iMap.lang.contextZoomOutHere);
    iMap.setText('contextCenterMapHere',iMap.lang.contextCenterMapHere);
 }

 
 iMap.zoomIn =function(){
            iMap.map.zoomIn();
            iMap.hideContextMenu();
 }
 iMap.zoomOut =function(){
            iMap.map.zoomOut();
            iMap.hideContextMenu();
 }
 iMap.zoomInHere=function() 
 {
           iMap.map.zoomIn(iMap.contextPoint,true);
               iMap.hideContextMenu();
 }      
 iMap.zoomOutHere =function() 
 {
          iMap.map.setCenter(iMap.contextPoint,iMap.map.getZoom()-1); 
              iMap.hideContextMenu();
 }      
 iMap.centerMapHere =function()
 {
         iMap.map.setCenter(iMap.contextPoint);
            iMap.hideContextMenu();
 }
 
iMap.showHideChOverlay=function()
{ 
    var url='http://www.intermediamap.com/layers/ch/transparent_ch.KML?neu8';
     if (iMap.currentCountry==1){ //1=Schweiz
        var bounds=iMap.map.getBounds(); 
        if (iMap.chOverlayBounds.containsLatLng(bounds.getNorthEast()) && iMap.chOverlayBounds.containsLatLng(bounds.getSouthWest())){
            iMap.chOverlay=new GGeoXml(url);
            iMap.map.addOverlay(iMap.chOverlay);
        }
     }
    
    
return;

    if (iMap.currentCountry==1){ //1=Schweiz
        var bounds=iMap.map.getBounds(); 
        if (iMap.chOverlayBounds.containsLatLng(bounds.getNorthEast()) && iMap.chOverlayBounds.containsLatLng(bounds.getSouthWest())){
        //overlay anzeigen
            if (!iMap.chOverlay){
                iMap.chOverlay=new GGroundOverlay("http://www.intermediamap.com/layers/ch/transparent.png", iMap.chOverlayBounds);
            }
            iMap.map.addOverlay(iMap.chOverlay);
        } else {
        //overlay verbergen
            if (iMap.chOverlay){
                iMap.map.removeOverlay(iMap.chOverlay);
            }
        }
    }

}


function handleKeyDown(e){e=e || window.event;if (e.ctrlKey){ctrlDown=false;}return true;}
function handleKeyUp(e){e=e || window.event;if (e.keyCode==17){ctrlDown=false; }return true;}

function cleanUp(){
if (!iMap.keepSession){
Ext.Ajax.request({
			url: 'onUnload.ashx',
		    method:'GET',
			headers: {'iMap-header': 'iMap'}
	});
	
	}
}

