// JavaScript Document

function megaHoverOver(){
	$(this).find(".sub").stop().fadeTo('fast', 1).show();
		
	//Calculate width of all ul's
	(function($) { 
		jQuery.fn.calcSubWidth = function() {
			rowWidth = 0;
			//Calculate row
			$(this).find("ul").each(function() {					
				rowWidth += $(this).width(); 
			});	
		};
	})(jQuery); 
	
	if ( $(this).find(".row").length > 0 ) { //If row exists...
		var biggestRow = 0;	
		//Calculate each row
		$(this).find(".row").each(function() {							   
			$(this).calcSubWidth();
			//Find biggest row
			if(rowWidth > biggestRow) {
				biggestRow = rowWidth;
			}
		});
		//Set width
		$(this).find(".sub").css({'width' :biggestRow});
		$(this).find(".row:last").css({'margin':'0'});
		
	} else { //If row does not exist...
		
		$(this).calcSubWidth();
		//Set Width
		$(this).find(".sub").css({'width' : rowWidth});
		
	}
}

function megaHoverOut(){ 
  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
	  $(this).hide(); 
  });
}

var megaHoverConfig = {    
	 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
	 interval: 50, // number = milliseconds for onMouseOver polling interval    
	 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
	 timeout: 250, // number = milliseconds delay before onMouseOut    
	 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
};

var RecaptchaOptions = {
	theme : 'white',
	lang : 'de',
	custom_translations : {
		instructions_visual : 'Geben Sie die 2 Wörter ein:',
		instructions_audio : 'Geben Sie die 8 Ziffern ein:',
		play_again : 'Nochmal abspielen',
		cant_hear_this : 'Als MP3-Datei herunterladen',
		visual_challenge : 'Audio-Aufgabe generieren',
		audio_challenge : 'Audio-Aufgabe generieren',
		refresh_btn : 'Neue Aufgabe generieren',
		help_btn : 'Hilfe',
		incorrect_try_again : 'Falsch. Nochmal',
	}
};

$(document).ready(function() {

	$('body').removeClass('nojs');
	
	$("ul#mnav li .sub").css({'opacity':'0'});
	$("ul#mnav li").hoverIntent(megaHoverConfig);
	$("ul#mnav li .sub").prev('a').addClass('touchhelper');
	if (Modernizr.touch){
		// bind to touchstart, touchmove, etc and watch `event.streamId`
		$('a.touchhelper').click(function() {
			event.preventDefault();
		});
	}
	
	$('.sub_left').each(function() {
		var w1 = $(this).width();
		var w2 = $(this).prev('a').width();
		
		if (w1 > w2) {
			$(this).css('left', (w2-w1)+17+'px');
		}
	});
	
	$('.slides .slides_zero').slides({
		play: 5000,
		pause: 2500,
		hoverPause: true,
		slideSpeed: 500,
		prependPagination: true
	});
	
	$('#mnav a[href="index.php"]').addClass('disabled');
	$('#mnav a.disabled').click(function(event) {
		event.preventDefault();
		$(this).effect("highlight", {color:'#f00'}, 1000);
	});
	
	$('a[href^="http://"]').attr('target', '_blank').attr('title', 'Die Seite wird in einem neuen Fenster aufgerufen.');
	$('a[href$=".pdf"]').attr('target', '_blank').attr('title', 'Die PDF-Datei wird in einem neuen Fenster aufgerufen.');
});



