// JS function for uncrypting spam-protected emails
// http://jumk.de/nospam/
function UnCryptMailto(s) {	
	var n=0;
	var r="";
	for(var i=0; i < s.length; i++) {
		n=s.charCodeAt(i);
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(1));
	}
	return r;
}  
function linkTo_UnCryptMailto(s) {
	location.href=UnCryptMailto(s);
} 
noSpam = function( user, domain ) {
document.location = 'mailto:' + user + '@' + domain;
} 
  
  
// Zeichenzähler Textarea (AddMentor, EditMentor)  
function ShowLength(text, field) {
    document.getElementById(text).innerHTML = document.getElementById(field).value.length;
}  
  
  
// jQuery
$(function() {
    $('#no_js').hide();
    
    // cmn video    
    $("#video").click(function() {
        $.fancybox({
            'padding'		        : 0,
            'autoScale'		        : false,
            'transitionIn'	        : 'fade',
            'transitionOut'	        : 'none',
            'overlayColor'          : '#2B3440',
            'overlayOpacity'        : '0.9', 
            'hideOnContentClick'    : false,
            'hideOnOverlayClick'    : true,
            'width'		            : 640,
            'height'		        : 505,
            'href'			        : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'			        : 'swf',
            'swf'			        : {
                'wmode'		        : 'transparent',
                'allowfullscreen'	: 'true'
            },
            'onClosed'              : function(){
                $.fancybox.cancel();  // cancels loading content
            } 
        });
        return false;
    });
        
    // leitung/beirat, kurse, datenschutz
    $('a.modal').fancybox({
		'autoDimensions'	    : false,
        'width'         		: 585,
		'height'        		: '80%',
        'padding'		        : 20, 
		'transitionIn'		    : 'fade',
		'transitionOut'		    : 'none',
        'overlayColor'          : '#2B3440',
        'overlayOpacity'        : '0.5', 
        'hideOnContentClick'    : false,
        'hideOnOverlayClick'    : true,
        'onClosed'              : function(){
            $.fancybox.cancel();  
        } 
	});
    
    
    // startInfos
    $('#startInfos div p.top').show();
    $('#startInfos a').css({ cursor:"pointer" });
    
    $('#startInfos a.more').click(function() {  
        // toggle the <div>: <a></a><div>
        //console.log($(this).next().text());    
        $(this).next().toggle("normal"); 
        $(this).toggleClass("selected");        
        }).next().hide(); 
        
    $('#startInfos a.more_p').click(function() {  
        // toggle the <div>: <p><a></a></p><div>
        //console.log($(this).parent().next().text());         
        $(this).parent().next().toggle("normal");
        $(this).toggleClass("selected");        
        }).parent().next().hide();     
    
    $('#startInfos p.top a').click(function() {  
        // toggle the <div>: <div><p><a></a></p></div>      
        $(this).parent().parent().toggle("normal");         
        $('#startInfos a').removeClass("selected");    
        }).parent().parent().hide(); 
    
    
    // zertifikat
    $('#zertifikat div p.top').show();
    $('#zertifikat a').css({ cursor:"pointer" });
    
    $('#zertifikat a.more').click(function() {        
        $(this).parent().next().toggle("normal");
        $(this).toggleClass("selected");        
        }).parent().next().hide(); 
    
    $('#zertifikat p.top a').click(function() {    
        $(this).parent().parent().toggle("normal");         
        $('#zertifikat a.more').removeClass("selected");    
        }).parent().parent().hide(); 
        
    // kurse
    $('#col2 div.kurs a.more').show();
    $('#col2 div.kurs a.more').css({ cursor:"pointer" });
    
    $('#col2 div.kurs a.more').click(function() {        
        $(this).parent().next().slideToggle("normal");
        $(this).toggleClass("selected"); 
        $(this).parent().toggleClass("selected"); 
       
        var myclasses = $(this).attr("class");
        var a_myclasses = myclasses.split(" ");
        var kurstyp = a_myclasses[1]; // 'Grund' oder 'Aufbau'        
        $(this).toggleText("« schließen", "weitere " + kurstyp + "kurse »");
        
        }).parent().next().hide();        
    
    $.fn.toggleText = function(a, b) {
        return this.each(function() {
        $(this).text($(this).text() == a ? b : a);   
        });  
    };    
    
});
  
