function panel(open) { jQuery(function ($) { if (open) { $('#loginpanel').trigger('click') } else { $('#closepanel a').trigger('click') } }) }
function getDomain() { var hostname = window.location.hostname.split('.'), tld = hostname.pop(), sl = hostname.pop(); return sl + '.' + tld }
function pad(n) {
    if (n < 10)
        return "0" + n
    else return n
}
function setCountdown(y, m, d) {
    jQuery(function ($) {
        bigDay = new Date(y, m - 1, d);
        msPerDay = 24 * 60 * 60 * 1000;
        timeLeft = (bigDay.getTime() - new Date().getTime());
        e_daysLeft = timeLeft / msPerDay;
        daysLeft = Math.floor(e_daysLeft);
        e_hrsLeft = (e_daysLeft - daysLeft) * 24;
        hrsLeft = Math.floor(e_hrsLeft);
        e_minsLeft = (e_hrsLeft - hrsLeft) * 60;
        minsLeft = Math.floor(e_minsLeft);
        e_secsLeft = (e_minsLeft - minsLeft) * 60;
        secsLeft = Math.floor(e_secsLeft);        
        $('.countdown').text(daysLeft + " Tage" + (daysLeft > 1 ? "n" : "") + ", " + pad(hrsLeft) + ":" + pad(minsLeft) + ":" + pad(secsLeft));
        setTimeout("setCountdown(" + y + "," + m + "," + d + ")", 1000);
    });
}
jQuery(function ($) {
    var ua = navigator.userAgent, desktop = true; $.msie();
    if (ua.match(/iPhone/i) || ua.match(/iPad/i) || ua.match(/iPod/i) || ua.match(/Android/i)) { desktop = false }

    ///////////////////////////////////////////////////////////
    //		SYNC HEIGHT OF TICKERS
    ///////////////////////////////////////////////////////////
    if ($('.ticker').length) {
        $('.ticker').each(function () {
            var theight = 0;
            $(this).find('a').each(function () {
                var h = $(this).height();
                if (theight < h) { theight = h }
            }).css({ height: theight })
        })
    }
    ///////////////////////////////////////////////////////////
    //		PANEL
    ///////////////////////////////////////////////////////////
    if ($('a[target=panel]').length) {
        var $panelurl = '/empty.html';
        $('body').append('<div id="panelwrap"><div id="panel" class="container"><div id="panelcontent" class="grid_17"><iframe src="' + $panelurl + '" width="960" height="185" allowtransparency="true" frameborder="0" scrolling="no" id="paneliframe" name="panel"></iframe></div><div id="closepanel"><a href="#">Panel ' + closephrase.toLowerCase() + '</a></div></div></div>');
        $('#paneliframe').fadeTo(0, 0);
        $('a[target=panel]').click(function (e) {
            var timedelay = 1000, href = $(this).attr('href');
            if (href == $panelurl) { timedelay = 0; e.preventDefault() }
            $panelurl = href;
            $('#paneliframe').stop().delay(timedelay + 500).fadeTo('normal', 1);
            $('#panelwrap').stop().animate({ top: 0 }, 'slow', 'swing', function () { $('#closepanel').stop().animate({ height: 24 }, 'normal', 'swing') });
        });
        $('#closepanel a').live('click', function () { $('#paneliframe').stop().fadeTo('slow', 0); $('#closepanel').stop().animate({ height: 0 }, 'fast', 'swing', function () { $('#panelwrap').stop().animate({ top: -240 }, 'normal', 'swing') }); return false })
    }

    ///////////////////////////////////////////////////////////
    //		TOOLTIP, POPUP, SHADOWBOX
    ///////////////////////////////////////////////////////////
    $('.container').popup();
    $('#main a[title],#sidebar a[title]').tooltip();

    Shadowbox.path = '/js/';
    Shadowbox.init({
        skipSetup: true,
        viewportPadding: 40,
        displayCounter: true,
        displayNav: true,
        showOverlay: true,
        overlayOpacity: 0.5,
        flashVersion: '9.0115.0',
        overlayColor: 'white',
        //	continuous:true,
        //	slideshowDelay:10,
        onOpen: jQuery.openBox
    });
    $('#sb-container').data('counter', 0);


    $('.tel').teltip();
    $('.fax').teltip({ desc: 'Faxnummer' });
    $('.content').sbox();


    ///////////////////////////////////////////////////////////
    //		NAVIGATION
    ///////////////////////////////////////////////////////////
    $('#nav').navigation();
    $('#homelink').fader({ no: 0.95 });
    $('#subnav').find('.no > a').fader({ no: 1, ro: 0.9, inSpeed: 'fast' });
    $('#nav').find('li > a').fader({ no: 1, ro: 0.9, inSpeed: 'fast' });
    $('#subnav').find('.act > a').fader({ no: 1, ro: 0.95, inSpeed: 'fast' });
    $('#actNav').fader({ no: 1, ro: 0.9, inSpeed: 'fast' });
    if ($('#subnav > li').length > 7) { $('#subnavigation').addClass('full') }

    ///////////////////////////////////////////////////////////
    //		CLAIMER
    ///////////////////////////////////////////////////////////
    if ($('#claim').length) {
        var $$ = $('#claim'), l = $$.find('i').length, i = 0;
        function showclaim() { $$.find('i:eq(' + i + ')').delay(1000).fadeIn(1000, function () { i++; if (l > i) { showclaim() } else { $$.delay(10000).fadeOut(2000, function () { i = 0; $$.delayer(3000, function () { $$.show().find('i').hide(); showclaim() }) }) } }) }
        showclaim();
    }

    ///////////////////////////////////////////////////////////
    //		AUDIOLINK
    ///////////////////////////////////////////////////////////

    var audioPopUpParameters = 'location=0,menubar=0,height=100,width=300,toolbar=0,scrollbars=0,status=0,resizable=0,left=-500,screenX=50,top=-500,screenY=50';

    function soundButton(state) {
        var find = '.sound', add = 'soundOFF', title = 'Musik abschalten', text = 'Musik';
        if (state) { find = '.soundOFF'; add = 'sound'; title = 'Musik gefällig?'; text = 'Musik?' }
        $('#meta').find(find).removeClass().addClass(add).find('a').attr('title', title).text(text)
    }

    $('a[target=audiopopup]').click(function () {
        var href = $(this).attr('href');
        if (window.name == 'audioPopUpOpen') {
            window.open('', 'audiopopup').close();
            soundButton(true);
            window.name = ''
        } else {
            window.open(href, 'audiopopup', audioPopUpParameters);
            window.name = 'audioPopUpOpen';
            soundButton();
            window.focus()
        }
        return false
    });
    if (window.name == 'audioPopUpOpen') { soundButton() }

    ///////////////////////////////////////////////////////////
    //		PAGE NAVIGATION
    //		inkl. das Zurücksetzen von Formularvalidation
    ///////////////////////////////////////////////////////////
    if ($('.pageNav').length) {
        function getHeight(el, height) { var h = el.outerHeight(true); if (height < h) { height = h } return height }
        $('.pageNav').each(function () {
            var $$ = $(this), $a = $$.find('a'), $first = $($$.find('a:first').attr('href')), $parent = $first.parent('.pageEntrys'), $entrys = $parent.find('.pageEntry');
            $$.find('a:first').addClass('act'); $first.show(); $parent.height($first.outerHeight(true));
            $a.click(function () {
                var $el = $($(this).attr('href')), $old = $entrys.has(':visible');
                if ($old.find('.validate').length) { $('.error').fadeTo(200, 0, function () { $old.find('.validate :input').validator({ formEvent: null, lang: 'de', errorInputEvent: 'keyup change', position: 'bottom left', offset: [2, -10] }).data('validator').reset() }) }
                $a.removeClass(); $(this).addClass('act');
                $old.stop().fadeTo(500, 0, function () {
                    $(this).hide(); $el.show().fadeTo(0, 0);
                    $parent.animate({ height: $el.outerHeight(true) }, 300);
                    $el.fadeTo(500, 1)
                })
                return false
            })
        })
    }
});

///////////////////////////////////////////////////////////
//		ON LOAD
///////////////////////////////////////////////////////////

var one = true;

jQuery(window).load(function () {
    var $ = jQuery, domain = getDomain();
    ///////////////////////////////////////////////////////////
    //		SLIDESHOW
    ///////////////////////////////////////////////////////////
    function slideshow() {
        var timeout = 10000, speed = 1500, $ul = $('#headIMGs'), $first = $ul.find('li:first'), path = $ul.attr('data-path'), img = $ul.attr('data-img').split(','), quantity = img.length, id = parseInt($ul.attr('data-id')), startup = id + 1, html = '', index = id;
        var cookieName = 'headIMG', cookieDomain = domain;
        if (quantity) { $first.css({ zIndex: 2 }); if (!id || startup > quantity) { startup = 1; index = 0 } for (var i = 0; i < quantity; i++) { var z = -1; if (index == i) { z = 1 } html += '<li style="z-index:' + z + ';"><img src="' + path + img[i] + '" width="960" height="250" border="0" alt="" /></li>' }; $ul.append(html); $.preload(path + img[startup - 1], { onFinish: function () { $ul.animate({ opacity: '+=0' }, timeout, function () { $.cookie(cookieName, startup, { path: '/', domain: cookieDomain }); $first.fadeOut(speed, function () { $first.remove(); $ul.innerfade({ animationtype: 'fade', type: 'sequence', containerheight: 250, speed: speed, timeout: timeout, startup: startup, cookie: cookieName, cookieOptions: { path: '/', domain: cookieDomain} }) }) }) } }) }
    }
    if ($('#headIMGs').length && one) { slideshow() }

    ///////////////////////////////////////////////////////////
    //		PRELOAD DATA
    ///////////////////////////////////////////////////////////
    if ($('.preload').length && one) {
        $('.preload').each(function () { var src = $(this).attr('data-src').split(','), path = $(this).attr('data-path'); $.preload(src, { base: path, onFinish: function () { $.cookie('loaded', true, { path: '/' }) } }) })
    }
    one = false;

    ///////////////////////////////////////////////////////////
    //		COUNTDOWN
    ///////////////////////////////////////////////////////////
    if ($('.countdown').length) {
        setCountdown(2010, 9, 13);        
    }
});


