$(document).ready(function() {
    /* center tt_news browsebox */
    
    function centerThumbs()
    {
        $('#content .tx-ttnews-browsebox').each(function()
        {
            var width = $('.tx-ttnews-browsebox').width();
            var marginL = '-' + Math.round(width/2);
            
            $(this).css({
                position:   'relative',
                left:       '50%',
                marginLeft: marginL + 'px'
            });
        });
    }
    
    // call it for initial centering
    centerThumbs();
    
    // dis is for IE6
    if($.browser.msie  && (jQuery.browser.version.substr(0,3)=="6.0")){
        $('#quickselect').show();
        $('#quickselect').hover
        (
            function(){
                $(this).addClass('js-hover').siblings('#contact').addClass('js-prev-hover');
            },
            function(){
                $(this).removeClass('js-hover').siblings('#contact').removeClass('js-prev-hover');
            }
        );  
    };

    
    if(!($.browser.msie  && (jQuery.browser.version.substr(0,3)=="6.0"))){
    
        // remove fallback class
        $('#colnavi .no-js').removeClass('no-js');
        // longDropdown for quickfinder
        // source: http://css-tricks.com/examples/LongDropdowns/
        var maxHeight = 236;
        
        $('#quickselect').addClass('js-select');
        
        $(function(){
        
            $("#quickselect").hover(function() {
            
                 var $container = $(this),
                     //$list = $container.find("#quickselect-dropdown > ul"),
                     $list = $container.find("#quickselect-dropdown"),
                     $anchor = $container.find("a"),
                     height = $list.height() * 1.1,       // make sure there is enough room at the bottom
                     multiplier = height / maxHeight;     // needs to move faster if list is taller
                
                // need to save height here so it can revert on mouseout            
                $container.data("origHeight", $container.height());
                
                // so it can retain it's rollover color all the while the dropdown is open
                $anchor.addClass("hover");
                
                // for styling
                $(this).addClass("hover").append('<div class="js-bottom"></div>').next().addClass('js-prev-hover');
                
                // make sure dropdown appears directly below parent list item    
                $list
                    .show()
                    .css({
                        paddingTop: $container.data("origHeight")
                    });
                
                // don't do any animation if list shorter than max
                if (multiplier > 1) {
                    $container
                        .css({
                            height: maxHeight,
                            overflow: "hidden"
                        })
                        .mousemove(function(e) {
                            var offset = $container.offset();
                            var relativeY = ((e.pageY - offset.top) * multiplier) - ($container.data("origHeight") * multiplier);
                            if (relativeY > $container.data("origHeight")) {
                                $list.css("top", -relativeY + $container.data("origHeight"));
                            };
                        });
                }
                
            // mouseout    
            }, function() {
            
                var $el = $(this);
                
                // put things back to normal
                $(this).removeClass("hover").find(".js-bottom").remove();
                $(this).next().removeClass('js-prev-hover');
                
                $el
                    .height($(this).data("origHeight"))
                    .find("#quickselect-dropdown")
                    .css({ top: 0 })
                    .hide()
                    .end()
                    .find("a")
                    .removeClass("hover");
            
            });
            
            // Add down arrow only to menu items with submenus
            /*
            $(".dropdown > li:has('ul')").each(function() {
                $(this).find("a:first").append("<img src='images/down-arrow.png' />");
            });
            */
            
        });


    };    

    // empty input fields on click
    $('#search-input, #footer input').focus(function () {
        $(this).val('');
    });
    
    $('#quickselect').hover
    (
        function(){
            $(this).children('#quickselect-dropdown').addClass('hovered');
        },
        function(){
            $(this).children('#quickselect-dropdown').removeClass('hovered');
        }
    );    
    
/*    
    fabrikItemList = [];
    $('#fabrikanimation a').each(function(){
    	fabrikItemList.push($(this));
    });
*/     
    $('#link-waerme').hover
    (
        function(){
            $('#waerme').show();
        },
        function(){
        	$('#waerme').hide();
        }
    );    
    $('#link-kaelte').hover
    (
        function(){
            $('#kaelte').show();
        },
        function(){
        	$('#kaelte').hide();
        }
    );
    $('#link-schall').hover
    (
        function(){
            $('#schall').show();
        },
        function(){
        	$('#schall').hide();
        }
    );
    $('#link-brand').hover
    (
        function(){
            $('#brand').show();
        },
        function(){
        	$('#brand').hide();
        }
    );
    $('#link-sonder').hover
    (
        function(){
            $('#sonder').show();
        },
        function(){
        	$('#sonder').hide();
        }
    );



    
});
/*
    // add clearer before splitted line in contact form in IE
    if($.browser.msie){
        $('#content .tx-pilmailform-pi1 li.p20').before("<br class='clear' />");
    }
*/
/*
    // Slideshow
    $('#head').cycle({ slideExpr: 'span.slideshowimage' });
*/
/*
    $('#quicklinks .loginlist').hide();

    if ( $("a.extranet").parent().next('li:hidden').hasClass('loginlist') ) {
        $("a.extranet").bind("click", function(ev){
                ev.preventDefault();
                $('#quicklinks .loginlist').toggle();
            }
        );
    };
*/
/*
    // Aufklappliste / Akkordion
    $('#content .slide .csc-header').not('.csc-header-n1').css({cursor: "pointer"}).addClass('hidden');
    $('#content .slide .csc-header').not('.csc-header-n1').next('div').hide();
    $('#content .slide .csc-header').not('.csc-header-n1').click(
        function(){
            if($(this).next().css("display")=="none" ){
                $(this).addClass('shown').removeClass('hidden');
                $(this).next('div').slideDown("fast");
            }else{
                $(this).addClass('hidden').removeClass('shown');
                $(this).next('div').slideUp("fast");
            }
        }
    );
*/
/*    
    // callback: hide labels, set text as value
    // add to empty-on-click-list below
    var labelText = $('#footer form label').text();
    $('#footer form label').attr('style','position: absolute; left: -99em').next('input').attr('value',labelText);
*/
/*
*/

