$(document).ready(function() {
	
	
	// --------------------------------------//
	// Print Funktion
	// --------------------------------------//
	
	$('div#sidebarServiceNavi div.print a').click(function() {
		window.print();
		return false;
	});
	
	
	// --------------------------------------//
	// Language Menu
	// --------------------------------------//
	
	/*$('div#serviceNavi ul li:first').mouseenter(function(e) {
		e.stopPropagation();
		$('div#langNavi').slideDown();
	});
	
	$('div#langNavi').mouseleave(function(e) {
		e.stopPropagation();
		$('div#langNavi').slideUp();
	});*/
	$("div#serviceNavi ul li:first").click(function () {
		$("div#langNavi").toggle();
	});
	
	
	
	// --------------------------------------//
	// fontSize functions
	// --------------------------------------//
	
	$('div#sidebarServiceNavi img.fontSizeReset').click(function() {
		$("body").css('font-size', '1em');
		Cufon.refresh();
		return false;
	});
	
	$('div#sidebarServiceNavi img.fontSizeBig').click(function() {
		$("body").css('font-size', '1.25em');
		Cufon.refresh();
		return false;
	});
	
	$('div#sidebarServiceNavi img.fontSizeBigger').click(function() {
		$("body").css('font-size', '1.5em');
		Cufon.refresh();
		return false;
	});
	
	
	
	// --------------------------------------//
	// show & hide subnavi
	// --------------------------------------//
	
	
	
	function styleNavi(pos, teaserNr){
		
		var actTeaser = "div#teaser"+teaserNr;

		$("ul#topnav ul.submenu").css("margin-left", pos);
		$(actTeaser).fadeIn();

	}
	
	
	
	//On Hover Over
	function megaHoverOver(){
	    
	    $(this).find(".sub").stop().slideDown(); //Find sub and fade it in
	    
	    var menuItem = this.id;
	    
		switch(menuItem){
			case "25":
				styleNavi("77px","1");
			break;
			
			case "26":
				styleNavi("247px","2");
			break;
			
			case "27":
				styleNavi("247px","3");
			break;
			
			case "28":
				styleNavi("77px","4");
			break;
			
		}
		
		
	}
	//On Hover Out
	function megaHoverOut(){
		
		
		$(this).find(".sub").stop().slideUp('fast', function() { //Fade to 0 opactiy
			$(this).hide();  //after fading, hide it
			$("div.teaser").hide(); //hide all teaser
		});
			  

	  
	}
	
	
	
	//Set custom configurations
	var config = {
	     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
	     interval: 150, // number = milliseconds for onMouseOver polling interval
	     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
	     timeout: 100, // number = milliseconds delay before onMouseOut
	     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};
	
	$("ul#topnav li").hoverIntent(config); //Trigger Hover intent with custom configurations
	
	
	
	
	
	
	
	
	
	
	
    
    
    // --------------------------------------//
	// tableSort
	// --------------------------------------//
	
	//german date
	$.tablesorter.addParser({
	  id: 'germandate',
	  is: function(s) {
	          return false;
	  },
	  format: function(s) {
	    var a = s.split('.');
	    a[1] = a[1].replace(/^[0]+/g,"");
	    return new Date(a.reverse().join("/")).getTime();
	  },
	  type: 'numeric'
	});

	
	
	//team
	$("#bzdTable").tablesorter({ 
        
        headers: { 
            0: { 
                sorter: false 
            }
        }
        
    }); 
    
	//news
	//$("#newsTable").tablesorter(); 
	$("#newsTable").tablesorter({
            headers: { 0: { sorter:'germandate' }}
    });
	
	
	
	//news with list and grid view
	$("#newsTable2").tablesorter({ 
        
        headers: { 
            0: { 
                sorter: false 
            }
        }
        
    }); 
    
    
    
    
    
    // --------------------------------------//
	// BrowserGrid View add even/odd Class
	// --------------------------------------//
    $("div.tx-bzdstaffdirectory-pi1 div.teamListImage").addClass("item");
	$("div.tx-bzdstaffdirectory-pi1 div.teamListImage:nth-child(4n+1)").addClass("last");
	
	
	
	// --------------------------------------//
	// Detail View Agenda
	// --------------------------------------//
	
	$("#container .news-list-container tr td a.agendaLink").click(function(){
		$(this).parent().find(".container2").stop().slideToggle("slow");
	  	$(this).toggleClass("active");
	});
	
	
	
	// --------------------------------------//
	// Switch Views
	// --------------------------------------//
	$('a.grid').click(function() {
		if($('div.container2:hidden').length){
			$("div.container1").fadeTo('fast', 0, function() { 
				$("div.container1").hide();
				$("div.container2").fadeTo('fast',1); 
				//$('a.grid').unbind('click');
			});
		}
	});

	$('a.list').click(function() {
		if($('div.container1:hidden').length){
			$("div.container2").fadeTo('fast', 0, function() { 
				$("div.container2").hide();
				$("div.container1").fadeTo('fast',1); 
			});
		}
	});
	
	
	
	// --------------------------------------//
	// Header Image Rotator
	// --------------------------------------//
	
	$('#loopedSlider').loopedSlider({
		addPagination: false,
		slidespeed: 500,
		autoStart: 10000
	});
	
	
	// --------------------------------------//
	// Bookmarkicon
	// --------------------------------------//
	
	$('div#sidebarServiceNavi div.bookmark a').jFav();
	
	// --------------------------------------//
	// Fancybox
	// --------------------------------------//
	
	
	$("a.jqfancybox").fancybox({
		'overlayOpacity': 0.8,
		'overlayColor': '#0a8bb5',
		'titleShow': false
	});
	
});


