// when the DOM is ready...
$(document).ready(function () {
	
	if($('#slider .scrollContainer').length>0){
		
		//bei javascript werden alle div panels auf display:block gesetzt
	    $('#slider').addClass("js");
	    $('.scrollButtons').remove();
	    var $panels = $('#slider .scrollContainer > div');
	    var $container = $('#slider .scrollContainer');
	
	    // if false, we'll float all the panels left and fix the width 
	    // of the container
	    var horizontal = true;
	
	    // float the panels left if we're going horizontal
	    if (horizontal) {
	        $panels.css({
	            'float' : 'left',
	            'position' : 'relative' // IE fix to ensure overflow is hidden
	        });
	
	        // calculate a new width for the container (so it holds all panels)
	        $container.css('width', $panels[0].offsetWidth * $panels.length);
	    }
	
	    // collect the scroll object, at the same time apply the hidden overflow
	    // to remove the default scrollbars that will appear
	    var $scroll = $('#slider .scroll').css('overflow', 'hidden');
	
	    // apply our left + right buttons
	    if($("html").attr("lang")=="en"){
	    	 $scroll
		        .before('<div class="scrollButtons left"><img src="/bio/images/bio/de/slideLeft.gif" /><a href="#">backward </a></div>')
		        .after('<div class="scrollButtons right"><a href="#">forward</a><img src="/bio/images/bio/de/slideRight.gif" /></div>');	    
	    }else{
		    $scroll
		        .before('<div class="scrollButtons left"><img src="/bio/images/bio/de/slideLeft.gif" /><a href="#">Zur&uuml;ck</a></div>')
		        .after('<div class="scrollButtons right"><a href="#">Vor</a><img src="/bio/images/bio/de/slideRight.gif" /></div>');
		}
	    // handle nav selection
	    function selectNav() {
	        $(this)
	            .parents('ul')
	                .find('a')
	                    .removeClass('selected')
	                .end()
	            .end()
	            .addClass('selected');
	           
	    }
	    
		$('#slider #panel_Inhalt .navigation2 a').click(function(){			
				$('#slider #sliderTop').find(".navigation").find('a[href$="'+$(this).attr("href")+'"]').trigger('click');
				return false;
			});	
		
	    // go find the navigation link that has this target and select the nav
	    function trigger(data) {
	        var el = $('#slider #sliderTop .navigation').find('a[href$="' + data.id + '"]').get(0);
	        selectNav.call(el);
	    }
	
	    // offset is used to move to *exactly* the right place, since I'm using
	    // padding on my example, I need to subtract the amount of padding to
	    // the offset.  Try removing this to get a good idea of the effect
	    var offset = parseInt((horizontal ? 
	        $container.css('paddingTop') : 
	        $container.css('paddingLeft')) 
	        || 0) * -1;
	
	
	    var scrollOptions = {
	        target: $scroll, // the element that has the overflow
	
	        // can be a selector which will be relative to the target
	        items: $panels,
	
	        navigation: '#sliderTop .navigation a',
	        
			jump: true,
			
	        // selectors are NOT relative to document, i.e. make sure they're unique
	        prev: 'div.left', 
	        next: 'div.right',
	
	        // allow the scroll effect to run both directions
	        axis: 'xy',
	
	        onAfter: trigger, // our final callback
	
	        offset: offset,
	
	        // duration of the sliding effect
	        duration: 1000,
	
	        // easing - can be used with the easing plugin: 
	        // http://gsgd.co.uk/sandbox/jquery/easing/
	        easing: 'jswing'
	    };
	    
	    
	
	    // apply serialScroll to the slider - we chose this plugin because it 
	    // supports// the indexed next and previous scroll along with hooking 
	    // in to our navigation.
	    $('#slider').serialScroll(scrollOptions);
	
	    // now apply localScroll to hook any other arbitrary links to trigger 
	    // the effect
	    $.localScroll(scrollOptions);
	
	    // finally, if the URL has a hash, move the slider in to position, 
	    // setting the duration to 1 because I don't want it to scroll in the
	    // very first page load.  We don't always need this, but it ensures
	    // the positioning is absolutely spot on when the pages loads.
	    scrollOptions.duration = 1;
	    $.localScroll.hash(scrollOptions);
	    
	    //Nach-Oben-Link für noscript-Variante
	    $(".scrollContainer div.panel .top").hide();
	    
	    //Title entfernen, damit keine Doppelung mit dem Tooltip auftritt
	    $("#slider .navigation li a").removeAttr("title");
	    
	    // Tooltip der Navigation
		$("#slider #sliderTop .navigation li a").hover(	  
	      function () {     
	       $(this).parent().append($("<span class=\"tooltip\"><span class=\"tooltipTop\">" + $("#panel_" + $(this).text() + " h3").text() + "</span><span class=\"tooltipBottom\">&nbsp;</span></span>"));
	       var tooltipHeight = $(this).parent().children("span.tooltip").height() + 10;       
	       $(this).parent().children("span.tooltip").css("top","-" + tooltipHeight + "px");    
	      }, 
	      function () {
	       $(this).parent().find("span.tooltip").remove();              
	      }
	    );
	    
	    $("#slider #sliderTop .navigation li a").focus(	  
	      function () {       
	       $(this).parent().append($("<span class=\"tooltip\"><span class=\"tooltipTop\">" + $("#panel_" + $(this).text() + " h3").text() + "</span><span class=\"tooltipBottom\">&nbsp;</span></span>"));
	       var tooltipHeight = $(this).parent().children("span.tooltip").height() + 10;       
	       $(this).parent().children("span.tooltip").css("top","-" + tooltipHeight + "px");      
	       
	      }
	    );
	    
	    $("#slider #sliderTop .navigation li a").blur(	  
	      function () {
	       $(this).parent().find("span.tooltip").remove();              
	      }
	    ); 
     }
     
    if($('#slider #sliderTop .navigation').find('.selected').length > 0){
    	var val = $('#slider #sliderTop .navigation').find('.selected');
    	var id = val.attr('id').substr("pan_".length);
    	$scroll.trigger( 'goto', [id] );
    }
    
    $('#slider .panelNoInhalt a').click(function(){		
    	location = $(this).attr("href");
    });	
    
    $('#slider #panel_Inhalt .inhaltsende .back a').click(function(){	
   		location = $(this).attr("href");
     });	
    
});
