	stationListDefaultSearchTerm = 'Suche...';
	matchedStations = Array();
	var doSearchTimeout;
	
	
	/************************************
		initStationSearch
	
		sets up search form / functions
	*************************************/
	function initStationSearch() {
		
		// Hide advanced search infos
		$('#stationListSearchMoreInfosList').hide();
		
		// Hide 'cancel search' button
		$('#stationListSearchCancel').hide();
		$('#stationListSearchCancel').click(function(){
			cancelSearch(true);
		});
		
		// Hide 'no stations found' message
		$('#noStationsFoundMessage').hide();
		
		
		// Show form
		$('.stationListSearchForm').show(0);
		
		// Init advanced search infos toggle
		$('a#stationListSearchMoreInfos').click(function(){
			$('#stationListSearchMoreInfosList').slideToggle(200);
		});
		
		// Insert default search term
		$('input.stationListSearch').val(stationListDefaultSearchTerm);
		
		// FOCUS/BLUR of input field
		// default
		$('input.stationListSearch').attr('class','stationListSearch inactive');
		// focus
		$('input.stationListSearch').focus(function(){
			// Remove default search term?
			var currentValue = $('input.stationListSearch').val();
			if (currentValue == stationListDefaultSearchTerm) {
				$('input.stationListSearch').val('');
			}
			$('input.stationListSearch').attr('class','stationListSearch active');
		});
		// blur
		$('input.stationListSearch').blur(function(){
			// reset default search term?
			var currentValue = $('input.stationListSearch').val();
			if (currentValue == '') {
				$('input.stationListSearch').val(stationListDefaultSearchTerm);
			}
			$('input.stationListSearch').attr('class','stationListSearch inactive');
		});
		
		
		// Init search function
		$('input.stationListSearch').keyup(function(){
			
			$('#stationListSearchCancel').show();
			
			if (doSearchTimeout) {
				clearTimeout(doSearchTimeout);
			}
			
			doSearchTimeout = setTimeout(doSearch, 1000);
			
		});
		
		
		
		// Hide advanced station infos
		$('.stationDetailsAdvanced').hide();
		// Init show advanced station infos hover/toggle
		$('.station').mouseover(function(){
			$(this).find('.stationDetailsAdvanced').show();
		});
		$('.station').mouseleave(function(){
			$(this).find('.stationDetailsAdvanced').hide();
		});
		
		
	} // function initStationSearch
	
		

		
	
	
	
	/************************************
		doSearch
	
		executes search based on
		current search field content
	*************************************/
	function doSearch() {
		
		var searchwords = $('input.stationListSearch').val();
		var minimumSearchTermLength = 2;
		var minimumSearchTermLengthToSearchInSubstrings = 3;
		var numberOfShownStations = 0;
		var numberOfHiddenStations = 0;
		
		
		// Show station if search term is empty 
		if (searchwords == '') {
			cancelSearch(false);
			return;
		}
			
		// Fade out 'no stations found message'
		$('#noStationsFoundMessage').fadeOut(200);
		
		searchwords = searchwords.toLowerCase();
		var searchwords = searchwords.split(" ");
		var numberOfSearchwords = searchwords.length;		
		
			
		// Go through the find-words of every station and compare with
		// entered search words
		for (stationNo in stationSearchTerms) {			
			
			var numberOfMatchedSearchwords = 0;
			var findwords = stationSearchTerms[stationNo].split(' ');
			
			// Go through every searchword and 'validate'
			searchword_loop:
			for (searchwordNo in searchwords) {
				
				var searchword = searchwords[searchwordNo].toLowerCase();
				var searchwordLength = searchword.length;
				
				// Validate search word
				if (searchwordLength < minimumSearchTermLength) {
					continue;
				}
				
				// Only allow searchwords whose string length equals the minimum characters,
				// if they appear as single find words. i.e. 'BE' will be found in 'BE Zollikofen'
				// but not in 'Bern'
				var findSubstring = false;
				if (searchwordLength >= minimumSearchTermLengthToSearchInSubstrings) {
					findSubstring = true;
				}
				
				var wordFound = false;
				for (findwordNo in findwords) {
					var findword = findwords[findwordNo].toLowerCase();
					
					if (findSubstring) {
						var wordFound = findword.indexOf(searchword);
					
					} else if(findword == searchword) {
						numberOfMatchedSearchwords = searchwords.length;
						// Treat a found, single searchword as full hit
						// i.e. searching for 'car' in 'my car is red' is a hit like this,
						// but not in 'my credit card rocks'.
						break searchword_loop;
					}
					
					if (wordFound > -1 && wordFound !== false) {
						numberOfMatchedSearchwords++;
						break;
					}
				} // for findwords
				
			} // for searchwords
			
			
			
			var showStation = false;
			if (numberOfMatchedSearchwords >= numberOfSearchwords) {
				showStation = true;
			}
			
			
			if (showStation) {
				numberOfShownStations++;
				showStationDetails(stationNo);
			} else {
				numberOfHiddenStations++;
				hideStationDetails(stationNo);
			}
			
		} // for stations
		
		
		// Message (no stations found)
		if (numberOfShownStations == 0) {
			$('#noStationsFoundMessage').fadeIn(200);
		}
		
		// Add CSSS class 'is filtered' to list
		if (numberOfHiddenStations > 0) {
			$('.stationList').addClass('isFiltered');
		}
			
			
	} // function doSearch
		
	
	
	
	/************************************
		showStationDetails /
		hideStationDetails
	
		fade in / out functions for
		station details
	*************************************/
	function showStationDetails(stationNo) {
		stationNo = String(stationNo);
		$('#stationDetails'+stationNo).show();
	} // function showStation
	function hideStationDetails(stationNo) {
		stationNo = String(stationNo);
		$('#stationDetails'+stationNo).hide();
	} // function showStation
	
		
		
		
	/************************************
		cancelSearch
	
		resets search form / results
	*************************************/
	function cancelSearch(resetFormToo) {
		
		if (resetFormToo) {
			$('input.stationListSearch').blur();
			$('input.stationListSearch').val(stationListDefaultSearchTerm);
		}
		
		$('.stationList').removeClass('isFiltered');
		$('#noStationsFoundMessage').fadeOut(200);
		$('#stationListSearchCancel').fadeOut(200);
		$('.station').show();
		
	} // function cancelSearch
		
		
		
