var mapZoomCollapsButtonLabels = new Array();
mapZoomCollapsButtonLabels[0] = "expand map"; // default value 
mapZoomCollapsButtonLabels[1] = "collapse map";	// default value

function setZoomButtonLabels( expandLabel, collapseLabel ){
	mapZoomCollapsButtonLabels[0] = expandLabel;
	mapZoomCollapsButtonLabels[1] = collapseLabel;
}

$(document).ready(function(){
    var mapZoomCollapsButtonLabels = new Array();
    mapZoomCollapsButtonLabels[0] = "expand map"; // default value 
    mapZoomCollapsButtonLabels[1] = "collapse map";	// default value 
        
   /*SUGGESTIONS*/
    

    $.get("index.php?id=630&type=555", function(data){
    	var suggestions = $(data).text();
    	searchfield(suggestions);
    });
    

    /*TEASER*/
	$(".teasercontainer .teaser").click( function () { 
		var target = $( "a", this ).attr("target");
		var url = $( "a", this ).attr("href");
		var pre = ( url.search(/http:/i) == -1 ) ? "/" : "";
		if( target == "_blank" ) {
			window.open( pre+url );
		} else {
			window.location.href = pre+url;
		}
		return false;
	});
     
    /*Small Teaser*/
	$('.smallteaser').mouseover( function() {
		$('span', this).css('display','block');
	});
	$('.smallteaser').mouseout( function() {
		$('span', this).css('display','none');
	});

    /*FORM*/
 	if( !$.browser.msie || parseInt( jQuery.browser.version ) != 6 ) {
	  	$('#finder form fieldset').hide();	
	  	$('#finder form fieldset.findersubmit').show();
	
		$selectCounter = 0;
	
		$('#finder form fieldset select').each(function(){
			$itemCounter = 0;
			$list = "";
			$list += "<div class='finderitem'>";
			$list += "<h3>" + $(this).siblings().text() + "</h3>";
			$list += "<div id="+ $selectCounter + " class='select'>";
			$list += "<ul>";
	    	$('option', this).each(function(){
	    		var active = $(this).attr('selected') == true ? 'class="active"' : '';
	    		$list += "<li><a id=" + $itemCounter +" "+active+">" + $(this).text() + "</a></li>";
	    		$itemCounter++;
	    	});
			$list += "</ul></div></div>";
	    	$('#finder form').before($list);
			$selectCounter++;
		});
	
		$('.career form fieldset input.careersearch').each(function(){
			$list = "<div class='finderitem'>";
			$list += "<h3>" + $(this).siblings().text() + "</h3>";
			$list += '<input class="careersearch" name="kw" value="" type="text"/>';
			$list += "</div>";
			$('#finder form').before($list);
		});
	}
	
    $('.clear').click(function(){
    	$('.select a.active').click();
    	$(".career div .careersearch").attr('value', "");
    	return false;
    });
    
    $('div.select a').bind('click', onSelectItem);
    $('div.select a.active').unbind('click');
    $('div.select a.active').bind('click', onDeselectItem);
    
    function onSelectItem(){				
		$(this).addClass('active');
		$(this).unbind("click");
		$itemIndex = $(this).attr('id');
		$selectIndex = $(this).parent().parent().parent().attr('id');
		$('#finder form select').eq(parseInt($selectIndex)).children().eq(parseInt($itemIndex)).attr("selected", "selected");
		$(this).bind("click", onDeselectItem);
	}
	
	function onDeselectItem(){
		$(this).unbind("click");
		$itemIndex = $(this).attr('id');
		$selectIndex = $(this).parent().parent().parent().attr('id');
		$('#finder form select').eq(parseInt($selectIndex)).children().eq(parseInt($itemIndex)).attr("selected", "");
		$(this).removeClass('active');
		$(this).bind("click", onSelectItem);
	}
    
    
    /*MENU*/
    
	$('#menu').superfish({hoverClass:"active", delay: 200});
    
    
    /*TABMENU*/
   
    
    $('#content #tabmenu').children().wrapAll('<div class="tabcontent"></div>');
    //$('.tabcontent').children().find('div').hide(); 
    
    $tablist = '<ul class="tabs">';
    
    $('#content #tabmenu div a').each(function(){
    	if($(this).attr('name')){
    		$tablist += '<li><a>' + $(this).attr('name') + '</a></li>';
    	}
    });
    
    $tablist += '</ul>';
    
    $('#content #tabmenu').append($tablist);
    
    $('#content .tabs li a').click(function(){
    	$(this).addClass('active').parent().siblings().children().removeClass('active');
    	$target = $(this).text();
    	$('#tabmenu div a').each(function(){
    		if($(this).attr('name')==$target){
    			$(this).parent().siblings().hide();
    			$(this).parent().fadeIn();
    		}
    	});
    
    });
    
    $('.tabs a').eq(0).click();
    
    $('#moduletab .tabs li a').removeAttr('href');
    
    $('#moduletab .tabs li a').click(function(){
    	$(this).addClass('active').parent().siblings().children().removeClass('active');
    	$('#moduletab .tabcontent .hidden').siblings().hide();
    	$('#moduletab .tabcontent .hidden').fadeIn().removeClass('hidden').siblings().addClass('hidden');
    });
    
    
    /*MODULES*/
    
    $('.hide').bind('click', onHide).siblings().show();
    $('#accordeon a.show').bind('click', onShow).siblings().hide(); 
    $('#finder a.show').bind('click', onShow).siblings().hide();    
    $('.newsdownload a.show').bind('click', onShow).siblings().hide(); 
    $('#modules a.show').bind('click', onShowModule).siblings().hide();
    $('#modules a.hide').bind('click', onHideModule).siblings().show();
    
    //$('#accordeon div a').eq(0).click();  
    
    function onShow(){	
		$(this).siblings().show('normal');
		$(this).addClass('active').addClass('hide').removeClass('show');
		$(this).unbind("click");
		$(this).bind("click", onHide);
	}
	
	function onShowModule(){	
		$(this).siblings().slideDown('slow');
		$(this).addClass('active').addClass('hide').removeClass('show');
		$(this).unbind("click");
		$(this).bind("click", onHide);
	}
	
	function onHide(){
		$(this).unbind("click");
		$(this).siblings().slideUp('slow');
		$(this).removeClass("hide").removeClass('active').addClass("show");
		$(this).bind("click", onShowModule);
	}
	
	function onHideModule(){
		$(this).unbind("click");
		$(this).siblings().slideUp('slow');
		$(this).removeClass("hide").removeClass('active').addClass("show");
		$(this).bind("click", onShowModule);
	}
	
	
	/*GALLERY*/
	
	//$('.lightbox a').lightBox();
	

	/*MAP*/
	
	$('.zoom_button').bind('click', mapdown);
	$('.zoom_button').text( mapZoomCollapsButtonLabels[0] );
//	$('.en').text('expand map');
//	$('.de').text('karte vergrössern');
	
	function mapdown(){				
		$('#map').animate({height: "33.333em"}, 1000, 'linear', setTimeout("showController()", 1000));
		$(this).unbind("click");
		$('.zoom_button').text( mapZoomCollapsButtonLabels[1] );
//		$('.en').text('collapse map');
//		$('.de').text('karte verkleinern');
		$(this).bind("click", mapup);
	}
	
	function mapup(){
		$(this).unbind("click");
		hideController();
		$('#map').animate({height: "12.5em"}, 1000, 'linear', setTimeout("setCenter()", 1000));
		$('.zoom_button').text( mapZoomCollapsButtonLabels[0] );
//		$('.en').text('expand map');
//		$('.de').text('karte vergrössern');
		$(this).bind("click", mapdown);
	}
    
	// reset search field on country sites
	var searchText = $('#searchfield_country').attr('value');
	
	$('#searchfield_country').focus( function() {
		var val = ( $(this).attr('value') == "" || $(this).attr('value') == searchText ) ?  "" : $(this).attr('value');
		$(this).attr('value', val); 
	});
	$('#searchfield_country').blur( function() {
		var val = ( $(this).attr('value') != "" && $(this).attr('value') != searchText ) ?  $(this).attr('value') : searchText;
		$(this).attr('value', val); 
	});
	
});


this.syncTextfields = function (){
		$('.career form fieldset .careersearch').attr('value', ($(".career div .careersearch").attr('value')));
		//alert($('.career form fieldset .careersearch').attr('value'));	
}


/* 

	SearchField 
	written by Alen Grakalic, provided by Css Globe (cssglobe.com)
	please visit http://cssglobe.com/post/1202/style-your-websites-search-field-with-jscss/ for more info
	
*/

this.searchfield = function(text){
	
	// CONFIG 
	
	// this is id of the search field you want to add this script to. 
	// You can use your own id just make sure that it matches the search field in your html file.
	var id = "searchfield";	
	
	// set to either true or false
	// when set to true it will generate search suggestions list for search field based on content of variable below
	var suggestion = true;
	
	// static list of suggestion options, separated by comma
	// replace with your own
	//var suggestionText = (document.getElementById('suggestions').value).toString();
	var suggestionText = text;

	// END CONFIG (do not edit below this line, well unless you really, really want to change something :) )
	// Peace, 
	// Alen

	var field = document.getElementById(id);
	
	// Text you want to set as a default value of your search field.
	var defaultText = field.value;
		
	var classInactive = "sf_inactive";
	var classActive = "sf_active";
	var classText = "sf_text";
	var classSuggestion = "sf_suggestion";
	//alert(navigator.vendor.indexOf("Apple Computer, Inc.")!=-1);
	this.safari = ((parseInt(navigator.productSub)>=20020000)&&(navigator.vendor.indexOf("Apple Computer, Inc.")!=-1));
	//if(field && !safari){
	if(field){
		field.value = defaultText;
		field.c = field.className;		
		field.className = field.c + " " + classInactive;
		field.onfocus = function(){
			this.className = this.c + " "  + classActive;
			this.value = (this.value == "" || this.value == defaultText) ?  "" : this.value;
		};
		field.onblur = function(){
			this.className = (this.value != "" && this.value != defaultText) ? this.c + " " +  classText : this.c + " " +  classInactive;
			this.value = (this.value != "" && this.value != defaultText) ?  this.value : defaultText;
			clearList();
		};
		if (suggestion){
			
			var selectedIndex = 0;
						
			field.setAttribute("autocomplete", "off");
			var div = document.createElement("div");
			var list = document.createElement("ul");
			var sForm = $("form#search");
			list.style.display = "none";
			div.className = classSuggestion;
			//list.style.width = field.offsetWidth + "px";
			div.appendChild(list);
			field.parentNode.appendChild(div);	

			field.onkeypress = function(e){
				
				var key = getKeyCode(e);
		
				if(key == 13){ // enter
					selectList();
					selectedIndex = 0;
					return false;
				};	
			};
				
			field.onkeyup = function(e){
			
				var key = getKeyCode(e);
		
				switch(key){
				case 13:
					return false;
					break;			
				case 27:  // esc
					field.value = "";
					selectedIndex = 0;
					clearList();
					break;				
				case 38: // up
					navList("up");
					break;
				case 40: // down
					navList("down");		
					break;
				default:
					startList();			
					break;
				};
			};
			
			this.startList = function(){
				var arr = getListItems(field.value);
				if(field.value.length > 0){
					createList(arr);
				} else {
					clearList();
				};	
			};
			
			this.getListItems = function(value){
				var arr = new Array();
				var src = suggestionText;
				var src = src.replace(/, /g, ",");
				var arrSrc = src.split(",");
				for(i=0;i<arrSrc.length;i++){
					if(arrSrc[i].substring(0,value.length).toLowerCase() == value.toLowerCase()){
						arr.push(arrSrc[i]);
					};
				};				
				return arr;
			};
			
			this.createList = function(arr){				
				resetList();			
				if(arr.length > 0) {
					for(i=0;i<arr.length;i++){				
						li = document.createElement("li");
						a = document.createElement("a");
						a.href = "javascript:void(0);";
						a.i = i+1;
						a.innerHTML = arr[i];
						li.i = i+1;
						li.onmouseover = function(){
							navListItem(this.i);
						};
						a.onmousedown = function(){
							selectedIndex = this.i;
							selectList(this.i);		
							return false;
						};					
						li.appendChild(a);
						list.setAttribute("tabindex", "-1");
						list.appendChild(li);	
					};	
					list.style.display = "block";				
				} else {
					clearList();
				};
			};	
			
			this.resetList = function(){
				var li = list.getElementsByTagName("li");
				var len = li.length;
				for(var i=0;i<len;i++){
					list.removeChild(li[0]);
				};
			};
			
			this.navList = function(dir){			
				selectedIndex += (dir == "down") ? 1 : -1;
				li = list.getElementsByTagName("li");
				if (selectedIndex < 1) selectedIndex =  li.length;
				if (selectedIndex > li.length) selectedIndex =  1;
				navListItem(selectedIndex);
			};
			
			this.navListItem = function(index){	
				selectedIndex = index;
				li = list.getElementsByTagName("li");
				for(var i=0;i<li.length;i++){
					li[i].className = (i==(selectedIndex-1)) ? "selected" : "";
				};
			};
			
			this.selectList = function(){
				li = list.getElementsByTagName("li");	
				a = li[selectedIndex-1].getElementsByTagName("a")[0];
				field.value = a.innerHTML;
				clearList();
				sForm.submit();
			};			
			
		};
	};
	
	this.clearList = function(){
		if(list){
			list.style.display = "none";
			selectedIndex = 0;
		};
	};		
	this.getKeyCode = function(e){
		var code;
		if (!e) var e = window.event;
		if (e.keyCode) code = e.keyCode;
		return code;
	};
	
};

// script initiates on page load. 
/*
this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	};
};
addEvent(window,"load",searchfield);
*/
