/*      DEZE JAVA SCRIPTS ZIJN BEWERKT OP
        19 maart 2011
*/
//----------------------- ANIMATION OBJECT VOOR imageObj
function animate1Frame(){ // 1 staat voor One-direction alleen van 1 tot aantal en dan weer vanvorenafaan
        this.teller++;
        if (this.teller >= this.aantal) {
                this.teller = 0;
        }
        clearTimeout(this.timer)
        this.$imgObj.css({ backgroundImage : 'url('+this.imA[this.teller].src+')' });
}

function animate1Loop(){ // 1 staat voor One-direction alleen van 1 tot aantal en dan weer vanvorenafaan
        this.teller++;
        if (this.teller >= this.aantal) {
                this.teller = 0;
        }
        this.$imgObj.css({ backgroundImage : 'url('+this.imA[this.teller].src+')' });
        clearTimeout(this.timer)
        this.timer = setTimeout(this.naamObj + "AIObj.animate1Loop()", this.tijd);
}

function animate1LoopW(){ // 1 staat voor One-direction alleen van 1 tot aantal en dan weer vanvorenafaan
        this.teller++;
        if (this.teller >= this.aantal) {
                this.teller = 0;
        }
        this.$imgObj.css({ backgroundImage : 'url('+this.imA[this.teller].src+')' });
        clearTimeout(this.timer)
        if (this.teller == 0) this.timer = setTimeout(this.naamObj + "AIObj.animate1LoopW()", 3000);
        else this.timer = setTimeout(this.naamObj + "AIObj.animate1LoopW()", this.tijd);
}

function animate1(){ // 1 staat voor One-direction alleen van 1 tot aantal en dan weer vanvorenafaan
        this.teller++;
        if (this.teller >= this.aantal) {
                this.teller = 0;
                clearTimeout(this.timer);
                this.timer = null;
                if (this.volgendeFunctie != "") this.timer = setTimeout(this.volgendeFunctie,10)
                return;
        }
        this.$imgObj.css({ backgroundImage : 'url('+this.imA[this.teller].src+')' });
        clearTimeout(this.timer)
        this.timer = setTimeout(this.naamObj + "AIObj.animate1()", this.tijd);
}
                        //DEZE FUNCTIE IS AFGELEID VAN animate2Loop(). DE setTimeout(...) ONTBREEKT, DEZE FUNCTIE MOET WORDEN
                        //GEACTIVEERD DOOR EEN ANDERE FUNCTIE VOOR SYNCHRONITEIT MET BEWEGING IN EEN makeAnimationPositionObj OBJECT!!!
function animate2Frame(){ // 2 staat voor Two-direction van 0 naar aantal en weer terug naar 0
        this.teller += this.factor;
        if ((this.teller < 1)||(this.teller > (this.aantal - 2))) {
                this.factor *= -1;
        }
        clearTimeout(this.timer)
        this.$imgObj.css({ backgroundImage : 'url('+this.imA[this.teller].src+')' });
}

function animate2Loop(){ // 2 staat voor Two-direction van 0 naar aantal en weer terug naar 0
        this.teller += this.factor;
        if ((this.teller < 1)||(this.teller > (this.aantal - 2))) {
                this.factor *= -1;
        }
        this.$imgObj.css({ backgroundImage : 'url('+this.imA[this.teller].src+')' });
        clearTimeout(this.timer)
        this.timer = setTimeout(this.naamObj + "AIObj.animate2Loop()", this.tijd);
}

function animate2LoopW(){ // 2 staat voor Two-direction van 0 naar aantal en weer terug naar 0
        this.teller += this.factor;
        if ((this.teller < 1)||(this.teller > (this.aantal - 2))) {
                this.factor *= -1;
        }
        this.$imgObj.css({ backgroundImage : 'url('+this.imA[this.teller].src+')' });
        clearTimeout(this.timer)
        if ((this.teller == 0)||(this.teller == this.aantal -1)) this.timer = setTimeout(this.naamObj + "AIObj.animate2LoopW()", 3000);
        else this.timer = setTimeout(this.naamObj + "AIObj.animate2LoopW()", this.tijd);
}

function animate2(){ // One staat voor One-direction alleen van 1 tot aantal en dan weer vanvorenafaan
        this.teller += this.factor;
        if ((this.teller < 1)||(this.teller > (this.aantal - 2))) {
                this.factor *= -1;
        }
        this.$imgObj.css({ backgroundImage : 'url('+this.imA[this.teller].src+')' });
        if (this.teller == 0) {
                this.factor *= -1;
                clearTimeout(this.timer);
                this.timer = null;
                if (this.volgendeFunctie != "") this.timer = setTimeout(this.volgendeFunctie,10)
                return;
        }
        clearTimeout(this.timer)
        this.timer = setTimeout(this.naamObj + "AIObj.animate2()", this.tijd);
}

function setFirstFrame(){ this.teller = 0; this.factor = 1; }

function setLastFrame(){ this.teller = this.aantal - 1; this.factor = -1;}

function setZIndexAIObj(ind){ this.imgObj.css({ zIndex : ind }); }

function getZIndexAIObj(ind){ return getZIndex(this.naamDiv+"Id"); }

function stopAIObj(){ clearTimeout(this.timer); this.timer = null; }
                     // bv. var eekhoornRentAIObj = copyAnimationImageObj("eekhoorn2Rent", eekhoornKlimtAIObj, "eekhoornRent", ".gif",  enz...)
                        // het is belangrijk dat de variabele uit pNaamSource + "AIObj" wordt samengesteld, dan werken de scripts goed
                        // var eekhoornRentAIObj = copyAnimationImageObj(eekhoornKlimtAIObj, "eekhoornRent", ".gif", 4) gaat om:
                        //        <DIV =eekhoornKlimtAIObj.naamDiv + "Id"> <IMG name='eekhoornKlimtAIObj.naamDiv + "Img"'> en eekhoornRent1.gif, eekhoornRent2.gif t/m eekhoornRent5.gif
function r_AIObj(pNaamObj, pNaamDiv,  pNaamSource, pExtensie, pWidth, pHeight, pAantal, pTijd){
        this.naamObj = pNaamObj //deze pNaamObj + "AIObj" is de naam die je de objectvariabele (laatste regel deze constructor: return this !!) moet geven
                // b.v. als pNaamObj(this.naamObj) == "eekhoorn2loopt" dan is de variabele eekhoorn2looptAIObj  en hoort bij plaatjes eekhoornloopt1.jpg, eekhoornloopt2.jpg enz!!
        this.naamDiv = pNaamDiv
        this.$imgObj = $("#"+this.naamDiv);
        this.width = pWidth
        this.height = pHeight
        this.aantal = pAantal
        this.imA = new Array(this.aantal)
        this.timer = null;
        this.teller = 0;
        this.factor = 1;
        this.tijd = pTijd;
				this.volgendeFunctie = "" // deze functie wordt uitgevoerd als animate1 of animate2 klaar zijn
        this.stop = stopAIObj;
        this.animate1 = animate1
        this.animate1Loop = animate1Loop
        this.animate1Frame = animate1Frame
        this.animate2 = animate2
        this.animate2Loop = animate2Loop
        this.animate2Frame = animate2Frame
        this.setFirstFrame = setFirstFrame
        this.setLastFrame = setLastFrame
        this.setZIndex = setZIndexAIObj
        this.getZIndex = getZIndexAIObj
        for (var i = 0 ; i < this.aantal ; i++) {
                this.imA[i] = new Image(this.width, this.height);
                this.imA[i].src= pNaamSource + (i + 1) + pExtensie
        }
        return this
}
                        // pAIObj is een ander AnimationImageObj-object, waaruit de volgende 4 waarden worden getrokken:
                        // this.naamDiv, this.width, this.height, en this.tijd
function r_copyAIObj(pNaamObj, pExtAIObj, pNaamSource, pExtensie, pAantal){
        return new r_AIObj(pNaamObj, pExtAIObj.naamDiv,  pNaamSource, pExtensie, pExtAIObj.width, pExtAIObj.height, pAantal, pExtAIObj.tijd)
}
                        // bv. var eekhoorn1KlimtAIObj = makeAnimationImageObj("eekhoorn1Klimt", "eekhoorn", "eekhoornKlimt", ".gif",  enz...)
                        // het is belangrijk dat de variabele uit pNaamObj + "AIObj" wordt samengesteld, dan werken de scripts goed
                        // var eekhoorn1KlimtAIObj = makeAnimationImageObj("eekhoorn1Klimt", "eekhoorn", "eekhoornKlimt", ".gif", 5, 50) gaat om:
                        //        <DIV =eekhoornId> <IMG name="eekhoornImage"> en eekhoornKlimt1.gif, eekhoornKlimt2.gif t/m eekhoornKlimt5.gif

////////////////////////////
function make_divaio(pnaam,pappendid, ppos,pleft,ptop,pwidth,pheight,pzind, pimgnaam, pext, paantal,ptijd, pclick, pmouseover, pmouseout){
	make_divimg(pnaam, pappendid, ppos, pleft, ptop, pwidth, pheight, pzind, pimgnaam+"1"+pext , pclick, pmouseover, pmouseout);
	return new r_AIObj(pnaam, pnaam,  pimgnaam, pext, pwidth, pheight, paantal, ptijd);
}

function make_divimg(pnaam, pappendid, ppos,pleft,ptop,pwidth,pheight,pzind, pimg, pclick, pmouseover, pmouseout){
	$(pappendid).append("<div id='" +pnaam + "' ></div>");
	$dd = $("#"+pnaam);
	if (ppos == "a") ppos = "absolute"; if (ppos == "r") ppos = "relative";
	$dd.css({ position: ppos, backgroundColor:'transparent', lineHeight:'1px', fontSize:'1px', zIndex: pzind  });
	$dd.css({top : ptop, left : pleft , width : pwidth , height : pheight , visibility : 'visible', backgroundImage : 'url(' + pimg + ')' });
	if (pclick != "") $('#'+pnaam).click(function(){ eval(pclick);});
	if (pmouseover != "") $('#'+pnaam).mouseover(function(){ eval(pmouseover);});
	if (pmouseout != "") $('#'+pnaam).mouseout(function(){ eval(pmouseout);});
}


