﻿
var Animation = function(num, count) {
    this.num = num;
    this.currentBlock = -1;
    this.bannerCount = count;

    /*this.changeBanner = function() {
    this.tick();
    var _me = this;
    window.setTimeout(function () { _me.changeBanner(); }, 5000, _me);
    }*/

    this.valid = function() {
        return $j('#anim' + this.num).length != 0;
    }

    this.tick = function() {
        var offset = $j('#anim' + this.num).offset();

        this.nextBlock = (this.currentBlock + 1 == this.bannerCount ? 0 : this.currentBlock + 1);
        //For first tick
        if (this.currentBlock == -1)
            this.currentBlock = 0;
        var newZ = parseInt($j('#img_' + this.num + '_' + this.currentBlock).css('z-index')) + 1;
        $j('#img_' + this.num + '_' + this.currentBlock).hide();

        $j('#img_' + this.num + '_' + this.nextBlock).css('left', offset.left);
        $j('#img_' + this.num + '_' + this.nextBlock).css('top', offset.top);
        $j('#img_' + this.num + '_' + this.nextBlock).hide();
        $j('#img_' + this.num + '_' + this.nextBlock).css('z-index', newZ);
        $j('#img_' + this.num + '_' + this.nextBlock).fadeIn('slow');
        this.currentBlock = this.nextBlock;
        return true;
    }

    //this.changeBanner();	            
}

var anim1 = null;
function RunAnim(num, count) {
    anim1 = new Animation(num, count);
    Tick();
}

function Tick() {
    if (anim1 != null && anim1.valid()) {
        anim1.tick();
    }
    window.setTimeout(function() { Tick(); }, 7000);
}



