/* Im Forum: CSS Klassen einfügen */
$(document).ready(function(){
    if($('body.page-id-169 #forummenu').length > 0 || $('body.page-id-169 #topicmenu').length > 0) {
        $('body.page-id-169 .breadcrumbs + table #forummenu a:contains("New Topic")').addClass('new-topic');
        $('body.page-id-169 .breadcrumbs + table #topicmenu a:contains("Reply")').addClass('reply');
    }
});



/* Login: Passwort vergessen: Text ändern */
$(document).ready(function(){
    if($('body.login #login #lostpasswordform').length > 0) {
        $('body.login #login .message').html( $('body.login #login .message').html().replace('oder deine E-Mail-Adresse','(vorname.nachname)') );
        $('body.login #login #lostpasswordform label').html( $('body.login #login #lostpasswordform label').html().replace('oder E-Mail-Adresse','(vorname.nachname)') );
    }
});
/* Login: Texte ändern */
$(document).ready(function(){
    if($('body.login #login #loginform').length > 0) {
        $('body.login #login #loginform').html( $('body.login #login #loginform').html().replace('Benutzername','Benutzername (vorname.nachname)') );
        $('body.login #login #loginform').html( $('body.login #login #loginform').html().replace('Erinnere dich an mich','Angemeldet bleiben') );
        // Erinnere dich an mich anwählen
        $('#rememberme').attr('checked', true);
        // Box einfügen
        $('body.login #login').prepend('<p class="note">Solltest Du als Mitglied des TTV Vilshofen e.V. noch nicht über Login-Daten verfügen, wende Dich bitte unter Angabe Deiner Email-Adresse an <a href="mailto:info@ttv-vilshofen.de">info@ttv-vilshofen.de</a>!</p>');
    }
});





/* Dynamisch vor allen PDF Links das Symbol platzieren */
$(document).ready(function(){
    if($('#content .entry-content a').length > 0) {
        $('#content .entry-content a').each(function() {
            if($(this).attr('href') !== undefined) {
            if( $(this).attr('href').indexOf("pdf") !== -1 ) {
                $(this).addClass('pdf');
                if($(this).attr('rel') === undefined) {
                    $(this).attr('rel',"shadowbox;width=640");
                }
                if($(this).attr('title') === undefined) {
                    $(this).attr('title',$(this).text());
                }
            }
            }
        });
    }
});



/* Höhe vom Wrapper dynamisch anpassen */
$(window).resize(function() { setMinHeight(); });
$(window).load(function() { setMinHeight(); });
function setMinHeight() {
    if($('#wrapper').length > 0) {
        $('#wrapper').css('min-height', ($(window).height()-115)+"px" );
        //console.log(($(window).height()-115)+"px");
    }
}




// Menü oben vorbereiten
$(document).ready(function(){
    if($('#current_user_information').length > 0 && $('#menu-navigation').length > 0) {
        // Wenn man nicht Administrator ist, "Neue News erstellen", ausblenden
        if( $('#current_user_information #user_level').html() < 8 ) {
            $('#menu-navigation #menu-item-585 .sub-menu li.menu-item-569').remove();
        }
        else {
            $('#menu-navigation #menu-item-585 .sub-menu li.menu-item-569 a').attr('target','_blank');
        }
        // Wenn man eingeloggt ist, Logout-URL richtig setzen
        if( $('#current_user_information #logged_in').html() != "false" ) {
            $('#menu-navigation #menu-item-1000 a').attr('href', $('#current_user_information #logout_link').text() );            
        }
    }
});



// Presseschau: Navigation durch Klick auf Link
$(document).ready(function(){
    $('#post-53 .year_links li a').click(function() {
        var t = $(this);
        // Aktiven Container ausblenden
        $('#post-53 div.year.active').fadeOut(00, function() {
            // Neuen Container anzeigen
            $('#post-53 div.year_'+t.children('span').html()).fadeIn(300);
            // Klassen setzen
            $(this).removeClass('active');
            $('#post-53 div.year_'+t.children('span').html()).addClass('active');
        });

        return false;
    });
});



// Werbepartner, schön durchlaufen lassen
$(document).ready(function(){
    if( $('.ads_right ul.suppliers_pool').length > 0 ) {
            setInterval ( "showNext()", 5000 );
    }
});
function showNext() {
        // Nach der Reihe durchgehen
        var t = $('.ads_right ul.suppliers_pool li.curr');
        t.fadeOut(200, function() {
            t.removeClass('curr');
            // Wenn nicht letztes
            if( t.next('li').length > 0 ) {
                t.next('li').addClass('curr');
                t.next('li').fadeIn(200);
            }
            else {
                $('.ads_right ul.suppliers_pool li:first-child').addClass('curr');
                $('.ads_right ul.suppliers_pool li:first-child').fadeIn(200);
            }
        });
}



/* Background-Header schön durchlaufen lassen */
$(document).ready(function(){
    if( $('#header .container .header_backgrounds').length > 0 ) {
            setInterval ( "showNextBg()", 4000 );
    }
});
var current_index = 5;
function showNextBg() {
        // Am Ende
        if(current_index == 1) {
            $('#header .container .header_backgrounds').append( $('#header .container .header_backgrounds img:nth-child('+current_index+')') );
            $('#header .container .header_backgrounds img').each(function() {
                $(this).show();
            });
            current_index = 5;
        }
        // Nach der Reihe durchgehen
        var t = $('#header .container .header_backgrounds img:nth-child('+current_index+')');
        t.fadeOut(1500, function() {
            current_index--;
        });
}


// Galerie: Wasserzeichen (Pseudo) einfügen beim ersten Klick
$(document).ready(function(){
    if($('body.page-id-56').length > 0) {
        $('body.page-id-56 .image a').live('click', function() {
            if($('#sb-container #sb-body .watermark').length == 0) {
                $('#sb-container #sb-body').append('<div class="watermark"></div>');    
            }            
        });
    }
});



// News: Überall die Shadowbox drüberklatschen
$(document).ready(function(){
    if($('body.single #content .entry-content a img').length > 0) {
        $('body.single #content .entry-content a img').each(function() {
            if( $(this).attr('title') === undefined) {
                $(this).attr('title', "" );
            }
            else {
                $(this).parent('a').attr('title', $(this).attr('title') );
            }
            if($(this).parent('a').attr('rel') === undefined) {
                $(this).parent('a').attr('rel','shadowbox[news]');
            }
        });
    }
});



// Vereinszeitung: Überall die Shadowbox drüberklatschen
$(document).ready(function(){
    if($('body.page-id-429').length > 0) {
        $('body.page-id-429 ul.current li a, body.page-id-429 ul.archive li a').each(function() {
            $(this).attr('rel','shadowbox[zeitung];width=640;');
            $(this).attr('title', $(this).html() );
        });
    }
});






/* Werbungen schön mittig platzieren */
// Dynamisch Breite/Höhe der Vorschau und der Textareas setzen
$(window).resize(function() { setAdPos(); });
$(window).load(function() { setAdPos(); });
function setAdPos() {
    // Bildschirmhöhe bekommen
    var winHeight = $(window).height();
    
    topPos1 = (( winHeight - $('#header').height() - $('#footer').height() - $('.ads_left > div').height()) / 2)+$('#header').height()-20;
    topPos2 = (( winHeight - $('#header').height() - $('#footer').height() - $('.ads_right > div').height()) / 2)+$('#header').height()-20;
    
    $('.ads_left > div').css('top',topPos1);
    $('.ads_right > div').css('top',topPos2);
}



/* Beitritt Control */
/*$(document).ready(function(){
    if($('body.page-id-41').length > 0) {
        $('body.page-id-41 #content .link-vr').click(function() {
            $('.beitritt.fk').slideUp(200);
            $('.beitritt.vr').slideToggle(200, function() {
                var pos = $('.vr').offset();
                $(window).scrollTop( pos.top )
            });
            return false;
        });
        $('body.page-id-41 #content .link-fk').click(function() {
            $('.beitritt.vr').slideUp(200);
            $('.beitritt.fk').slideToggle(200, function() {
                var pos = $('.fk').offset();
                $(window).scrollTop( pos.top )
            });
            return false;
        });
    }
});*/




/* Vereinsgeschichte: Bilder rechts */
$(document).ready(function(){
    if($('body.page-id-643').length > 0) {
        $('body.page-id-643 #content .entry-content img').each(function() {
            $(this).wrap('<a title="'+$(this).attr('title')+'" href="'+$(this).attr('src')+'" rel="shadowbox[history]" class="image" />');
            $(this).parent('a').append('<span class="title">'+$(this).attr('title')+'</span>');
        });
    }
});




/* Vereinsgeschichte Anchor fixen */
$(document).ready(function(){
    if($('#post-643 .year_overview').length > 0) {
            $('#post-643 .year_overview li a').click(function() {
                var pos = $( '#post-643 .entry-content ' + $(this).attr('href') ).offset();
                $(window).scrollTop( pos.top - 100 );
                return false;
            });
    }
});


/* Vereinsturniere Anchor fixen */
$(document).ready(function(){
    if($('#post-71 .tournamentSubNavigation').length > 0) {
            $('#post-71 .tournamentSubNavigation li a').click(function() {
                var t = $( '#post-71 .entry-content ' + $(this).attr('href') ).parent();
                var pos = $( '#post-71 .entry-content ' + $(this).attr('href') ).offset();
                $(window).scrollTop( pos.top - 100 );
                t.animate({"paddingLeft": "5px"}, 200, function() { t.animate({"paddingLeft": "10px"}, 600); });
                return false;
            });
    }
});




/* Intern-Forum Profil Links fixen */
$(document).ready(function(){
    if($('a[title="View profile"]').length > 0) {
        $('a[title="View profile"]').each(function() {
            if( $(this).attr('href').indexOf( "forum?vasthtmlaction=profile" ) != -1 ) {
                $(this).attr('href', $(this).attr('href').replace("forum?vasthtmlaction=profile&","p?") );
                $(this).attr('title', "Spielerprofil ansehen" );
            }
        });
    }
});
