/*********************************************************
* Variablen
*********************************************************/

/*
Änderung: 09.02.2009
var ntTrans = parseInt('5000');
*/
var ntTrans = parseInt('2500'); // Anzeige einer News des Newsticker in ms


/*********************************************************
* jQuery-Kompatibilitätsmodus
*********************************************************/

jQuery.noConflict();


/*********************************************************
* Globale Funktionen
*********************************************************/

function trim( s )
{
	while (s.substring(0,1) == ' ')
		s = s.substring(1,s.length);
		
	while (s.substring(s.length-1,s.length) == ' ')
		s = s.substring(0,s.length-1);
		
	return s;
}

function scrollposition()
{	
	var scrollX = parseInt('0')
	var scrollY = parseInt('0');
	
	if( document.pageYOffset )
	{
		scrollX = document.pageXOffset;
		scrollY = document.pageYOffset;
	}
	else if( document.documentElement && document.documentElement.scrollTop )
	{
		scrollX = document.documentElement.scrollLeft;
		scrollY = document.documentElement.scrollTop;
	}
	else if( document.body )
	{
		scrollX = document.body.scrollLeft;
		scrollY = document.body.scrollTop;
	}
	
	return ({scrollX: scrollX, scrollY: scrollY })
}


/*********************************************************
* Scrolllinks
*********************************************************/

function scrollinterna()
{
	jQuery('a[href*=#]').click(function() {
		if( location.pathname.replace( /^\//,'' ) == this.pathname.replace( /^\//,'' ) && location.hostname == this.hostname && jQuery(this).attr('href').replace( /#/,'' ) != '' )
		{
			var jQuerytarget = jQuery(this.hash);
			jQuerytarget = jQuerytarget.length && jQuerytarget || jQuery('[name=' + this.hash.slice(1) +']');
			if (jQuerytarget.length)
			{
				var targetOffset = jQuerytarget.offset().top;
				jQuery('html,body').animate({scrollTop: targetOffset}, 800, 'swing');
				return false;
			}
		}
	});
};


/*********************************************************
* Elemente erweitern
*********************************************************/

function add2El( add, tagname, areas, eClass )
{
	var areas = areas.split(',');
	jQuery.each(areas, function(){
		jQuery('#' + trim(this) + ' ' + tagname).each(function(){
			if( !jQuery(this).hasClass(eClass) )
				jQuery(this).prepend(add);
		});
	});
}


/*********************************************************
* News-Ticker
*********************************************************/
var ntFirstEl;
var ntActEl;


function newsticker()
{
	
	if( !jQuery.browser.msie )
	{
		jQuery('#news').css({position: 'absolute'});
		jQuery('#home-teaser').css({marginTop: 100 + 'px'});
	}
	jQuery('#news-rechts h2').hide();
	jQuery('#news-rechts h2:first').fadeIn('fast', function(){
		ntFirstEl = jQuery(this);
		ntActEl = jQuery(this);
		window.setTimeout('fadeMe()', ntTrans);
	});
}

function fadeMe()
{
	var nextEl = ( !jQuery(ntActEl).next().length ) ? ntFirstEl : jQuery(ntActEl).next();
	jQuery(ntActEl).fadeOut('slow', function(){
		jQuery(nextEl).fadeIn('slow', function(){
			ntActEl = nextEl;
			window.setTimeout('fadeMe()', ntTrans);
		});
	});
}


/*********************************************************
* Menü-Slider
*********************************************************/

function menuSlider()
{
	var tolerance = parseInt('30');
	if( jQuery('#menue-scroller').attr('id') == 'menue-scroller' && jQuery('#hauptmenue-start').attr('id') != 'hauptmenue-start' )
	{
		var offsetY = jQuery('#hauptmenue').offset().top;
		var uLimit = offsetY + jQuery('#hauptmenue').height();

		if( jQuery.browser.msie && jQuery.browser.version < 7 )
			jQuery('#menue-scroller').css({ display: 'none', position: 'absolute', top: (uLimit + 50) });
			
		jQuery(window).scroll(function(){
			var scrollPos = scrollposition();
			var scrollPosY = scrollPos.scrollY;
			
			if( scrollPosY > uLimit - tolerance && uLimit < scrollPosY + tolerance )
			{
				if( jQuery('#menue-scroller').css('display') == 'none' )
					jQuery('#menue-scroller').fadeIn('slow');

				if( jQuery.browser.msie && jQuery.browser.version < 7 )	
					jQuery('#menue-scroller').css({ top: ( scrollPosY + jQuery(window).height() - 120  ) });
			}
			else
			{
				if( jQuery('#menue-scroller').css('display') != 'none' )
					jQuery('#menue-scroller').fadeOut(70);
			}
		});
	}
}

/*********************************************************
* Lightbox
*********************************************************/

function lightbox() {
     
     var curURL = document.URL;
     
     if(~ curURL.indexOf('/en/')) { // Englisch
          var langClose = '&raquo;&nbsp;Close';
          var langOpenInNewWindow = '&raquo;&nbsp;Open in new window';
          var langPrint = '&raquo;&nbsp;Print';
     }
     else if(~ curURL.indexOf('/pl/')) { // Polnisch
          var langClose = '&raquo;&nbsp;Zamknij zdjȩcie';
          var langOpenInNewWindow = '&raquo;&nbsp;Otwórz w nowym oknie';
          var langPrint = '&raquo;&nbsp;Drukuj';
     }
     else if(~ curURL.indexOf('/ru/')) { // Russisch
          var langClose = '&raquo;&nbsp;Закрыть';
          var langOpenInNewWindow = '&raquo;&nbsp;Открыть в новом окне';
          var langPrint = '&raquo;&nbsp;Печать';
     }
     else if(~ curURL.indexOf('L=3')) { // Chinesisch
          var langClose = '&raquo;&nbsp;关闭';
          var langOpenInNewWindow = '&raquo;&nbsp;在新视窗开启';
          var langPrint = '&raquo;&nbsp;打印';
     }
     else { // Deutsch
          var langClose = '&raquo;&nbsp;Bild schließen';
          var langOpenInNewWindow = '&raquo;&nbsp;In neuem Fenster öffnen';
          var langPrint = '&raquo;&nbsp;Drucken';
     }

     jQuery('#fancybox-content').after('<div class="controller"/>');
     jQuery('<a id="fancybox-open-in-new-window" />').appendTo('.controller');
     jQuery('<a id="fancybox-print" />').appendTo('.controller');
     jQuery('#fancybox-close').appendTo('.controller');
     
     jQuery('#fancybox-open-in-new-window').html(langOpenInNewWindow);
     jQuery('#fancybox-close').html(langClose);
     jQuery('#fancybox-print').html(langPrint);
     
     jQuery('#fancybox-open-in-new-window').click(function(){
          window.open(jQuery('#fancybox-img').attr('src'));
          return false;
     });
     
     jQuery('#fancybox-print').click(function(){
          var printMe =  window.open();
          jQuery('#fancybox-img').clone().appendTo(printMe.document.body);
          printMe.print();
          return false;
     });
     
	jQuery("#wrapper a[href*=.jpg], #wrapper a[href*=.gif], #wrapper a[href*=.png]").fancybox({
		overlayOpacity: .8,
		overlayColor: '#ccc',
		titleShow: false
	});
}


/*********************************************************
* Document-Ready
*********************************************************/

jQuery(document).ready(function() { // Wenn DOM geladen, dann ...
	scrollinterna(); // Scrollinks
	add2El( '&raquo;&nbsp;', 'a', 'inhalt, zusatzspalte', 'ohnedoppelpfeil' ) // » vor Links anfügen
	menuSlider(); // Menü-Button
	lightbox(); // Lightbox
	//newsticker(); // Newsticker-Animation
});
