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 bildwechsel() {
	$('div#wechsel1 ul li').css({opacity: 0.0});
	$('div#wechsel1 ul li:first').css({opacity: 1.0});

    $('div#wechsel2 ul li').css({opacity: 0.0});
	$('div#wechsel2 ul li:first').css({opacity: 1.0});

    $('div#wechsel3 ul li').css({opacity: 0.0});
	$('div#wechsel3 ul li:first').css({opacity: 1.0});

    $('div#wechsel4 ul li').css({opacity: 0.0});
	$('div#wechsel4 ul li:first').css({opacity: 1.0});
	
	setInterval("setTimeout('rotate1()',1)",8000);
	setInterval("setTimeout('rotate4()',2000)",8000);
	setInterval("setTimeout('rotate2()',4000)",8000);
	setInterval("setTimeout('rotate3()',6000)",8000);
}

function rotate1() {	
	//Erstes Bild
	var current = ($('div#wechsel1 ul li.show')?  $('div#wechsel1 ul li.show') : $('div#wechsel1 ul li:first'));

	//Naechstes Bild, wenn es sich um das letzte handelt, nimm das erste erneut
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#wechsel1 ul li:first') :current.next()) : $('div#wechsel1 ul li:first'));	

	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

	current.animate({opacity: 0.0}, 1000).removeClass('show');
    
};

function rotate2() {	
	//Erstes Bild
	var current = ($('div#wechsel2 ul li.show')?  $('div#wechsel2 ul li.show') : $('div#wechsel2 ul li:first'));

	//Naechstes Bild, wenn es sich um das letzte handelt, nimm das erste erneut
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#wechsel2 ul li:first') :current.next()) : $('div#wechsel2 ul li:first'));	

	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

	current.animate({opacity: 0.0}, 1000).removeClass('show');

};

function rotate3() {	
	//Erstes Bild
	var current = ($('div#wechsel3 ul li.show')?  $('div#wechsel3 ul li.show') : $('div#wechsel3 ul li:first'));

	//Naechstes Bild, wenn es sich um das letzte handelt, nimm das erste erneut
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#wechsel3 ul li:first') :current.next()) : $('div#wechsel3 ul li:first'));	

	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

	current.animate({opacity: 0.0}, 1000).removeClass('show');

};

function rotate4() {	
	//Erstes Bild
	var current = ($('div#wechsel4 ul li.show')?  $('div#wechsel4 ul li.show') : $('div#wechsel4 ul li:first'));

	//Naechstes Bild, wenn es sich um das letzte handelt, nimm das erste erneut
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#wechsel4 ul li:first') :current.next()) : $('div#wechsel4 ul li:first'));	

	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

	current.animate({opacity: 0.0}, 1000).removeClass('show');

};

/**
 *
 * @access public
 * @return void
 **/
$(document).ready(function () {
    
	/* Wechsel der Bilder der Hauptnavigationspunkte bei MouseOver über eine Klassen-Eigenschaft */
    $('.overBtn').mouseover(function(){
    
        /* Dateiendung ermitteln, damit die Funktion generisch ist für verschiedene 3-stellige Dateiendungen */
        filetyp = $(this).attr('src').substring($(this).attr('src').length - 3, $(this).attr('src').length);
    
        $(this).attr('src', 'img/'+$(this).attr('name')+'_over.'+filetyp);

    }).mouseout(function(){
        
        // Wechsel nur veranlassen, wenn nicht schon aktiver Menupunkt
        if ( $(this).attr('class') != 'overBtn active' ) {
    	
            $(this).attr('src', 'img/'+$(this).attr('name')+'.'+filetyp);
        
        }

    });
    
    $('#wechsel1').click(function(){
        
        var srcKlein = $('#wechsel1 ul').find('li.show img').attr('src');
        var srcBildname = srcKlein.substring(0, srcKlein.length - 9);

        $('#topLeftZoom').css('display', 'block');
        $('#topLeftZoom').html('<img src="'+srcBildname+'gross.jpg" alt="" id="bigPic" onclick="$(this).fadeOut();$(this).parent().css(\'display\', \'none\');" style="width:410px;" />');
        $('#topLeftZoom').fadeIn();
    });
    
    $('#wechsel2').click(function(){
        
        var srcKlein = $('#wechsel2 ul').find('li.show img').attr('src');
        var srcBildname = srcKlein.substring(0, srcKlein.length - 9);

        $('#topLeftZoom').css('display', 'block');
        $('#topLeftZoom').html('<img src="'+srcBildname+'gross.jpg" alt="" id="bigPic" onclick="$(this).fadeOut();$(this).parent().css(\'display\', \'none\');" style="width:410px;" />');
        $('#topLeftZoom').fadeIn();
    });
    
    $('#wechsel3').click(function(){
        
        var srcKlein = $('#wechsel3 ul').find('li.show img').attr('src');
        var srcBildname = srcKlein.substring(0, srcKlein.length - 9);

        $('#topLeftZoom').css('display', 'block');
        $('#topLeftZoom').html('<img src="'+srcBildname+'gross.jpg" alt="" id="bigPic" onclick="$(this).fadeOut();$(this).parent().css(\'display\', \'none\');" style="width:410px;" />');
        $('#topLeftZoom').fadeIn();
    });
    
    $('#wechsel4').click(function(){
        
        var srcKlein = $('#wechsel4 ul').find('li.show img').attr('src');
        var srcBildname = srcKlein.substring(0, srcKlein.length - 9);

        $('#topLeftZoom').css('display', 'block');
        $('#topLeftZoom').html('<img src="'+srcBildname+'gross.jpg" alt="" id="bigPic" onclick="$(this).fadeOut();$(this).parent().css(\'display\', \'none\');" style="width:410px;" />');
        $('#topLeftZoom').fadeIn();
    });
    
});