if (jQuery) {

    // Functions extending the jQuery object
    jQuery.fn.extend({
        
        // Wraps first word of a DOM element with a span to apply a different css style
        highlightFirstWord: function()
        {
            this.each(function(){
                $(this).html( $(this).html().replace(/(^\w+)/,'<span>$1</span>') );
            });
        }
    });
    

    // DOM ready
    $(function()
    {
        // Init behavoior: search box
        $('.search')
            .bind('submit', function(event) {
                // Don't submit with empty or default value
                if ( $('input:text', this).val() === '' || $('input:text', this).val() === $('label', this).text() ) {
                    return false; event.preventDefault();
                }
            })
            .find('input:text')
            .bind('focus', function() {
                // Focus: Remove defalut value
                if ( $(this).val() === $(this).prev().text() )
                { 
                    $(this).val('').removeClass( 'empty-query' );
                }
            })
            .bind('blur', function(){
                // Blur: Set defalut value for search field
                if ( $(this).val() === '' || $(this).val() === $(this).prev().text() )
                { 
                    $(this).val( $(this).prev().text() ).addClass( 'empty-query' );
                }    
            }).blur();

            
        // Rounded corners for last top navigation item with SVG in Opera >= 9.5
        if (window.opera && parseFloat(navigator.appVersion, 10) >= 9.5) { 
            $('#main5 a').css('background-image', 'url(/STATIC/images/topnav_bg_05.svg)');
        }

        // Hide empty subnavigation
        subNavigation = $('#level2');
        if (subNavigation.children().length === 0) {
            subNavigation.remove();
            $('#level2-bottom').remove();
        }
        
        // Homepage features
        $('#news').accordion();
        $('body#home .teaser h3').highlightFirstWord();

        // Accorion & Tabs
        $('.download-gallery-accordion').accordion({ active:false, collapsible:true });
        $('.tabs').tabs();

        if ($('#fadeContent').length)
        {
            $('#fadeContent').innerfade({ speed: 2000, timeout: 6000 }); 
        }
         
        $('div.teaser img').after('<img class="rahmen_mini" src="/STATIC/images/rahmen_mini.png" alt="" />');

        $(".shadebox .messe_item:first").addClass("firstmess");

        $('ul.headerlinks li:first').addClass('first');

    });    
}
