Functions= {};
var visible ={
	'visibility' : 'visible',
	'display' : 'block'
}
var invisible = {
	'visibility' : 'visible',
	'display' : 'none'			
}

$(document).ready(function () {
		externalLinks();
		//Verlinkung von Grafiken
		$(".clickLink").click(			
			function()
			{
				//alert('clickLink');
			    window.location = $(this).attr("title");
		});
		
	
		
			
		//lightbox für contentbilder
		// -> aufgrund der mehrsprachigkeit werder nur mehr zeichen angezeigt
		$(".lightbox").lightbox(
			{
				strings : {
					help: ' \u2190 / P - &laquo;\u00a0\u00a0\u00a0\u00a0\u2192 / N - &raquo;\u00a0\u00a0\u00a0\u00a0ESC / X - Bildergalerie schliessen',
					prevLinkTitle: '&laquo;',
					nextLinkTitle: '&raquo;',
					prevLinkText:  '&laquo;',
					nextLinkText:  '&raquo;',
					closeTitle: 'X',
					image: ' ',
					of: ' / '
				}
			}		
		);
		
		
		//-----------------//	
		//akkordeon -------//
		//-----------------//
		$(".akkordeon").each(function(i){
			var shorttext = trim( $(this).children('.content').children('.longtext').children('.longtext_content').text().substring(0, 160) );						
			//alert(shorttext.length);
			if( shorttext.length != 0  ){ shorttext +=' ...'; }			
			$(this).children('.content').children('.shorttext').html( shorttext );
			
		});		
			
		$(".akkordeon").click(function(){			
			if( $(this).hasClass('active_akkordeon') ){				
				$(this).children('.content').animate({
					height: '25px'	
				}, 1000, 'swing', function() {
					//alert("fertig");
									
					$(this).children('.longtext').fadeOut( 500 );
					$(this).children('.shorttext').fadeIn( 500 );
					$(this).children('.button').addClass('button_open').removeClass('button_close');
					
				});						
				
				$(this).removeClass('active_akkordeon');
			}else{
				
				var textheight = $(this).children('.content').children('.longtext').height();
				
				$(this).children('.content').animate({
					height: textheight+50+'px' 
				}, 500, 'swing', function(){
							
					$(this).children('.button').addClass('button_close').removeClass('button_open');	
					$(this).children('.shorttext').fadeOut( 500 );					
					$(this).children('.longtext').fadeIn( 500 );
						
				});
								
				$(this).addClass('active_akkordeon');	
								
			}
						
		});	
		
		
		//-----------------//	
		//history - header //
		//-----------------//		
		$("#historyimages").slideView();		
		if( $("div#historyimages").length > 0  ){			
			window.setTimeout(function() { 					
				Functions.slideHeaderImages();
			}, 7000);
						
		}
		
		
		//--------------------------------//	
		//start - header - infobox -------//
		//--------------------------------//	
		if( $('#start_switchup_box') ){
			var height = $('#start_switchup_box .headline').height();
			$('#start_switchup_box').css('height', height );				
		}		
		$('#start_switchup_box').click(function(){
			//alert($('#start_switchup_box .text').height());
			
			if( $(this).children('.button').hasClass('button_down') ){
				var height = $('#start_switchup_box .headline').height();
				
				//$('#start_switchup_box').css('top', -( height + 30 ) );
				//$('#start_switchup_box').css('height', height );	
				$('#start_switchup_box').animate({
					height: height					
					},
					500,
					'swing'
				);
				
				$(this).children('.button').removeClass('button_down').addClass('button_up');	
			}else{
				
				var height = $('#start_switchup_box .headline').height() + $('#start_switchup_box .text').height(); 
				//$('#start_switchup_box').css('height', height+15 );
				$('#start_switchup_box').animate({
					height: height+15					
					},
					500,
					'swing'
				);	
				
				$(this).children('.button').removeClass('button_up').addClass('button_down');	
			
			}
		});
		
		
		//ie overeffect
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			$(".button").mouseover(
					function(){
						var height = $(this).height();
						//alert(height);
						$(this).css('background-position', '0 '+(-height));
						$(this).css('cursor','pointer');
					} 
			).mouseout(function(){
					$(this).css('background-position', '0 0');
			});
			$(".infobox2 .button").mouseover(
					function(){				
						$(this).css('background-position', '0 0');
						$(this).css('cursor','pointer');
					} 
			).mouseout(function(){
					var height = $(this).height();
					$(this).css('background-position', '0 '+(-height));
			});
					
			$(".search_submit").mouseover(
					function(){
						var height = $(this).height();
						//alert(height);
						$(this).css('background-position', '0 -42px');
						$(this).css('cursor','pointer');
					} 
			).mouseout(function(){
					$(this).css('background-position', '0 0');
			});
			$(".send").mouseover(
					function(){
						var height = $(this).height();
						//alert(height);
						$(this).css('background-position', '0 -25px');
						$(this).css('cursor','pointer');
					} 
			).mouseout(function(){
					$(this).css('background-position', '0 0');
			});
			
		}
	
		
						
});





Functions= {
	init: function(){
		//alert("init");
	},
	doFormCheck: function() {	
		var result = true;		
		//alert('doFormCheck');
		
		jQuery.each($('.required'),function() {
			//alert('required');
			if($(this).val() < 2 ){
				$(this).addClass("invalid");
				result=false;
			}else if($(this).hasClass("invalid")){$(this).removeClass("invalid");}		
		});
		
		return result;
	},
	slideHeaderImages: function(){
		
		var whole_width = $("div#historyimages ul").width();
		//alert( whole_width );
		var show_width = $("div#historyimages").width();
		//alert( show_width );
		var slide_width = "0px";
		slide_width = $("div#historyimages ul").css('left');
		
		slide_width = parseInt( slide_width.substring( 0, slide_width.indexOf('px') ));
		//alert( slide_width );
		var position = slide_width - show_width;
		//
		// alert( whole_width + position );
		if( whole_width + position <= 0){
			position = 0;
		}
		
		//alert( position );
		//$('div#historyimages ul').fadeOut( 500 );
		$('div#historyimages ul').animate({
			left: position+'px'
		}, 1500);
		//$('div#historyimages ul').fadeIn( 500 );
		
		window.setTimeout(function() { 					
			Functions.slideHeaderImages();
		}, 7000);
		
		
	},
	showGallery: function( id ){
		//alert('#'+id);
		$('.gallery').addClass('inactive').removeClass('active');
		$('#'+id).addClass('active').removeClass('inactive');
		$('#gallery_headlines div.active').removeClass('active');
		$('#headline_'+id).addClass('active');		
		
	}

};


function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function externalLinks() {
	 if (!document.getElementsByTagName) {
	 	return;
	 }
	 var anchors = document.getElementsByTagName("a");
	 for (var i=0; i<anchors.length; i++) {
		 var anchor = anchors[i];
		 if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			 anchor.target = "_blank";
		 }
	 }
}


