/*
 * Plugin: mh_ fixULwidth
 */
(function(jQuery){  
	
	jQuery.fn.extend({
		fixulwidth: function() {			
			
			return this.each(function(i) {
				
				var width = 0;
				
				var ul = jQuery(this);
				
				if (ul.hasClass('devtools_ulwidthfixed')) { 
					return true;
				}
				
				ul.addClass('devtools_ulwidthfixed');
				
				var lis = ul.children('li');
				
				jQuery(this).attr('style','display:block');
		 		
				lis.each(function(){
				
					var thiswidth = jQuery(this).width();
					
					if(thiswidth > width){
						width = thiswidth;
					}
					
				});
				
				
				ul.find('ul').fixulwidth();
				
				ul.removeAttr('style');
				
				if(width > 0){
					jQuery(this).width(width);
					jQuery(this).addClass('devtools_liwidthfixed');
				}
				
			});
			
		}  
	});         
 })(jQuery);
 
 	function hiding1(){
 		$('#overview-navi').fadeOut(200);
 	}
 
 	function hiding2(){
 		$('#partner-navi').fadeOut(200);
 	}
 	
	function onAfter1(curr, next, opts) {	
    	var index = opts.currSlide;
    	$('.overview-prev')[index == 0 ? 'hide' : 'show']();
    	$('.overview-next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
    	$('#overview-navi').fadeIn(200);
	}
 
 	function onAfter2(curr, next, opts) {	
    	var index = opts.currSlide;
    	$('.partner-prev')[index == 0 ? 'hide' : 'show']();
    	$('.partner-next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
    	$('#partner-navi').fadeIn(200);
	}
 
$(document).ready(function(){
	//target blank
	$("a[href^='http://']").attr('target','_blank');
	$("a[href^='http://']").addClass('extern');
	
	$("#siteinfo a[href^='http://']").attr('target','_self');
	$("#siteinfo a[href^='http://']").removeClass('extern');	
	
	$("a[href$=.pdf]").addClass('pdf');
	$("a[href$=.doc]").addClass('doc');
	$("a[href$=.xls]").addClass('xls');
	$("a[href$=.docx]").addClass('docx');
	$("a[href^=mailto]").addClass('mailto');
	
	$("ul li:first-child").addClass('first');
	$("ul li:last-child").addClass('last');


	//for special effects in the navi
	$('#navigation ul ul').parent().addClass('sub');
	
	//fix the corner for hovers
	$('#navigation ul ul').parent().mouseover(function(){
		$(this).children('a').addClass('corner');
	});
	$('#navigation ul ul').parent().mouseout(function(){
		$(this).children('a').removeClass('corner');
	});
		
	
	$('#navigation li.sub').mouseover(function(){
		$(this).addClass('hover');
	});
	
	$('#navigation li.sub').mouseout(function(){
		$(this).removeClass('hover');
	});

	jQuery('#navigation ul ul').fixulwidth();

	//jQuery('#navigation ul ul ul').fixulwidth();


	jQuery("#navigation ul").superfish({ 
		delay: 400
	});


	// blaetternavi - slideshowmodul

	if (jQuery('.picslideshow .pic-cont2').width() > 0){
		
		jQuery('#breadcrumb #bread').append('<p id="slideshownavi"><a class="slideshow-prev" href="#">Prev</a><span>Bl&auml;ttern</span><a class="slideshow-next" href="#">Next</a></p>');

	    jQuery('.picslideshow').cycle({
			fx: 'fade',
			timeout: 9000, 
	    	next: '.slideshow-next', 
	    	prev: '.slideshow-prev'
		});
	
	}
	
	
	// Zurueck zur Uebersicht bei Example-Details
	
	if(jQuery('.example-detail').width() > 0){
		var link = jQuery('#breadcrumb a:last-child').attr('href');	
	}


	// Nummerierung auf Detailseiten
	
	if (jQuery('#examplenum').width() > 0){
			var examplenum = jQuery('p#examplenum').html();
			jQuery('p#examplenum').remove();
			jQuery('#breadcrumb #bread').append('<span class="bread"></span><span class="breadcrumb">'+examplenum+'</span>');
	}


	// Blaetternavi - Detailseite

	if (jQuery('.example-detail').width() > 0){
		
		if (jQuery('.example-detail').width() > 0){
			var examplenav = jQuery('p#examplenav').html();
			jQuery('p#examplenav').remove();
			jQuery('#breadcrumb #bread').append('<p id="examplenav">'+ examplenav +'</p>');
			jQuery('p#examplenav').show();
		}
		

	    jQuery('.example-detail').cycle({
			fx: 'fade',
			timeout: 6000
		});
	
	}


	// blaetternavi - uebersichtsseite
		
	if (jQuery('.example-container .teaser2').width() > 0){
		
		jQuery('#breadcrumb #bread').append('<p id="overview-navi"><a class="overview-prev" href="#">Prev</a><span>Bl&auml;ttern</span><a class="overview-next" href="#">Next</a></p>');
		
	    jQuery('.example-wrap').cycle({
			fx: 'fade',
			timeout: 0, 
	    	next: '.overview-next', 
	    	prev: '.overview-prev',
	    	nowrap: 1,
	    	before: hiding1,
	    	after: onAfter1
		});
	
	}


	// Zurueck zur Uebersicht bei Example-Details

	if(jQuery('.example-detail').width() > 0){
		jQuery('#breadcrumb #bread').append('<p id="backlink"><a href="'+link+'">&Uuml;bersicht</a></p>');
	}


	// blaetternavi - partnerseite
	
	if (jQuery('.partnercontainer .teaser2').width() > 0){
		
		jQuery('#breadcrumb #bread').append('<p id="partner-navi"><a class="partner-prev" href="#">Prev</a><span>Bl&auml;ttern</span><a class="partner-next" href="#">Next</a></p>');
		
	    jQuery('.partnerwrap').cycle({
			fx: 'fade',
			timeout: 0, 
	    	next: '.partner-next', 
	    	prev: '.partner-prev',
	    	nowrap: 1,
	    	before: hiding2,
	    	after: onAfter2
    		
		});
	
	}
	
	// blaetternavi bei neuem modul entfernen
	
	if(jQuery('.nomenu').width() > 0){
		jQuery('#slideshownavi').remove();
	}



	
	
	
	
	
});





/*$(window).load(function(){

	
	// bildskalierung - uebersichtsseite
	
	if (jQuery('.example-container .teaserbox').width() > 0){
		
		jQuery('.example-container .teaserbox').each(function(){
			
			
			
			jQuery(this).find('.pic').each(function(){
			
				var img = jQuery(this).find('img');
					
					var imgHeight = img.height();
				
					var margin = 146 - imgHeight;
					var margin = margin / 2;
					jQuery(this).find('img').css('margin-top',margin+'px');
			
			});
		});		
	
	}
	
	
	
		// Bildskalierung - partnerseite

	if (jQuery('.partnercontainer .partmerbox').width() > 0){
		
		jQuery('.partnercontainer .partnerbox').each(function(){
			
			jQuery(this).find('.pic').each(function(){
			
				var imgWidth = jQuery(this).find('img').width();
				var imgHeight = jQuery(this).find('img').height();
				
				if(imgWidth > imgHeight){
					var margin = imgWidth - 220;
					var margin = margin / 2;
					jQuery(this).find('img').css('margin-left','-'+margin+'px');
				} 
				
				
				if(imgHeight > imgWidth){
					var margin = imgHeight - 146;
					var margin = margin / 2;
					jQuery(this).find('img').css('margin-top','-'+margin+'px');
				}
			
			});
		});		
	
	}
	
	
			
});*/
