// Scroller OBJECT - soucast DHTML Lib 1.2.1 - dhtmllib.js musi byt nactena

/*  Pixy DOM DHTML Lib 1.2.1
    ------------------------
    Knihovna JS funkci pro snazsi dynamickou manipulaci s HTML dokumenty
    
    Copyright (C) 2001 Petr Stanicek (aka -pixy-), mailto:stanicek@mac.com
    Info, licence, download, kontakt: http://web.iol.cz/pixy/dhtmllib.html
    * GNU/GPL 2.CZE *
    Tato knihovna a jeji soucasti jsou volne programove vybaveni;
    muzete jej sirit a modifikovat podle ustanoveni Obecne verejne licence GNU
    pro Ceskou republiku, vydavane Free Software Foundation a obcanskym sdruzenim
    zastudena.cz, ve verzi 2.CZE teto licence.
    Tento program je rozsirovan v nadeji, ze bude uzitecny, avsak BEZ JAKEKOLI ZARUKY;
    neposkytuji se ani odvozene zaruky PRODEJNOSTI anebo VHODNOSTI PRO URCITY UCEL.
    Dalsi podrobnosti hledejte v Obecne verejne licenci GNU pro Ceskou republiku,
    ktera je soucasti teto knihovny - http://web.iol.cz/pixy/dhtmllib.html
*/

// outerObj i innerObj jsou absolutne pozicovane, padding i border: 0
// Po zmene velikosti se musi znovu inicializovat kazdy scroller, jinak nebudou souhlasit rozmery
// napr. windows.onresize = MyScoller.Init();

function ScrollerObj(outerObj, innerObj, padding, allowFullscroll) {
    this.outer = getObj(outerObj);
    this.inner = getObj(innerObj);
    this.pad = padding;
    this.allowFull = allowFullscroll;
    setObjCSSProp(this.outer,'overflow','hidden');
    this.Init();
    }
function ScrollObjInit() {
    var width = getObjW(this.outer);
    var height = getObjH(this.outer);
    this.outW = width - 2*this.pad;
    this.outH = height - 2*this.pad;
	resizeObjTo(this.inner,this.outW,null);
    moveObjTo(this.inner,this.pad,this.pad);
    this.inH = getObjH(this.inner);
    this.minScroll = (this.allowFull) ? -this.outH : 0;
    this.maxScroll = (this.allowFull) ? this.inH : this.inH-this.outH;
    this.midScroll = Math.round((this.maxScroll+this.minScroll)/2);
    this.ScrollFullDn(); this.ShiftMid();
    }
function ScrollObjScrollFullDn() { this.ofs = this.minScroll; this.DoScroll(); }
function ScrollObjScrollFullUp() { this.ofs = this.maxScroll; this.DoScroll(); }
function ScrollObjScrollMid() { this.ofs = this.midScroll; this.DoScroll(); }
function ScrollObjDoScroll() {
    this.inner.style.top = -this.ofs+this.pad+'px';
    setObjClip(this.inner, this.ofs,this.ltr+this.outW, this.ofs+this.outH,this.ltr);
    }
function ScrollObjScrollPgDn() { return this.Scroll(-this.outH); }
function ScrollObjScrollPgUp() { return this.Scroll(this.outH); }

function ScrollObjScroll(n) { // n>0 - nahoru; n<0 - dolu
    if ( ((n<0) && this.ofs>this.minScroll) || ((n>0) && this.ofs<this.maxScroll) ) {
        this.ofs+=n;
        if (this.ofs>this.maxScroll) this.ofs=this.maxScroll;
        if (this.ofs<this.minScroll) this.ofs=this.minScroll;
        this.DoScroll();
        return true;
        }
    else return false;
    }
function ScrollObjShiftFullLeft() { this.ltr = this.outW; this.DoShift(); }
function ScrollObjShiftFullRight() { this.ltr = -this.outW; this.DoShift(); }
function ScrollObjShiftMid() { this.ltr = 0; this.DoShift(); }
function ScrollObjDoShift() {
    this.inner.style.left = -this.ltr+this.pad+'px';
    setObjClip(this.inner, this.ofs, this.ltr+this.outW, this.ofs+this.outH, this.ltr);
    }
function ScrollObjShift(n) { // n>0 - doprava; n<0 - doleva
    if ( ((n<0) && this.ltr>-this.outW) || ((n>0) && this.ltr<this.outW) ) {
        this.ltr+=n;
        if (this.ltr>this.outW) this.ofs=this.outW;
        if (this.ltr<-this.outW) this.ofs=-this.outW;
        this.DoShift();
        return true;
        }
    else return false;
    }

ScrollerObj.prototype.Init = ScrollObjInit;
ScrollerObj.prototype.ScrollFullUp = ScrollObjScrollFullUp;
ScrollerObj.prototype.ScrollFullDn = ScrollObjScrollFullDn;
ScrollerObj.prototype.ScrollMid = ScrollObjScrollMid;
ScrollerObj.prototype.ScrollPgUp = ScrollObjScrollPgUp;
ScrollerObj.prototype.ScrollPgDn = ScrollObjScrollPgDn;
ScrollerObj.prototype.DoScroll = ScrollObjDoScroll;
ScrollerObj.prototype.Scroll = ScrollObjScroll;
ScrollerObj.prototype.ShiftFullLeft = ScrollObjShiftFullLeft;
ScrollerObj.prototype.ShiftFullRight = ScrollObjShiftFullRight;
ScrollerObj.prototype.ShiftMid = ScrollObjShiftMid;
ScrollerObj.prototype.DoShift = ScrollObjDoShift;
ScrollerObj.prototype.Shift = ScrollObjShift;

// AutoScroller OBJECT

function AutoScrollerObj(selfname, outerObj, padding) {
    this.self = selfname;
    this.outer = getObj(outerObj);
    this.pad = padding;
    this.inners = new Array();
    this.innersCnt = 0;
    this.reverse = false;
    this.active = -1;
    this.play = false;
    }
function AutoScrollerObjAddInner(innerObj,horiz,step1,step2,speed1,speed2,pause) {
    var obj = new ScrollerObj(this.outer, innerObj, this.pad, true);
    obj.step1 = step1;
    obj.step2 = step2;
    obj.speed1 = speed1;
    obj.speed2 = speed2;
    obj.pause = pause;
    obj.horiz = horiz;
    obj.wasMid = false;
    this.inners[this.innersCnt] = obj;
    this.DeactivateInner(this.innersCnt);
    this.innersCnt++;
    }
function AutoScrollerObjActivateInner(n) {
    this.active = n;
    var o = this.inners[n];
    if (o.horiz) {
        o.ScrollMid();
        if (o.step1<0) o.ShiftFullLeft(); else o.ShiftFullRight();
        }
    else {
        o.ShiftMid();
        if (o.step1<0) o.ScrollFullUp(); else o.ScrollFullDn();
        }
    o.wasMid = false;
    setObjVisible(o.inner,true);
    }
function AutoScrollerObjDeactivateInner(n) {
    this.active = -1;
    setObjVisible(this.inners[n].inner,false);
    }
function AutoScrollerObjMove() {
    var n,o,p,st,scrolled=false,toMid,isMid=false;
    if (this.play && this.innersCnt) {
        if (this.active<0) this.ActivateInner(0);
        n=this.active; o=this.inners[n];
        if (o.wasMid) st=o.step2;
        else {
            if (o.horiz) {
                toMid = Math.abs(o.ltr);
                if (toMid<=o.step1 && o.step1>0 && o.ltr<0) { st=toMid; isMid=true; }
                else if (-toMid>=o.step1 && o.step1<0 && o.ltr>0) { st=-toMid; isMid=true; }
                else st = o.step1;
                }
            else {
                toMid = Math.abs(o.midScroll-o.ofs);
                if (toMid<=o.step1 && o.step1>0 && o.ofs<o.midScroll) { st=toMid; isMid=true; }
                else if (-toMid>=o.step1 && o.step1<0 && o.ofs>o.midScroll) { st=-toMid; isMid=true; }
                else st = o.step1;
                }
            }
        if (isMid && !o.wasMid) o.wasMid=true;
        scrolled = (o.horiz) ? o.Shift(st) : o.Scroll(st);
        p = (isMid) ? o.speed1+o.pause : (o.wasMid) ? o.speed2: o.speed1;
        if (!scrolled) {
            this.DeactivateInner(n);
            n++;
            if (n>=this.innersCnt) n=0;
            this.ActivateInner(n);
            }
        setTimeout(this.self+".Move()",p);
        }
    }
function AutoScrollerObjGo(on) {
    this.play = on;
    if (this.play) this.Move();
    }
function AutoScrollerObjReinitAll() { for (var i=0; i<this.innersCnt; i++) this.inners[i].Init(); }

AutoScrollerObj.prototype.AddInner = AutoScrollerObjAddInner;
AutoScrollerObj.prototype.ActivateInner = AutoScrollerObjActivateInner;
AutoScrollerObj.prototype.DeactivateInner = AutoScrollerObjDeactivateInner;
AutoScrollerObj.prototype.Move = AutoScrollerObjMove;
AutoScrollerObj.prototype.Go = AutoScrollerObjGo;
AutoScrollerObj.prototype.ReinitAll = AutoScrollerObjReinitAll;

