/* Plugin to make variable height divs equal heights */
$.fn.sameHeights = function() {

$(this).each(function(){
var tallest = 0;

$(this).children().each(function(i){
if (tallest < $(this).height()) { tallest = $(this).height(); }
});
$(this).children().css({'height': tallest});
});
return this;
};

$(document).load(function(){
if ($('#subnavigation').offset().top > 200) {
        $('#subnavigation').addClass('fixed');		  
	  }
})
$(document).ready(function(){
	
	//if($.cookie('opt_visible') != 'true'){ //wenn kein Cookie existiert
	//$("#teaser").css("opacity","0");
	$("#claim").css("opacity","0");
	$("#abstracts").css("opacity","0");
	//$("#teaser").animate({opacity:"+=100"},2000);
	$("#claim").delay(500).animate({opacity:"+=100"},8000,"swing");
	$("#abstracts").delay(700).animate({opacity:"+=100"},8000,"swing");
	$.cookie('opt_visible', 'true', { path: '/', expiresAt: new Date(new Date().getTime()+3600000) }); //für 1h
		
    $("#subnavigation").css("opacity","0");
	$("#navigation ul ul").css("visibility","visible");
	$("#subnavigation").delay(300).animate({opacity:"+=100"},8000,"swing");
	//	$.cookie('opt_visible_sub', 'true', { path: '/', expiresAt: new Date(new Date().getTime()+3600000) }); //für 1h
	//}

	$('#content ul li').each(function(i, e) {
        $(e).css('color', '#999')
        $(e).contents().wrap('<span class="text"></span>')
    })
	$('#teaser ul li').each(function(i, e) {
        $(e).css('color', '#999')
        $(e).contents().wrap('<span class="text"></span>')
    })
	$('#content ol li').each(function(i, e) {
        $(e).css('color', '#999')
        $(e).contents().wrap('<span class="text"></span>')
    })

    // Barrierefreie Navigation
	$("#navigation ul li a").focus(function() {
		$(this).parent().children("ul").css({left: "auto", top:"40px", display:"block"});
		$(this).parent().children("a").addClass("active");
		$(this).parent().addClass("active");
	});
	
	$("#navigation ul li a").blur(function() {
		$(this).parent().children("ul").css({left: "-5000px"});
		$(this).parent().removeClass("active");
		$(this).removeClass("active");
	});
	
	$("#navigation ul li ul li a").focus(function() {
		$(this).parent().parent().parent().children("ul").css({left:"auto", top:"40px", display:"block"});
		$(this).parent().children("ul").css({left:"100%", top:"10px", display:"block"});
		$(this).parent().parent().parent().children("a").addClass("active");
		$(this).parent().parent().parent().addClass("active");
	});
	
	$("#navigation ul li ul li a").blur(function() {
		$(this).parent().parent().parent().children("ul").css({left: "-5000px"});
		$(this).parent().children("ul").css({left:"-5000px", top:"10px", display:"block"});
		$(this).parent().parent().parent().children("a").removeClass("active");
		$(this).parent().parent().parent().removeClass("active");
	});
	
	$("#navigation ul li ul li ul li a").focus(function() {
		$(this).parent().parent().parent().parent().parent().children("ul").css({left:"auto", top:"40px", display:"block"});
		$(this).parent().parent().parent().children("ul").css({left:"100%", top:"10px", display:"block"});
		$(this).parent().parent().parent().parent().parent().children("a").addClass("active");
		$(this).parent().parent().parent().parent().parent().addClass("active");
	});
	
	$("#navigation ul li ul li ul li a").blur(function() {
		$(this).parent().parent().parent().parent().parent().children("ul").css({left: "-5000px"});
		$(this).parent().parent().parent().children("ul").css({left:"-5000px", top:"10px", display:"block"});
		$(this).parent().parent().parent().parent().parent().children("a").removeClass("active");
		$(this).parent().parent().parent().parent().parent().removeClass("active");
	});
	
	$("#navigation ul li").hover(
		function(){
			$(this).children("ul").css({left: "auto"});
		},
		function(){
			$(this).children("ul").css({left: "-5000px"});
		}
	);
	
	$("#navigation ul li ul li").hover(
		function(){
			$(this).children("ul").css({left: "100%"});
		},
		function(){
			$(this).children("ul").css({left: "-5000px"});
		}
	);

	$(function () {
		var msie6 = $.browser == 'msie' && $.browser.version < 7;
  		if (!msie6) {
    		var top = $('#subnavigation').offset().top - parseFloat($('#subnavigation').css('margin-top').replace(/auto/, 0));
          	// what the y position of the scroll is
      		var y = $(this).scrollTop();
            // whether that's below the form
      		if (y >= top) {
        		// if so, ad the fixed class
        		$('#subnavigation').addClass('fixed');
      		} else {
        		// otherwise remove it
        		$('#subnavigation').removeClass('fixed');
      		}	
			$(window).scroll(function (event) {
				// what the y position of the scroll is
				var y = $(this).scrollTop();
				// whether that's below the form
				if (y >= top) {
					// if so, ad the fixed class
					$('#subnavigation').addClass('fixed');
				} else {
					// otherwise remove it
					$('#subnavigation').removeClass('fixed');
				}
			});
  		} 
	});

  	//Examples of how to assign the ColorBox event to elements
	$("a[rel='example1']").colorbox();
	$("a[rel='example2']").colorbox({transition:"fade"});
	$("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
	$("a[rel='example4']").colorbox({slideshow:true});
	$(".example5").colorbox();
	$(".example6").colorbox({iframe:true, innerWidth:535, innerHeight:344});
	$(".example7").colorbox({width:"80%", height:"80%", iframe:true});
	$(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"});
	$(".example9").colorbox({
		onOpen:function(){ alert('onOpen: colorbox is about to open'); },
		onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
		onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
		onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
		onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
	});
	
	//Example of preserving a JavaScript event for inline calls.
	$("#click").click(function(){ 
		$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
		return false;
	});
	
	
	
	
});

function closeColorbox(){
	$.colorbox.close();
}
