/*
    (C) Copyright 2005-2006 Bohumil Sladek (bobo@dotek.cz)
*/

    //  Content object (begin)
    //  Objekt definuje metody pro skrolovani vlozeneho dokumentu
    function Content(scrollBy, firstInterval, nextInterval)
    {
        this.ScrollByDef = 0;

        this.ScrollBy = scrollBy;
        this.ScrollByTmp = this.ScrollBy;
        this.FirstInterval = firstInterval;
        this.NextInterval = nextInterval;

        this.scrollInterval = null;
        this.scrollTimeout = null;

        this.OnKeyUp = Content_OnKeyUp;
        this.OnKeyDown = Content_OnKeyDown;

        this.OnMouseWheel = Content_OnMouseWheel;

        this.ScrollDown = Content_ScrollDown;
        this.ScrollUp = Content_ScrollUp;
        this.Scroll = Content_Scroll;

        this.AutoScrollOn = Content_AutoScrollOn;
        this.AutoScrollOff = Content_AutoScrollOff;

        this.InitAutoScroll = Content_InitAutoScroll;

        this.GetElement = Content_GetElement;

        this.CanScroll = Content_CanScroll;
    }

    function Content_OnKeyDown(e)
    {
        var eventObject = (BIF.isW3cc) ? e : window.event;

        switch(eventObject.keyCode)
        {
            case 38:
                // Up
                this.AutoScrollOn("Up", 20);
                break;
            case 40:
                // Down
                this.AutoScrollOn("Down", 20);
                break;
            case 33:
                // PageUp
                this.AutoScrollOn("Up", 400);
                break;
            case 34:
                // PageDown
                this.AutoScrollOn("Down", 400);
                break;
            default:
                break;
        }
    }

    function Content_OnKeyUp(e)
    {
        var eventObject = (BIF.isW3cc) ? e : window.event;

        switch(eventObject.keyCode)
        {
            case 38:
                // Up
                this.AutoScrollOff();
                break;
            case 40:
                // Down
                this.AutoScrollOff();
                break;
            case 33:
                // PageUp
                this.AutoScrollOff();
                break;
            case 34:
                // PageDown
                this.AutoScrollOff();
                break;
                // Home
                // End
            default:
                break;
        }
    }

    function Content_OnMouseWheel(e)
    {
        var eventObject = (BIF.isW3cc) ? e : window.event;

        if (typeof(e.wheelDelta) != "undefined")
        {
            this.ScrollByTmp = (this.ScrollByDef > 0) ? this.ScrollByDef : this.ScrollBy;
            var delta = e.wheelDelta;

            if (delta >= 120)
               this.ScrollUp();
            else if (delta <= -120)
               this.ScrollDown();
        }
    }

    function Content_GetElement()
    {
        return document.getElementById("content");
    }

    function Content_ScrollDown()
    {
        var content = this.GetElement();
        content.scrollTop = content.scrollTop + this.ScrollByTmp;
        UpdateScrollButtonsState();
    }

    function Content_ScrollUp()
    {
        var content = this.GetElement();
        if (content.scrollTop > 0)
        {
            content.scrollTop = content.scrollTop - this.ScrollByTmp;
        }
        UpdateScrollButtonsState();
    }

    function Content_Scroll(direction)
    {
        eval("objContent.Scroll" + direction + "();");
    }

    function Content_InitAutoScroll(direction)
    {
        if (this.scrollTimeout != null)
            window.clearTimeout(this.scrollTimeout);

        this.Scroll(direction);
        this.scrollInterval = window.setInterval("objContent.Scroll('" + direction + "')", this.NextInterval);
    }

    function Content_AutoScrollOn(direction, scrollBy)
    {
        this.AutoScrollOff();

        if (scrollBy != null)
            this.ScrollByTmp = (this.ScrollByDef > 0) ? this.ScrollByDef : scrollBy;

        this.Scroll(direction);

        this.scrollTimeout = window.setTimeout("objContent.InitAutoScroll('" + direction + "')", this.FirstInterval);
    }

    function Content_AutoScrollOff()
    {
        this.ScrollByTmp = (this.ScrollByDef > 0) ? this.ScrollByDef : this.ScrollBy;

        if (this.scrollTimeout != null)
            window.clearTimeout(this.scrollTimeout);
        if (this.scrollInterval != null)
            window.clearInterval(this.scrollInterval);
    }

    function Content_CanScroll(direction)
    {
        var content = this.GetElement();
        if (direction == "Up")
        {
            return (content.scrollTop > 0);
        }
        else
        {
            return (content.scrollTop < content.scrollHeight - content.offsetHeight) ;
        }
    }
    var objContent = new Content(40, 800, 80);
    //  Content object (end)

