window.onload = function(){
    checkBrowserAndAdjustStyle();
};
function checkBrowserAndAdjustStyle() {
            if ($.browser.msie && $.browser.version < 9) {
                //$('link').remove();
                if ($(window).height() <= 680) {
                    $("head").append('<link href="http://linde.scheringer.de/styles/style.css" type="text/css" media="all" rel="stylesheet">')
                } else if ($(window).height() > 680 && $(window).height() <= 830) {
                    $("head").append('<link href="http://linde.scheringer.de/styles/style-middle.css" type="text/css" media="all" rel="stylesheet">');
                } else if ($(window).height() > 831) {
                    $("head").append('<link href="http://linde.scheringer.de/styles/style-biggest.css" type="text/css" media="all" rel="stylesheet">');
                }

            }

        }
$(document).ready(function() {
    if ($('#impressum') != undefined) {
        $('#impressum').toggle();
        $('#impressum_button').click(function() {
            $('#impressum').toggle();
            checkBrowserAndAdjustStyle();
            setVars();
            setScrollBar();
        });
    }
    checkBrowserAndAdjustStyle();
    
    if ($('#text-holder') != undefined) {
        var visible_text_height = 0;
        var new_box_height = 0;
        var surrounding_box_min_height = 0;

        

        function setVars() {

            if ($(window).height() <= 680) {

                visible_text_height = 366;
                surrounding_box_min_height = 516;
                if ($(window).height() < surrounding_box_min_height) {
                    new_box_height = visible_text_height - (surrounding_box_min_height - $(window).height());
                } else {
                    new_box_height = visible_text_height;
                }
            } else if ($(window).height() > 680 && $(window).height() <= 830) {
                visible_text_height = 380;
                surrounding_box_min_height = 660;
                if ($(window).height() < surrounding_box_min_height) {
                    new_box_height = visible_text_height - (surrounding_box_min_height - $(window).height());
                } else {
                    new_box_height = visible_text_height;
                }
            } else if ($(window).height() > 831) {
                visible_text_height = 380;
                surrounding_box_min_height = 830;
                if ($(window).height() < surrounding_box_min_height) {
                    new_box_height = visible_text_height - (surrounding_box_min_height - $(window).height());
                } else {
                    new_box_height = visible_text_height;
                }
            }
        }

        //alert("window  " + $(window).height() + "  text " + $('#text-holder').innerHeight());
        function setScrollBar() {
            /*if ($('#text-holder').innerHeight() > new_box_height || $(window).height() < surrounding_box_min_height) {

                var oScrollbar = $('#text-holder');
                if ($('#text-holder').has('.scrollbar').length <= 0) {
                    $('#text-holder').wrapInner('<div class="viewport">');
                    $('.viewport').wrapInner('<div class="overview">');
                    $('<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>').insertBefore('.viewport');
                }
                if ($(window).height() <= 680) {
                    $('#content-holder').css("width", 387);
                    //  $('.overview').css("width", 355);
                }
                $('.viewport').css("height", new_box_height);
                $('#text-holder').css("height", new_box_height);
                oScrollbar.tinyscrollbar({
                    axis: 'y',
                    sizethumb: 92
                });
                if (typeof oScrollbar.update == 'function') {
                    oScrollbar.update();
                };
            }*/if ($('#text-holder').innerHeight() >= new_box_height){

                var oScrollbar = $('#text-holder');
                if ($('#text-holder').has('.scrollbar').length <= 0) {
                    $('#text-holder').wrapInner('<div class="viewport">');
                    $('.viewport').wrapInner('<div class="overview">');
                    $('<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>').insertBefore('.viewport');
                }
                if ($(window).height() <= 680) {
                    $('#content-holder').css("width", 387);
                    //  $('.overview').css("width", 355);
                }
                $('.viewport').css("height", new_box_height);
                $('#text-holder').css("height", new_box_height);
                oScrollbar.tinyscrollbar({
                    axis: 'y',
                    sizethumb: 92
                });
                if (typeof oScrollbar.update == 'function') {
                    oScrollbar.update();
                };
            } else {
                var oScrollbar = $('#text-holder');
                if ($('#text-holder').has('.scrollbar').length > 0) {
                    $('.scrollbar').addClass('disable');
                    $('#content-holder').css("width", '');
                  // $('.viewport').css("height", '');
                   $('#text-holder').css("height", '');
                   $('.overview').replaceWith( $('.overview').contents() ); 
                   $('.viewport').replaceWith( $('.viewport').contents() ); 
                     $('.scrollbar').remove();
                    if (typeof oScrollbar.update == 'function') {
                        oScrollbar.update();
                    };
                }
            }/*else if ($(window).height() >= surrounding_box_min_height) {
                var oScrollbar = $('#text-holder');
                if ($('#text-holder').has('.scrollbar').length > 0) {
                    $('.scrollbar').addClass('disable');
                    $('#content-holder').css("width", '');
                    $('.viewport').css("height", new_box_height);
                    $('#text-holder').css("height", new_box_height);

                    if (typeof oScrollbar.update == 'function') {
                        oScrollbar.update();
                    };
                }
            }*/
        }

        $(window).resize(function() {
            checkBrowserAndAdjustStyle();
            setVars();
            setScrollBar();
        });
        
        setVars();
        setScrollBar();
        
        if($('#video')!==null&&typeof jwplayer!='undefined'){
            
           jwplayer('video').setup({
            
            'controlbar': 'over',
            'width': '576',
            'height': '324',
            'autostart':'false',
            'stretching':'extrafit',
            icons:'flase',
            image: "/images/uploads/BG_Termine_663x380.jpg",
            modes: [
                { type: "flash", 
                  src: "/scripts/player/player.swf",
                  config: {
                    image: "/images/uploads/BG_Termine_663x380.jpg",
                    file: "/videos/playlist.xml",
                    skin:"/scripts/player/nacht.zip"
                  }
                },
                { type: "html5",
                
                  config: {
                    image: "/images/uploads/BG_Termine_663x380.jpg",
                    file: "http://linde.scheringer.de/videos/Linde_final_h264_640p_2400kbit.mp4"
                  }
                },
                { type: "download",
                    image: "/images/uploads/BG_Termine_663x380.jpg",
                    file: "http://linde.scheringer.de/videos/Linde_final_h264_720p_5000kbit.mov"
                }
            ]

            //'skin':'/scripts/player/nacht.zip'
          });
        
        }
    }

});
