
stationsMapObj = {
   cObjID: 0,
   stopsURL: '',
   newStopsURL: '',
   addressesURL: '',
   stationDetailURL: '',
   lastStringChangeTS: 0,
   realDetailURL: '',
   stopScriptsURL: '',
   timeTableRequestURL: '',
   showStops: 6,
   showAddresses: 3,
   defaultRadius: 1600,
   dragNewTS: 0,
   dragOldTS: 0,
   centerObj: {},
   searchRequest: {},
   responseArr: [],
   radialArr: [],
   resultArr: [],
   testObj: {},
   mapObj: {},
   selectedFrom: {},
   selectedTo: {},
   dontSearch: false,
   performSearch: {},
   xMin: 0,
   xMax: 0,
   yMin: 0,
   yMax: 0,
   requestStatus: {stops: false,addresses: false},
   init: function(cObjID,stopsURL,newStopsURL,addressesURL,stationDetailURL,stopScriptsURL,timeTableRequestURL,realDetailURL,mapObj,xMin,xMax,yMin,yMax) {

      try {

         this.cObjID = parseInt(cObjID,10);
         this.stopsURL = stopsURL;
         this.newStopsURL = newStopsURL;
         this.addressesURL = addressesURL;
         this.stationDetailURL = stationDetailURL;
         this.stopScriptsURL = stopScriptsURL;
         this.timeTableRequestURL = timeTableRequestURL;
         this.realDetailURL = realDetailURL;
         this.xMin = parseFloat(xMin);
         this.yMin = parseFloat(yMin);
         this.xMax = parseFloat(xMax);
         this.yMax = parseFloat(yMax);
         this.mapObj = mapObj;
         this.updateSavedStops();

      }catch(error) {
         this.write2Debug('stationsMapObj.init',error);
      }

   },
   setMap2FullHeight: function(elementID1,elementID2) {

      try {

         var maxHeight = 0;

         if ($('pageBoxFS')) {
            maxHeight = parseInt($('pageBoxFS').getHeight(),10);
            if ( $('mainContent')) {
               maxHeight -= 224;
            }
          } else {
            maxHeight = 600;
            $(elementID1).style.width = '690px';
            $(elementID2).style.width = '690px';
            // no fullscreen, set height of content column
         }

         $(elementID1).style.height = maxHeight+'px';
         $(elementID2).style.height = maxHeight+'px';

      } catch(error) {
         this.write2Debug('stationsMapObj.setMap2FullHeight',error);
      }

   },
   stringChanged: function(element) {

      try {

         if (this.dontSearch) {
            this.dontSearch = false;
            return false;
         }


         var actTS = new Date().getTime();

         this.write2Debug('stationsMapObj.stringChanged','actTS: '+actTS);
         this.write2Debug('stationsMapObj.stringChanged','lastTS: '+this.lastStringChangeTS);

         var timePassed = parseInt(actTS - this.lastStringChangeTS,10);

         this.write2Debug('stationsMapObj.stringChanged','passed: '+timePassed);

         this.lastStringChangeTS = actTS;

         var searchString = String(element.value);

         try {
            window.clearTimeout(this.performSearch);
         } catch(err) {

         }

         this.performSearch = this.startSearch.bind(this).delay(1,searchString);
         
      } catch(error) {
         this.write2Debug('stationsMapObj.stringChanged',error);
      }

   },
   startSearch: function(searchString) {

      try {

         var i=0;
         var result = {};

         if ( searchString == '' ) {
            return false;
         }

         var stringLength = parseInt(searchString.length,10);

         if (stringLength == 1) {
            return false;
         }

         if (stringLength > 64) {
            return false;
         }

         $('searchResult_'+this.cObjID).show();
         $('searchResult_'+this.cObjID).innerHTML = this.loadingContent;

         // Start Request
         this.requestStatus.stops = false;
         this.requestStatus.addresses = false;
         this.resultArr = [];


         if ( typeof(this.searchRequest.abort) == 'function' ) {
            this.searchRequest.abort();
         }

         // this.searchRequest.abort();

         // get some stops
         this.searchRequest = new Ajax.Request(this.stopsURL, {
            method: 'get',
            parameters: {
               cmd: 'stops',
               search_string: searchString,
               export_type: 'json',
               xmin: this.xMin,
               xmax: this.xMax,
               ymin: this.yMin,
               ymax: this.yMax
            },
            onSuccess: function(transport) {

               if (transport.responseJSON) {

                  this.responseArr = transport.responseJSON.toArray();

                  i = 0;

                  this.responseArr.each(function(info){

                     if ( i < this.showStops ) {

                        result = {
                           type: 'stop',
                           label: info.name,
                           x: info.coord.x,
                           y: info.coord.y,
                           id: info.id
                        };

                        if ( info.gemeinde != '' ) {
                           result.gemeinde = info.gemeinde;
                        }

                        if ( info.ort != '' ) {
                           result.ort = info.ort;
                        }

                        this.resultArr.push(result);

                        i++;

                     }

               }.bind(this));

               // request finished
               this.requestStatus.stops = true;
               this.setOutput();

              } else {
                  // no json, but request is finished
                  this.requestStatus.stops = true;
                  this.setOutput();
              }

           }.bind(this),
           onFailure : function() {

            // Failure, but finished
            this.requestStatus.stops = true;
            this.setOutput();


           }.bind(this),
           onException: function() {

            // Exception, but finished
            this.requestStatus.stops = true;
            this.setOutput();


           }.bind(this),
           onComplete: function() {

            if (Ajax.activeRequestCount < 0) {
                Ajax.activeRequestCount = 0;
            }

           }

         });


         // search for addresses if String 4+ chars
         if (stringLength < 5) {
            // no json, but request is finished
            this.requestStatus.addresses = true;
            this.setOutput();
            return true;
         }


         new Ajax.Request(this.stopsURL, {
           method: 'get',
           parameters: {
            cmd: 'addresses',
            search_string: searchString,
            export_type: 'json',
            xmin: this.xMin,
            xmax: this.xMax,
            ymin: this.yMin,
            ymax: this.yMax
           },
           onSuccess: function(transport) {

              if (transport.responseJSON) {

               this.responseArr = transport.responseJSON.toArray();

               i = 0;

               this.responseArr.each(function(info){

                  this.testObj = info;

                  if ( i < this.showAddresses ) {

                     result = {
                        type: 'address',
                        label: info.name,
                        x: info.coord.x,
                        y: info.coord.y
                     };

                     this.resultArr.push(result);

                     i++;

                  }

               }.bind(this));

               // request finished
               this.requestStatus.addresses = true;
               this.setOutput();

              } else {
                  // no json, but request is finished
                  this.requestStatus.addresses = true;
                  this.setOutput();
              }

           }.bind(this),
           onFailure : function() {

            // Failure, but finished
            this.requestStatus.addresses = true;
            this.setOutput();


           }.bind(this),
           onException: function() {

            // Exception, but finished
            this.requestStatus.addresses = true;
            this.setOutput();


           }.bind(this)

         });

         return true;


      } catch(error) {
         this.write2Debug('stationsMapObj.startSearch',error);
      }
      

   },
   setOutput: function() {

      try {

         if (this.requestStatus.stops && this.requestStatus.addresses) {

            $('searchResult_'+this.cObjID).show();

            var label;

            var outputAddresses = '';
            var outputStops = '';

            var itemTemplate = new Template(this.itemTemplate);

            this.resultArr.each(function(info) {

               if ( info.type == 'stop' ) {

                  label = info.label;

                  if (info.gemeinde && info.ort) {
                     label += ' ('+info.gemeinde+' / '+info.ort+')';
                  } else if (info.gemeinde) {
                     label += ' ('+info.gemeinde+')';
                  } else if (info.ort) {
                     label += ' ('+info.ort+')';
                  }

                  outputStops += itemTemplate.evaluate({itemType: info.type, itemLabel: label, itemX: info.x, itemY: info.y, itemID: info.id, itemCity: info.ort, itemDistrict: info.gemeinde});
               }

            }.bind(this));

            this.resultArr.each(function(info) {

               if ( info.type == 'address' ) {

                  outputAddresses += itemTemplate.evaluate({itemType: info.type, itemLabel: info.label, itemX: info.x, itemY: info.y, itemID: 0, itemCity: '', itemDistrict: ''});
               }

            });


            $('searchResult_'+this.cObjID).innerHTML = outputStops+outputAddresses;

            // reset
            this.requestStatus.stops = false;
            this.requestStatus.addresses = false;
            this.resultArr = [];

         }

      }catch(error) {
         this.write2Debug('stationsMapObj.setOutput',error);
      }

   },
   setCenter: function(x,y,label,type,id,city,district) {

      try {

         x = parseFloat(x);
         y = parseFloat(y);

         if ($('searchResult_'+this.cObjID) ) {
            $('searchResult_'+this.cObjID).hide();
         }

         if ($('searchInput_'+this.cObjID) ) {
            $('searchInput_'+this.cObjID).value = label;
         }

         id = parseInt(id,10);
         this.centerObj.id = id;
         this.centerObj.type = type;
         this.centerObj.label = label;
         this.centerObj.x = x;
         this.centerObj.y = y;

         this.dontSearch = true;

         // this.mapObj.setZoomlevel(6);
         // this.mapObj.setMapPosition(x,y);

         this.mapObj.removeAllMarker();
         this.mapObj.redrawTourtorial();

         this.resetCenterMarker();

         this.getStopsAround(x,y,this.defaultRadius);


      } catch(error) {
         this.write2Debug('stationsMapObj.setCenter',error);
      }


   },
   setTopBoxPosition: function() {

      try {

         if ( $('pageBoxFS') && $('nav') ) {


            var navPos = $('nav').select('ul.firstLevel');

            // sbsLightBox.resizePopup('bigDetail');
            var platform = this.checkPlatform();
            var newWidth = 702;

            switch(platform) {

               default:
               case 'win':
                   $('topBox_'+this.cObjID).style.width = newWidth+'px';
               break;

               case 'mac':
                  newWidth = 679;
                  $('topBox_'+this.cObjID).style.width = newWidth+'px';
               break;

            }


            if (navPos[0]) {
               navPos = navPos[0].cumulativeOffset();
               navPos = navPos[0];

               var mapPos = $('mapObj'+this.cObjID).cumulativeOffset();
               mapPos = mapPos[0];

               navPos = navPos - mapPos;

               if (navPos > -1) {

                  $('topBox_'+this.cObjID).style.left = navPos+'px';

               }


            }

         } else {

            if ( $('mainContent2') && $('topBox_'+this.cObjID) ) {

               var ffwidth1 = parseInt($('topBox_'+this.cObjID).getWidth(),10);
               var ffwidth2 = parseInt($('mainContent2').getWidth(),10);

               var ffwidth3 = parseInt(ffwidth2 - ffwidth1,10);

               ffwidth3 = Math.floor(ffwidth3/2);

               $('topBox_'+this.cObjID).style.left = ffwidth3+'px';


            }

         }

      } catch (error) {
         this.write2Debug('stationsMapObj.setTopBoxPosition',error);
      }

   },
   getStopsAround: function(x,y,radius,cmd) {

      try {

         // alert(x+' | '+y+' | '+radius+' | '+cmd);

         x = parseFloat(x);
         y = parseFloat(y);
         radius = parseInt(radius,10);

         this.radialArr = [];

         // get some stops
         new Ajax.Request(this.stopScriptsURL, {
            method: 'get',
            parameters: {
               search_x: x,
               search_y: y,
               search_radius: radius,
               export_type: 'json',
               cmd: 'radialStops'
            },
            onSuccess: function(transport) {

               if (transport.responseJSON) {

                  this.radialArr = transport.responseJSON.toArray();

                  this.showStopMarker(cmd);


              } else {
               // no json, but request is finished
               this.showStopMarker(cmd);
              }

           }.bind(this),
           onFailure : function() {

            // Failure, but finished
            this.showStopMarker(cmd);


           }.bind(this),
           onException: function() {

            // Exception, but finished
            this.showStopMarker(cmd);

           }.bind(this)

         });

      } catch(error) {
         this.write2Debug('stationsMapObj.getStopsAround',error);
      }

   },
   showStopMarker: function(cmd){

      try {

         var tempMarker = {};
         var center_icons = [];

         var actID = 0;

         if ( cmd == 'clear' ) {
            this.mapObj.removeAllMarker();
            this.mapObj.redrawTourtorial();
         		this.resetCenterMarker();
         }

         this.radialArr.each(function(info){

            actID = parseInt(info.id,10);

            if (actID === this.centerObj.id ) {
               return;
            }

            tempMarker = new sbsMarker('stoppoint['+info.id+']','stoppoint', new sbsGKPoint(info.coord.x,info.coord.y,0),null,null);

            center_icons = new Array();
            center_icons[0] = icon_stop_16;
            center_icons[1] = icon_stop_16;
            center_icons[2] = icon_stop_16;
            center_icons[3] = icon_stop_24;
            center_icons[4] = icon_stop_24;
            center_icons[5] = icon_stop_30;
            center_icons[6] = icon_stop_30;
            center_icons[7] = icon_stop_30;
            center_icons[8] = icon_stop_30;
            tempMarker.setIconArray(center_icons);

            center_icons = new Array();
            center_icons[0] = icon_stop_16_hover;
            center_icons[1] = icon_stop_16_hover;
            center_icons[2] = icon_stop_16_hover;
            center_icons[3] = icon_stop_24_hover;
            center_icons[4] = icon_stop_24_hover;
            center_icons[5] = icon_stop_30_hover;
            center_icons[6] = icon_stop_30_hover;
            center_icons[7] = icon_stop_30_hover;
            center_icons[8] = icon_stop_30_hover;
            tempMarker.setHoverArray(center_icons);

            tempMarker.setMarkerMovePositionHArray(markerMovePositionHArray);
            tempMarker.setMarkerMovePositionVArray(markerMovePositionVArray);


            var markerParams = '{"stop":{"id":'+info.id+',"title":"'+info.name+'"}}';
            markerParams = encodeURIComponent(markerParams);
            tempMarker.setParams(markerParams);
            tempMarker.setDetailUrl(this.mapObj.getMultiMarkerUrl());

            this.mapObj.addMarker(tempMarker);

         }.bind(this));

         if ( cmd != 'clear' ) {
            this.mapObj.zoom2AllMarker();
            // this.mapObj.setMapPosition(this.centerObj.x,this.centerObj.y);
         }

         // Show selected Stop if available
         this.updateSavedStops();

      } catch(error) {
         this.write2Debug('stationsMapObj.showStopMarker',error);
      }

   },
   writeSession: function(url) {

      try {

         if ( url.empty() ) {
            return false;
         }

         new Ajax.Request(url, {
           method: 'get',
           onSuccess: function(transport) {

               this.updateSavedStops();

           }.bind(this)
         });

         return true;

      } catch(error) {
         this.write2Debug('stationsMapObj.writeSession',error);
      }

   },
   updateSavedStops: function() {

      try {

         var requestParams = '';

         new Ajax.Request(this.stopScriptsURL, {
           method: 'get',
           parameters: {
            cmd: 'get'
           },
           onSuccess: function(transport) {

            try {

              if (transport.responseJSON) {

               if ( transport.responseJSON.from || transport.responseJSON.to ) {

                  // start writing url params
                  requestParams = '';
                  requestParams += '?tx_vrsstations_pi_details[piType]=searchmask';

                  if ( transport.responseJSON.from ) {

                     // if there is valid From-Stop
                     if ( parseInt(transport.responseJSON.from.id,10) > 0 && transport.responseJSON.from.title != '' ) {

                        this.selectedFrom.id = parseInt(transport.responseJSON.from.id,10);
                        this.selectedFrom.title = transport.responseJSON.from.title;
                        this.selectedFrom.city = transport.responseJSON.from.city;
                        this.selectedFrom.district = transport.responseJSON.from.district;
                        this.selectedFrom.x = parseFloat(transport.responseJSON.from.x);
                        this.selectedFrom.y = parseFloat(transport.responseJSON.from.y);

                        requestParams += '&tx_vrsstations_pi_details[from][assID]='+this.selectedFrom.id;
                        requestParams += '&tx_vrsstations_pi_details[from][title]='+this.selectedFrom.title;
                        requestParams += '&tx_vrsstations_pi_details[from][district]='+this.selectedFrom.district;
                        requestParams += '&tx_vrsstations_pi_details[from][city]='+this.selectedFrom.city;

                        $('stopFrom_'+this.cObjID).innerHTML = this.selectedFrom.title;
                        $('deleteStopFrom_'+this.cObjID).show();

                     } else {

                        this.selectedFrom = {};
                        $('stopFrom_'+this.cObjID).innerHTML = '';
                        $('deleteStopFrom_'+this.cObjID).hide();

                     }

                  } else {

                     this.selectedFrom = {};
                     $('stopFrom_'+this.cObjID).innerHTML = '';
                     $('deleteStopFrom_'+this.cObjID).hide();

                  }


                  if ( transport.responseJSON.to ) {

                     // if there is valid To-Stop
                     if ( parseInt(transport.responseJSON.to.id,10) > 0 && transport.responseJSON.to.title != '' ) {

                        this.selectedTo.id = parseInt(transport.responseJSON.to.id,10);
                        this.selectedTo.title = transport.responseJSON.to.title;
                        this.selectedTo.city = transport.responseJSON.to.city;
                        this.selectedTo.district = transport.responseJSON.to.district;
                        this.selectedTo.x = parseFloat(transport.responseJSON.to.x);
                        this.selectedTo.y = parseFloat(transport.responseJSON.to.y);

                        requestParams += '&tx_vrsstations_pi_details[to][assID]='+this.selectedTo.id;
                        requestParams += '&tx_vrsstations_pi_details[to][title]='+this.selectedTo.title;
                        requestParams += '&tx_vrsstations_pi_details[to][district]='+this.selectedTo.district;
                        requestParams += '&tx_vrsstations_pi_details[to][city]='+this.selectedTo.city;

                        $('stopTo_'+this.cObjID).innerHTML = this.selectedTo.title;
                        $('deleteStopTo_'+this.cObjID).show();

                     } else {

                        this.selectedTo = {};
                        $('stopTo_'+this.cObjID).innerHTML = '';
                        $('deleteStopTo_'+this.cObjID).hide();

                     }

                  } else {

                     this.selectedTo = {};
                     $('stopTo_'+this.cObjID).innerHTML = '';
                     $('deleteStopTo_'+this.cObjID).hide();

                  }


                  $('ftsLabelBox').hide();
                  $('fromToStopsID').style.width = '262px';
                  $('ftsSwitchBox').show();

                  $('searchConnectionImgIA').hide();

                  $('searchButton').href = encodeURI(this.realDetailURL+requestParams);
                  $('searchButton').show();


               } else {

                  this.selectedFrom = {};
                  this.selectedTo = {};

                  $('searchConnectionImgIA').show();
                  $('searchButton').hide();

                  $('ftsLabelBox').show();
                  $('fromToStopsID').style.width = '200px';
                  $('ftsSwitchBox').hide();

                  $('stopFrom_'+this.cObjID).innerHTML = '';
                  $('stopTo_'+this.cObjID).innerHTML = '';

                  $('deleteStopFrom_'+this.cObjID).hide();
                  $('deleteStopTo_'+this.cObjID).hide();

               }

            }

               // Set Marker for selected Stops
               this.showSelectedStops();

            } catch(error) {
               this.write2Debug('stationsMapObj.updateSavedStops:onsuccess',error);
            }

           }.bind(this),
           onFailure : function(failure) {

           }.bind(this),
           onException: function(exception) {

           }.bind(this)

         });

      }catch(error) {
         this.write2Debug('stationsMapObj.updateSavedStops',error);
      }

   },
   showSelectedStops: function() {

      try {

         var markerParams = '';
         var tempMarker = {};

         // show From-Stop if available
         if ( this.selectedFrom.id > 0 && this.selectedFrom.x > 0 && this.selectedFrom.y > 0 ) {

            // check if marker exists
            tempMarker = this.mapObj.getMarkerFromList('stoppoint['+this.selectedFrom.id+']');
            if (tempMarker) {
               this.mapObj.removeMarker('stoppoint['+this.selectedFrom.id+']');
            }

            tempMarker = this.mapObj.getMarkerFromList('frompoint');
            if (tempMarker) {
               this.mapObj.removeMarker('frompoint');
            }

            tempMarker = {};

            tempMarker = new sbsMarker('frompoint','stoppoint', new sbsGKPoint(this.selectedFrom.x,this.selectedFrom.y,0),null,null);

            center_icons = new Array();
            center_icons[0] = from_icon_stop_16;
            center_icons[1] = from_icon_stop_16;
            center_icons[2] = from_icon_stop_16;
            center_icons[3] = from_icon_stop_24;
            center_icons[4] = from_icon_stop_24;
            center_icons[5] = from_icon_stop_30;
            center_icons[6] = from_icon_stop_30;
            center_icons[7] = from_icon_stop_30;
            center_icons[8] = from_icon_stop_30;
            tempMarker.setIconArray(center_icons);

            center_icons = new Array();
            center_icons[0] = from_icon_stop_16_hover;
            center_icons[1] = from_icon_stop_16_hover;
            center_icons[2] = from_icon_stop_16_hover;
            center_icons[3] = from_icon_stop_24_hover;
            center_icons[4] = from_icon_stop_24_hover;
            center_icons[5] = from_icon_stop_30_hover;
            center_icons[6] = from_icon_stop_30_hover;
            center_icons[7] = from_icon_stop_30_hover;
            center_icons[8] = from_icon_stop_30_hover;
            tempMarker.setHoverArray(center_icons);

            tempMarker.setMarkerMovePositionHArray(markerMovePositionHArray);
            tempMarker.setMarkerMovePositionVArray(markerMovePositionVArray);


            markerParams = '{"stop":{"id":'+this.selectedFrom.id+',"title":"'+this.selectedFrom.title+'","city":"'+this.selectedFrom.city+'","district":"'+this.selectedFrom.district+'","x":'+this.selectedFrom.x+',"y":'+this.selectedFrom.y+'}}';
            markerParams = encodeURIComponent(markerParams);
            tempMarker.setParams(markerParams);
            tempMarker.setDetailUrl(this.mapObj.getMultiMarkerUrl());

            this.mapObj.addMarker(tempMarker);

         } else {

            // no selected 'From'; remove marker available
            tempMarker = this.mapObj.getMarkerFromList('frompoint');
            if (tempMarker) {
               this.mapObj.removeMarker('frompoint');
            }

         }


         // show From-Stop if available
         if ( this.selectedTo.id > 0 && this.selectedTo.x > 0 && this.selectedTo.y > 0 ) {

            // check if marker exists
            tempMarker = this.mapObj.getMarkerFromList('stoppoint['+this.selectedTo.id+']');
            if (tempMarker) {
               this.mapObj.removeMarker('stoppoint['+this.selectedTo.id+']');
            }
            tempMarker = this.mapObj.getMarkerFromList('topoint');
            if (tempMarker) {
               this.mapObj.removeMarker('topoint');
            }

            tempMarker = {};

            tempMarker = new sbsMarker('topoint','stoppoint', new sbsGKPoint(this.selectedTo.x,this.selectedTo.y,0),null,null);

            center_icons = new Array();
            center_icons[0] = to_icon_stop_16;
            center_icons[1] = to_icon_stop_16;
            center_icons[2] = to_icon_stop_16;
            center_icons[3] = to_icon_stop_24;
            center_icons[4] = to_icon_stop_24;
            center_icons[5] = to_icon_stop_30;
            center_icons[6] = to_icon_stop_30;
            center_icons[7] = to_icon_stop_30;
            center_icons[8] = to_icon_stop_30;
            tempMarker.setIconArray(center_icons);

            center_icons = new Array();
            center_icons[0] = to_icon_stop_16_hover;
            center_icons[1] = to_icon_stop_16_hover;
            center_icons[2] = to_icon_stop_16_hover;
            center_icons[3] = to_icon_stop_24_hover;
            center_icons[4] = to_icon_stop_24_hover;
            center_icons[5] = to_icon_stop_30_hover;
            center_icons[6] = to_icon_stop_30_hover;
            center_icons[7] = to_icon_stop_30_hover;
            center_icons[8] = to_icon_stop_30_hover;
            tempMarker.setHoverArray(center_icons);

            tempMarker.setMarkerMovePositionHArray(markerMovePositionHArray);
            tempMarker.setMarkerMovePositionVArray(markerMovePositionVArray);


            markerParams = '{"stop":{"id":'+this.selectedTo.id+',"title":"'+this.selectedTo.title+'","city":"'+this.selectedTo.city+'","district":"'+this.selectedTo.district+'","x":'+this.selectedTo.x+',"y":'+this.selectedTo.y+'}}';
            markerParams = encodeURIComponent(markerParams);
            tempMarker.setParams(markerParams);
            tempMarker.setDetailUrl(this.mapObj.getMultiMarkerUrl());

            this.mapObj.addMarker(tempMarker);

         } else {

            // no selected 'From'; remove marker available
            tempMarker = this.mapObj.getMarkerFromList('topoint');
            if (tempMarker) {
               this.mapObj.removeMarker('topoint');
            }

         }


      }catch(error) {
         this.write2Debug('stationsMapObj.showSelectedStops',error);
      }

   },
   showBigDetails: function(detailURL) {

      try {

         $('sbsContent').setStyle({
            width: '600px'
         });

         $('sbsContent').innerHTML = this.loadingContent;
         sbsLightBox.resizePopup('loadingDiv',0);
         sbsLightBox.setPopUpPosition();
         sbsLightBox.show();


         new Ajax.Updater('sbsContent',detailURL,{
            evalScripts: true,
            onComplete: function() {

               // sbsLightBox.resizePopup('bigDetail');
               var platform = this.checkPlatform();

               switch(platform) {

                  default:
                  case 'win':

                  break;

                  case 'mac':

                     $('bClose').style.right = 'auto';
                     $('bClose').style.left = '-24px';

                  break;



               }

               sbsLightBox.resizePopup('bigDetail',48);
               sbsLightBox.setPopUpPosition();

               $('bClose').show();


            }.bind(this)
         });

      } catch(error) {
         this.write2Debug('stationsMapObj.showBigDetails',error);
      }

   },
   checkPlatform: function() {

      try {

         var platform = navigator.platform;
         var result = 0;


         result = platform.search(/Win/);

         if (result > -1) {
            return 'win';
         }

         result = platform.search(/Mac/);

         if (result > -1) {
            return 'mac';
         }

         // linux or something ...
         return 'win';

      } catch(error) {
         this.write2Debug('stationsMapObj.checkPlatform',error);
      }

   },
   move2Stop: function(stop) {

      try {

         var tempMarker = {};

         switch(stop) {

            case 'from':

               tempMarker = this.mapObj.getMarkerFromList('frompoint');
               if (tempMarker) {
                  this.mapObj.scroll2Marker('frompoint');
               }

            break;

            case 'to':

               tempMarker = this.mapObj.getMarkerFromList('topoint');
               if (tempMarker) {
                  this.mapObj.scroll2Marker('topoint');
               }

            break;

         }

      } catch(error) {
         this.write2Debug('stationsMapObj.move2Stop',error);
      }
   },
   showSearchForm: function(href) {

      try {

         if ( href.empty() || href == '#') {
            return null;
         }

         $('sbsContent').setStyle({
            width: '451px'
         });


         $('sbsContent').innerHTML = this.loadingContent;
         sbsLightBox.resizePopup('loadingDiv',0);
         sbsLightBox.setPopUpPosition();
         sbsLightBox.show();


         new Ajax.Updater('sbsContent',href,{
            evalScripts: true,
            onComplete: function() {

             sbsLightBox.resizePopup('searchMask',0);
             sbsLightBox.setPopUpPosition();

            }.bind(this)
         });

         return true;

      } catch(error) {
         this.write2Debug('stationsMapObj.showSearchForm',error);
      }

   },
   showHelp: function() {

      try {

         $('sbsContent').setStyle({
            width: '600px'
         });

         $('sbsContent').innerHTML = this.loadingContent;
         sbsLightBox.resizePopup('loadingDiv',0);
         sbsLightBox.setPopUpPosition();
         sbsLightBox.show();

         new Ajax.Updater('sbsContent',this.realDetailURL,{
            evalScripts: true,
            parameters: {
               'tx_vrsstations_pi_details[piType]': 'helpBox'
            },
            onComplete: function() {

               try {

                  // sbsLightBox.resizePopup('bigDetail');
                  var platform = this.checkPlatform();

                  switch(platform) {

                     default:
                     case 'win':

                     break;

                     case 'mac':

                        $('bClose').style.right = 'auto';
                        $('bClose').style.left = '-24px';

                     break;


                  }

                  sbsLightBox.resizePopup('bigDetail',32);
                  sbsLightBox.setPopUpPosition();

                  $('bClose').show();

               } catch(error) {
                  this.write2Debug('stationsMapObj.showHelp:ajax:onsuccess',error);
               }


            }.bind(this)
         });


      } catch(error) {
         this.write2Debug('stationsMapObj.showHelp',error);
      }

   },
   changeSavedStops: function(cmd) {

      try {

         if ( cmd.empty() ) {
            return false;
         }

         switch(cmd) {

            case 'from':

               new Ajax.Request(this.stopScriptsURL, {
                 method: 'get',
                 parameters: {
                  cmd: 'deleteFrom'
                 },
                 onSuccess: function(transport) {

                     this.write2Debug('stationsMapObj.changeSavedStops','delete from success');

                     this.updateSavedStops();


                 }.bind(this)
               });


            break;

            case 'to':

               new Ajax.Request(this.stopScriptsURL, {
                 method: 'get',
                 parameters: {
                  cmd: 'deleteTo'
                 },
                 onSuccess: function(transport) {

                     this.write2Debug('stationsMapObj.changeSavedStops','delete to success');

                     this.updateSavedStops();

                 }.bind(this)
               });


            break;

            case 'switch':

               new Ajax.Request(this.stopScriptsURL, {
                 method: 'get',
                 parameters: {
                  cmd: 'switchFromTo'
                 },
                 onSuccess: function(transport) {
                     this.updateSavedStops();
                 }.bind(this)
               });

            break;


         }

         return true;

      } catch(error) {
         this.write2Debug('stationsMapObj.changeSavedStops',error);
      }

   },
   write2Debug: function(functionName,errorMessage) {

      try {

         if ( $('debug') ) {
            $('debug').innerHTML += functionName+': '+errorMessage+'<br />';
         }

      } catch(error) {

      }

   },
   dragEndCallBack: function(zoomLevel,centerPoint) {

      var newDrag = new Date().getTime();

      this.dragOldTS = this.dragNewTS;
      this.dragNewTS = newDrag;

      zoomLevel = parseInt(zoomLevel);

      this.slowDown.bind(this).delay(0.75,newDrag,zoomLevel,centerPoint.rw,centerPoint.hw,this.defaultRadius,'clear');

      // $('debug').innerHTML += this.lastDragTS+'<br />';


   },
   zoomEndCallBack: function(zoomLevel,centerPoint,cmd) {

      switch(zoomLevel) {

         case 1:
            this.getStopsAround(centerPoint.rw,centerPoint.hw,4000,cmd);
         break;

         case 2:
            this.getStopsAround(centerPoint.rw,centerPoint.hw,3000,cmd);
         break;

         case 3:
            this.getStopsAround(centerPoint.rw,centerPoint.hw,2000,cmd);
         break;

         case 4:
            this.getStopsAround(centerPoint.rw,centerPoint.hw,1800,cmd);
         break;

         case 5:
            this.getStopsAround(centerPoint.rw,centerPoint.hw,1600,cmd);
         break;

         case 6:
            this.getStopsAround(centerPoint.rw,centerPoint.hw,800,cmd);
         break;

         case 7:
            this.getStopsAround(centerPoint.rw,centerPoint.hw,600,cmd);
         break;

      }

      return true;


   },
   slowDown: function(dragTS,zoomLevel,rw,hw,radius,cmd) {

      if (dragTS < this.dragNewTS) {
         return null;
      }

      switch(zoomLevel) {

         case 1:
            this.getStopsAround(rw,hw,4400,cmd);
         break;

         case 2:
            this.getStopsAround(rw,hw,4000,cmd);
         break;

         case 3:
            this.getStopsAround(rw,hw,3000,cmd);
         break;

         case 4:
            this.getStopsAround(rw,hw,2200,cmd);
         break;

         case 5:
            this.getStopsAround(rw,hw,1600,cmd);
         break;

         case 6:
            this.getStopsAround(rw,hw,800,cmd);
         break;

         case 7:
            this.getStopsAround(rw,hw,600,cmd);
         break;

      }

      return true;

   },
   resetCenterMarker: function() {

      // reset Centermarker
      var tempMarker
      var markerID = '';

      if (this.centerObj.id > 0) {
         markerID = 'centerpoint['+this.centerObj.id+']';
      } else {
         markerID = 'centerpoint[address]';
      }


      tempMarker = this.mapObj.getMarkerFromList('centerpoint['+this.centerObj.id+']');
      if ( tempMarker ) {
         this.mapObj.removeMarker('centerpoint['+this.centerObj.id+']');
      }

      tempMarker = this.mapObj.getMarkerFromList('centerpoint[address]');
      if ( tempMarker ) {
         this.mapObj.removeMarker('centerpoint[address]');
      }


      tempMarker = new sbsMarker(markerID,'centerpoint', new sbsGKPoint(this.centerObj.x,this.centerObj.y,0),null,null );

      var center_icons = new Array();
      var center_icons_hover = new Array();

      switch(this.centerObj.type) {

         case 'stop':

            center_icons[0] = icon_stop_center_16;
            center_icons[1] = icon_stop_center_16;
            center_icons[2] = icon_stop_center_16;
            center_icons[3] = icon_stop_center_24;
            center_icons[4] = icon_stop_center_24;
            center_icons[5] = icon_stop_center_30;
            center_icons[6] = icon_stop_center_30;
            center_icons[7] = icon_stop_center_30;
            center_icons[8] = icon_stop_center_30;

            center_icons_hover[0] = icon_stop_center_16_hover;
            center_icons_hover[1] = icon_stop_center_16_hover;
            center_icons_hover[2] = icon_stop_center_16_hover;
            center_icons_hover[3] = icon_stop_center_24_hover;
            center_icons_hover[4] = icon_stop_center_24_hover;
            center_icons_hover[5] = icon_stop_center_30_hover;
            center_icons_hover[6] = icon_stop_center_30_hover;
            center_icons_hover[7] = icon_stop_center_30_hover;
            center_icons_hover[8] = icon_stop_center_30_hover;

            var markerParams = '{"stop":{"id":'+this.centerObj.id+',"title":"'+this.centerObj.label+'"}}';

            markerParams = encodeURIComponent(markerParams);

            tempMarker.setParams(markerParams);

            tempMarker.setDetailUrl(this.mapObj.getMultiMarkerUrl());


         break;

         case 'address':

            center_icons[1] = icon_address_center_16;
            center_icons[2] = icon_address_center_16;
            center_icons[3] = icon_address_center_24;
            center_icons[4] = icon_address_center_24;
            center_icons[5] = icon_address_center_30;
            center_icons[6] = icon_address_center_30;
            center_icons[7] = icon_address_center_30;
            center_icons[8] = icon_address_center_30;

            center_icons_hover[0] = icon_address_center_16_hover;
            center_icons_hover[1] = icon_address_center_16_hover;
            center_icons_hover[2] = icon_address_center_16_hover;
            center_icons_hover[3] = icon_address_center_24_hover;
            center_icons_hover[4] = icon_address_center_24_hover;
            center_icons_hover[5] = icon_address_center_30_hover;
            center_icons_hover[6] = icon_address_center_30_hover;
            center_icons_hover[7] = icon_address_center_30_hover;
            center_icons_hover[8] = icon_address_center_30_hover;

         break;

      }

      tempMarker.setIconArray(center_icons);
      tempMarker.setHoverArray(center_icons_hover);
      tempMarker.setMarkerMovePositionHArray(markerMovePositionHArray);
      tempMarker.setMarkerMovePositionVArray(markerMovePositionVArray);

      // tempMarker.setDetailUrl(this.stationDetailURL+'&tx_vrsstations_pi_details[stop][id]='+id+'&tx_vrsstations_pi_details[stop][title]='+encodeURIComponent(label) );

      this.mapObj.addMarker(tempMarker);


   }
};



sbsLightBox = {
	mainElement : 'pageBoxFS',
	popUpWidth: 560,
	popUpHeight: 44,
	show: function() {

      try {

         this.setCurtain();
         this.hideContent();
         this.showPopUp();

      } catch(error) {
         this.write2Debug('sbsLightBox.show',error);
      }

	},
	hideContent: function() {
		try {

			if ( $('sbsLightBoxCurtain') ) {

				$('sbsLightBoxCurtain').show();

			} else {

				$(this.mainElement).insert({bottom: '<div id="sbsLightBoxCurtain"><\/div>'});
				$($('sbsLightBoxCurtain')).clonePosition($(this.mainElement));

			}

		} catch(error) {
         this.write2Debug('sbsLightBox.hideContent',error);
		}
	},
	showPopUp: function() {
		try {

			if ( $('sbsLightBoxPopUp') ) {
				$('sbsLightBoxPopUp').show();
            this.setPopUpPosition();
			} else {

				if ( $('sbsLightBoxCurtain') ) {

					$('sbsLightBoxCurtain').insert({after: '<div id="sbsLightBoxPopUp"><div id="sbsHead"><span onclick="sbsLightBox.close();" style="cursor: pointer;" class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-close"></span><\/div><div id="sbsContent"><\/div>'});

				} else {

					this.hideContent();
					$('sbsLightBoxCurtain').insert({after: '<div id="sbsLightBoxPopUp"><div id="sbsHead"><span onclick="sbsLightBox.close();" style="cursor: pointer;" class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-close"><\/span><\/div><div id="sbsContent"><\/div>'});

				}

				this.setPopUpPosition();


			}


		} catch(error) {
         this.write2Debug('sbsLightBox.showPopUp',error);
		}


	},
	setPopUpPosition: function() {

		try {

			var mainWidth = $(this.mainElement).getWidth();
			var popUpWidth = $('sbsContent').getWidth();
			var newLeft = parseInt( parseInt(mainWidth,10) - parseInt(popUpWidth,10) ,10);
			newLeft = parseInt(newLeft / 2, 10);

			var mainheight = $(this.mainElement).getHeight();
			var popUpHeight = $('sbsContent').getHeight();
			var newTop = parseInt( parseInt(mainheight,10) - parseInt(popUpHeight,10) ,10);
			newTop = parseInt(newTop / 3, 10);

			newTop += 6;


			$('sbsContent').setStyle({
				top: newTop+'px'
			});

		}catch (error) {
         this.write2Debug('sbsLightBox.setPopUpPosition',error);
		}

	},
	close: function() {

      try {

         if ($('sbsLightBoxPopUp')) {
            $('sbsLightBoxPopUp').hide();
         }

         if ($('sbsLightBoxCurtain')) {
            $('sbsLightBoxCurtain').hide();
         }

         this.closeCallBackFunction();

		} catch (error) {
         this.write2Debug('sbsLightBox.close',error);
		}

	},
	closeCallBackFunction: function() {

		// overwrite this function to call js on closing the popUp
      try {


		} catch (error) {
         this.write2Debug('sbsLightBox.closeCallBackFunction',error);
		}

	},
	resize: function() {

      try {

         // set Size and Position of the half transparent Layer
         this.setCurtain();

		} catch (error) {
         this.write2Debug('sbsLightBox.resize',error);
		}

	},
	setCurtain: function() {

		try {

			if ( $('sbsLightBoxCurtain') ) {

				var dimensions = $(this.mainElement).getDimensions();

				$('sbsLightBoxCurtain').setStyle({
					height: dimensions.height+'px'
				});

			}

		} catch(error) {
         this.write2Debug('sbsLightBox.setCurtain',error);
		}

	},
	resizePopup: function(elementID,addHeight) {

      try {

         // if popup is heigher than viewport -> resize
         var viewPortHeight = parseInt(document.viewport.getHeight(), 10);
         var popUpHeight = parseInt($('sbsContent').getHeight(), 10);

         var contentInnerHeight = parseInt(	$(elementID).getHeight(), 10);

         addHeight = parseInt(addHeight,10)

         $('sbsContent').setStyle({
            height: contentInnerHeight+addHeight+'px'
         });

         if (popUpHeight > (viewPortHeight-20) ) {

            $('sbsContent').setStyle({
               height: viewPortHeight-40+'px'
            });

            if (elementID != null) {
               if ($(elementID)) {
                  $(elementID).setStyle({
                     height: viewPortHeight-40+'px'
                  });
               }
            }

         }

		} catch(error) {
         this.write2Debug('sbsLightBox.resizePopup',error);
		}

	},
   write2Debug: function(functionName,errorMessage) {

      try {

         if ( $('debug') ) {
            $('debug').innerHTML += functionName+': '+errorMessage+'<br />';
         }

      } catch(error) {

      }

   }
};



try {

   Event.observe(window,'resize',function(){
      sbsLightBox.resize();
   });

} catch(error) {

//   if ( $('debug') ) {
//      $('debug').innerHTML += 'Event.observe(window.resize): '+error+'<br />';
//   }

}

function submitSearchForm(form,startID,endID) {

   try {

      var nv = form.START.value;
      nv = '[HST]'+nv+':'+startID;
      form.START.value = nv;
      form.STARTGEMEINDE.value = '';

      nv = form.ZIEL.value;
      nv = '[HST]'+nv+':'+endID;
      form.ZIEL.value = nv;
      form.ZIELGEMEINDE.value = '';

      window.open('','timeTable');
      form.target='timeTable';
      form.submit();

      sbsLightBox.close();

   }catch (error) {

      if ( $('debug') ) {
         $('debug').innerHTML += 'submitSearchForm: '+error+'<br />';
      }

   }



}


try {

	Ajax.Request.prototype.abort = function() {
	    // prevent and state change callbacks from being issued
	    this.transport.onreadystatechange = Prototype.emptyFunction;
	    // abort the XHR
	    this.transport.abort();
	    // update the request counter
	    Ajax.activeRequestCount--;
	};

} catch(error) {

}
