$.noConflict();
jQuery(document).ready(function($) {

    bg_pfad = 'tl_files/layout/bg/';

    $('.content').css('display','none');

    // Jedem Inhalts-Container einen schließen-Button hinzufügen
    $('.inhalt').prepend('<div class="close-button"></div>')
    
    // Anker aus der URL holen, falls vorhanden
    if (window.location.hash) {
        link = window.location.hash.substring(1);
    } else {
        link = 'startseite';
    }

    // Content darf mit der Maus verschoben werden
    $( ".content" ).draggable({
        opacity: 0.6
//        containment: 'document'
    });

    ////////////////////////
    // Seite fertig geladen
    ////////////////////////
    $(window).load(function () {
        $('a.'+link).addClass('active');
        $('#'+link).fadeIn(300);
    });  // ENDE: Seite fertig geladen


    ////////////////////////
    // Klick auf Menüpunkt
    ////////////////////////
    $('#mainnavi a, #metanavi a').click(function() {

        // Vorherigen Link merken und
        // aktive Klasse entfernen
        prev_link = $('a.active');
        prev_link.removeClass('active');
        prev_link = prev_link.attr('class');

        link = $(this).attr('class');

        // So lange warten, bis alle Animationen abgespielt sind
        var wait = setInterval(function() {
            if (!$('*').is(':animated')) {
                clearInterval(wait);
                navi_click(prev_link,link);
            }
        }, 200);

    });  // ENDE: Klick auf Menüpunkt

    ////////////////////////
    // Klick auf Menüpunkt
    ////////////////////////
    function navi_click(prev_link,link) {

        // Wenn wieder auf den aktiven Link geklickt wird,
        // Inhalt nochmals einblenden (oder wieder, wenn dieser
        // zuvor geschlossen wurde)
        if (prev_link == link) {
            $('#'+link).fadeIn(500);
            $('a.'+link).addClass('active');
        } else {

            // Alten Content ausfaden, neuen einfaden
            $('#'+prev_link).fadeOut(250, function() {
                $('a.'+link).addClass('active');
                $('#'+link).fadeIn(500);
            });

            // Der IE hat ein Problem mit der load-Funktion
            if ($.browser.msie) {   // Browser = IE
                    if (link == 'startseite') {
                        $('#supersized img').attr('src', bg_pfad+'startseite.jpg');
                    } else if (link == 'impressum') {
                        $('#supersized img').attr('src', bg_pfad+'impressum.jpg');
                    } else if (link == 'links') {
                        $('#supersized img').attr('src', bg_pfad+'links.jpg');
                    } else if (link == 'kontakt') {
                        $('#supersized img').attr('src', bg_pfad+'kontakt.jpg');
                    } else if (link == 'impressionen') {
                        $('#supersized img').attr('src', bg_pfad+'impressionen.jpg');
                    } else if (link == 'anlaesse') {
                        $('#supersized img').attr('src', bg_pfad+'anlaesse.jpg');
                    } else if (link == 'accessoires') {
                        $('#supersized img').attr('src', bg_pfad+'accessoires.jpg');
                    } else if (link == 'service') {
                        $('#supersized img').attr('src', bg_pfad+'service.jpg');
                    }
            } else {    // alle anderen Browser
                // Alten BG ausfaden, neuen einfaden
                $('#supersized img').fadeOut(250, function() {
                    if (link == 'startseite') {
                        $('#supersized img').attr('src', bg_pfad+'startseite.jpg');
                    } else if (link == 'impressum') {
                        $('#supersized img').attr('src', bg_pfad+'impressum.jpg');
                    } else if (link == 'links') {
                        $('#supersized img').attr('src', bg_pfad+'links.jpg');
                    } else if (link == 'kontakt') {
                        $('#supersized img').attr('src', bg_pfad+'kontakt.jpg');
                    } else if (link == 'impressionen') {
                        $('#supersized img').attr('src', bg_pfad+'impressionen.jpg');
                    } else if (link == 'anlaesse') {
                        $('#supersized img').attr('src', bg_pfad+'anlaesse.jpg');
                    } else if (link == 'accessoires') {
                        $('#supersized img').attr('src', bg_pfad+'accessoires.jpg');
                    } else if (link == 'service') {
                        $('#supersized img').attr('src', bg_pfad+'service.jpg');
                    }
                    $('#supersized img').load(function() {  // warten bis Bild geladen ist
                        $('#supersized img').fadeIn(250);
                    });
                });
            }   // ENDE: Browsertest
        }

    }   // ENDE: Klick auf Menüpunkt


    ////////////////////////
    // Klick auf Schließen-Button
    ////////////////////////
    $('.close-button').click(function() {
        $('.content').fadeOut(500);
    });  // ENDE: Klick auf Schließen-Button

    ////////////////////////
    // Slideshow
    //Copyright (c) 2011 Sam Dunn / One Mighty Roar (www.onemightyroar.com)
    //Project Website: http://www.buildinternet.com/project/supersized/
    //Github project available at: https://github.com/buildinternet/supersized
    //
    //Permission is hereby granted, free of charge, to any person obtaining
    //a copy of this software and associated documentation files (the
    //"Software"), to deal in the Software without restriction, including
    //without limitation the rights to use, copy, modify, merge, publish,
    //distribute, sublicense, and/or sell copies of the Software, and to
    //permit persons to whom the Software is furnished to do so, subject to
    //the following conditions:
    //
    //The above copyright notice and this permission notice shall be
    //included in all copies or substantial portions of the Software.
    //
    //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    //EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    //MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    //NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    //LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    //OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    //WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    ////////////////////////
    if (link == 'startseite') {
        $.supersized({
            slides : [ {image : bg_pfad+'startseite.jpg'} ]
        });
    } else if (link == 'impressum') {
        $.supersized({
            slides : [ {image : bg_pfad+'impressum.jpg'} ]
        });
    } else if (link == 'links') {
        $.supersized({
            slides : [ {image : bg_pfad+'links.jpg'} ]
        });
    } else if (link == 'kontakt') {
        $.supersized({
            slides : [ {image : bg_pfad+'kontakt.jpg'} ]
        });
    } else if (link == 'impressionen') {
        $.supersized({
            slides : [ {image : bg_pfad+'impressionen.jpg'} ]
        });
    } else if (link == 'anlaesse') {
        $.supersized({
            slides : [ {image : bg_pfad+'anlaesse.jpg'} ]
        });
    } else if (link == 'accessoires') {
        $.supersized({
            slides : [ {image : bg_pfad+'accessoires.jpg'} ]
        });
    } else if (link == 'service') {
        $.supersized({
            slides : [ {image : bg_pfad+'service.jpg'} ]
        });
    }
    // ENDE: Slideshow


});
