// JavaScript Document
var contentobj = document.getElementById ? document.getElementById("content") : document.all.content;
var htmlcontentobj = document.getElementById ? document.getElementById("htmlcontent") : document.all.htmlcontent;
var containerobj = document.getElementById ? document.getElementById("container") : document.all.container;
var scrollcontainerobj = document.getElementById ? document.getElementById("scrollcontainer") : document.all.scrollbar;
var scrollerobj = document.getElementById ? document.getElementById("scroller") : document.all.scroller;
var scrollbarobj = document.getElementById ? document.getElementById("scrollbar") : document.all.scrollbar;
var scrollpfeil_obenobj = document.getElementById ? document.getElementById("scrollpfeil_oben") : document.all.scrollbar;
var scrollpfeil_untenobj = document.getElementById ? document.getElementById("scrollpfeil_unten") : document.all.scrollbar;
var flashcontentobj = document.getElementById ? document.getElementById("flashcontent") : document.all.flashcontent;

var scrollerheight = 100;
var mouseposition = 0;
var mousetop = 0;
var scrollerpercent = 0;
var contentobjposition = 0;
var speed = 30;
var direction = -1;
var scrollit = false;
var wheelit = false;
var scrollitupdown = false;

if (containerobj) {

    var containeroffsettop = htmlcontentobj.offsetTop + containerobj.offsetTop;
    var contentheightneu = containerobj.offsetHeight - (parseInt(displayheight));
    var contentheight = contentobj.offsetHeight - (parseInt(displayheight));
    var displayheight = containerobj.offsetHeight;
    var scrollbarheight = scrollbarobj.offsetHeight;
    
    //die h�he des inhalts wird ermittelt, damit dieser nachher prozentual entsprechend der position des scrollers an die richtige stelle springen kann.	
    function getContentHeight(){
    
        /*
         
         containeroffsettop =htmlcontentobj.offsetTop + containerobj.offsetTop;
         displayheight=containerobj.offsetHeight;
         contentheight=contentobj.offsetHeight-(parseInt(displayheight));
         if(contentheightneu!=contentheight){
         showScroller(contentheight);
         contentheightneu=contentheight;
         }
         */
        screenheight = bodyobj.offsetHeight;
        screenwidth = bodyobj.offsetWidth;
	
        
        if (screenheight < 680) {
            flashcontentobj.style.height = "680px";
			htmlcontentobj.style.marginTop = "0px";
			htmlcontentobj.style.top = "100px";
        }
        else {
            flashcontentobj.style.height = "100%";
			htmlcontentobj.style.marginTop = "-243px";
			htmlcontentobj.style.top = "50%";
        }
        if (screenwidth < 1005) {
            flashcontentobj.style.width = "1005px";
			htmlcontentobj.style.marginLeft = "0px";
			htmlcontentobj.style.left = "200px";
        }
        else {
            flashcontentobj.style.width = "100%";
			htmlcontentobj.style.marginLeft = "-300px";
			htmlcontentobj.style.left = "50%";
        }
        
    }
    //der scrollbar soll nur angezeigt und das js gestartet werden, wenn der content h�her als der display div ist.
    function showScroller(contentheight){
        if (contentheight > 0) {
            scrollcontainerobj.style.display = "block";
            htmlcontentobj.onmousemove = doScroll;
            document.onmouseup = stopScroll;
            scrollbarobj.onmousedown = startScroll;
            scrollpfeil_obenobj.onmousedown = startScrollUp;
            scrollpfeil_untenobj.onmousedown = startScrollDown;
            scrollpfeil_obenobj.onmouseup = stopScrollUpDown;
            scrollpfeil_untenobj.onmouseup = stopScrollUpDown;
            scrollpfeil_obenobj.onmouseout = stopScrollUpDown;
            scrollpfeil_untenobj.onmouseout = stopScrollUpDown;
            startWheel();
            setScrollerToPosition();
            if (window.addEventListener) {
                window.addEventListener('DOMMouseScroll', doWheel, false);
            }
            window.onmousewheel = document.onmousewheel = doWheel;
        }
        else {
            contentobj.style.top = 0 + "px";
            scrollcontainerobj.style.display = "none";
            stopWheel();
        }
    }
    function setScrollerToPosition(){
        contentpercent = getContentPercent();
        if (contentpercent < 95 && contentpercent > 5) {
            scrollerposition = getScrollerobjPosition(contentpercent);
            scrollerobj.style.top = parseInt(scrollerposition) - scrollerheight + "px";
        }
        else 
            if (contentpercent <= 5) {
                scrollerobj.style.top = 0 + "px";
            }
            else 
                if (contentpercent >= 95) {
                    scrollerobj.style.top = 0 + "px";
                    contentobj.style.top = 0 + "px";
                }
    }
    function getMousePosition(mouseevent){
        mouseposition = document.all ? window.event.clientY : mouseevent.pageY;
        var wert = parseInt(mouseposition - containeroffsettop - (scrollerheight / 2));
        return wert;
    }
    function getScrollerPercent(mousetop){
        var wert = ((parseInt(mousetop) + (scrollerheight)) * -100 / (parseInt(displayheight)));
        return wert;
    }
    function getContentobjPosition(scrollerpercent){
        var wert = (parseInt(contentheight) / 100) * (parseInt(scrollerpercent));
        return wert;
    }
    function getContentPercent(){
        var wert = (parseInt(contentobj.style.top) * -100) / parseInt(contentheight);
        return wert;
    }
    function getScrollerobjPosition(contentpercent){
        var wert = (parseInt(displayheight) / 100) * parseInt(contentpercent) - (scrollerheight / 2);
        return wert;
    }
    function doNotScroll(mouseevent){
        return false;
    }
    function startScroll(e){
        scrollit = true;
    }
    function stopScroll(e){
        scrollit = false;
    }
    function startWheel(e){
        wheelit = true;
    }
    function stopWheel(e){
        wheelit = false;
    }
    function startScrollUp(e){
        scrollitupdown = true;
        direction = 1;
        doArrowScroll();
    }
    function startScrollDown(e){
        scrollitupdown = true;
        direction = -1;
        doArrowScroll();
    }
    function stopScrollUpDown(e){
        scrollitupdown = false;
    }
    function doScroll(mouseevent){
        if (scrollit == true) {
            mousetop = getMousePosition(mouseevent);
            scrollerpercent = getScrollerPercent(mousetop);
            contentobjposition = getContentobjPosition(scrollerpercent);
            
            if (mousetop <= (displayheight - scrollerheight) && mousetop >= 0) {
                scrollerobj.style.top = mouseposition - containeroffsettop - (scrollerheight / 2) + "px";
                contentobj.style.top = contentobjposition + "px";
            }
            else 
                if (mousetop > (displayheight - scrollerheight)) {
                    scrollerobj.style.top = (parseInt(displayheight - scrollerheight)) + "px";
                    contentobj.style.top = -(parseInt(contentheight)) + "px";
                }
                else 
                    if (mousetop < 0) {
                        scrollerobj.style.top = 0 + "px";
                        contentobj.style.top = 0 + "px";
                    }
        }
    }
    
    function doWheel(event){
        if (wheelit == true) {
            var delta = 0;
            if (!event) {
                event = window.event;
            }
            if (event.wheelDelta) {
                delta = event.wheelDelta / 120;
                if (window.opera) {
                    delta = -delta;
                }
            }
            else 
                if (event.detail) {
                    delta = -event.detail / 3;
                }
            if (delta) {
                if (!scrollerobj.style.top) {
                    scrollerobj.style.top = 0 + "px";
                }
                if (!contentobj.style.top) {
                    contentobj.style.top = 0 + "px";
                }
                contentpercent = getContentPercent();
                if (delta < 0) {
                    //scrollt nach unten
                    if (contentpercent < 90) {
                        contentobj.style.top = parseInt(contentobj.style.top) - speed + "px";
                    }
                    contentpercent = getContentPercent();
                    scrollerposition = getScrollerobjPosition(contentpercent);
                    scrollerobj.style.top = parseInt(scrollerposition) + "px";
                    
                    if (contentpercent >= 90) {
                        scrollerobj.style.top = (parseInt(displayheight - scrollerheight)) + "px";
                        contentobj.style.top = -(parseInt(contentheight)) + "px";
                    }
                }
                else {
                    //scrollt nach oben
                    if (contentpercent > 10) {
                        contentobj.style.top = parseInt(contentobj.style.top) + speed + "px";
                    }
                    contentpercent = getContentPercent();
                    scrollerposition = getScrollerobjPosition(contentpercent);
                    scrollerobj.style.top = parseInt(scrollerposition) + "px";
                    
                    if (contentpercent <= 10) {
                        scrollerobj.style.top = 0 + "px";
                        contentobj.style.top = 0 + "px";
                    }
                }
            }
        }
    }
    
    
    
    function doArrowScroll(){
        if (scrollitupdown == true) {
            if (!scrollerobj.style.top) {
                scrollerobj.style.top = 0 + "px";
            }
            if (!contentobj.style.top) {
                contentobj.style.top = 0 + "px";
            }
            contentpercent = getContentPercent();
            if (direction < 0) {
                //scrollt nach unten
                if (contentpercent < 90) {
                    contentobj.style.top = parseInt(contentobj.style.top) - speed + "px";
                }
                contentpercent = getContentPercent();
                scrollerposition = getScrollerobjPosition(contentpercent);
                scrollerobj.style.top = parseInt(scrollerposition) + "px";
                
                if (contentpercent >= 90) {
                    scrollerobj.style.top = (parseInt(displayheight) - scrollerheight) + "px";
                    contentobj.style.top = -(parseInt(contentheight)) + "px";
                }
                
            }
            else {
                //scrollt nach oben
                if (contentpercent > 5) {
                    contentobj.style.top = parseInt(contentobj.style.top) + speed + "px";
                }
                contentpercent = getContentPercent();
                scrollerposition = getScrollerobjPosition(contentpercent);
                scrollerobj.style.top = parseInt(scrollerposition) + "px";
                
                if (contentpercent <= 5) {
                    scrollerobj.style.top = 0 + "px";
                    contentobj.style.top = 0 + "px";
                }
                
            }
            window.setTimeout("doArrowScroll()", 30);
        }
    }
    
}


if (containerobj) {
    document.onload = getContentHeight;
    document.onresize = getContentHeight;
    //containerobj.onmousemove=getContentHeight
    window.setInterval("getContentHeight()", 500);
}
//-->
