function AdRotator(clientid, objs) {
    this.clientid = clientid;
    this.imgs = new Array();

    this.zInterval = null;
    this.current = 0;
    this.pause = true;
    this.aniPause = 3;
    this.aniTime = 2;
    this.aniSegments = 30;
    this.objs = objs;
    this.lastImage = null;
    this.Navigation = false;
    this.Direction = 1;
    this.inc = 0;
    this.rotate = true;
    this.random = false;
    this.remember = true;
    this.cookieKey = "AdRotator_" + clientid;
    this.textPrevious = "&lt; previous";
    this.textNext = "next &gt;";
    this.showDots = false;
    this.setCurrent = -1;
    this.last = 0;
    this.ani = null;
    var self = this;

    this.setOpacity = function (obj) {
        if (obj.xOpacity > .99) {
            obj.xOpacity = .99;
            return;
        }
        obj.style.opacity = obj.xOpacity;
        obj.style.MozOpacity = obj.xOpacity;
        if (document.all)
            obj.style.filter = "alpha(opacity=" + (obj.xOpacity * 100) + ")";
    }


    this.display = function (doUpdate, inc) {
        if (inc != self.inc) {
            return;
        }

        var objs = self.objs;

        var update = false;

        if (doUpdate) update = true;

        var i = self.current;
        var iobj = self.imgs[i];

        self.ani = objs[self.current][6] == "True";

        if (iobj) {
            if (!(iobj.src == "" || iobj.src == null || iobj.src == undefined)) {
                if (self.ani) {

                    var temp = i;
                    self.increment();
                    i = self.current;
                    self.current = temp;
                    iobj = self.imgs[i];

                    var nOpacity = iobj.xOpacity;

                    nOpacity += 1 / self.aniSegments;
                    iobj.xOpacity = nOpacity;
                    self.setOpacity(iobj);


                    if (doUpdate || nOpacity >= 0.99) {
                        for (var ni = 0; ni < self.imgs.length; ni++) self.imgs[ni].style.display = "none";
                        self.increment();
                        self.increment();
                        iobj = self.imgs[self.current];
                        self.current = i;

                        iobj.xOpacity = 0;
                        self.setOpacity(iobj);
                        iobj.style.display = "block";

                        update = true;

                        if (self.rotate) setTimeout(self.clientid + "_Ad.display(false," + self.inc + ");", objs[self.current][5] * 1000);
                    } else {
                        setTimeout(self.clientid + "_Ad.display(false," + self.inc + ");", self.aniTime / self.aniSegments * 1000);
                    }
                } else {
                    iobj.style.display = "none";
                    self.increment(true);

                    self.imgs[self.current].style.display = "block";
                    self.imgs[self.current].xOpacity = 0.99;
                    self.setOpacity(self.imgs[self.current]);
                    i = self.current;

                    if (self.rotate) setTimeout(self.clientid + "_Ad.display(false," + self.inc + ");", objs[self.current][5] * 1000);

                    update = true;
                }
            }

            if (!update) return;

            var aobj = $$(self.clientid + "_AdA");
            i = self.current;
            aobj.style.backgroundImage = "url(" + objs[i][0] + ")";
            aobj.href = objs[i][3];
            aobj.ahref = objs[i][3];
            aobj.target = (objs[i][4] == "True") ? "_blank" : "_self";

            self.selectDot();

        }
    }

    this.increment = function () {
        var i = self.current;
        if (self.setCurrent == -1) {
            if (self.Direction > 0) {
                self.current = self.imgs[i + self.Direction] ? i + self.Direction : 0;
            } else {
                self.current = self.imgs[i + self.Direction] ? i + self.Direction : self.imgs.length - 1;
            }
        } else {
            self.current = self.setCurrent;
            self.setCurrent = -1;
        }
    }

    this.navigate = function (dir) {

        if (self.remember) {
            SimpleSetCookie(this.cookieKey, self.current);
        }

        if (dir == "next") {
            self.Direction = 1;
        } else if (dir == "previous") {
            self.Direction = -1;
        } else {
            self.setCurrent = parseInt(dir);
        }

        self.inc++;
        self.display(true, self.inc);
    }

    this.selectDot = function () {
        if (!self.showDots) return;

        for (var i = 0; i < self.objs.length; i++) {
            var obj = $$(self.clientid + "_dot" + i);
            if (obj) obj.src = "/img/addot-" + (self.current == i ? "s" : "n") + "el.png";
        }
    }

    this.initialize = function () {
        var objs = self.objs;

        for (var i = 0; i < objs.length; i++) {
            self.imgs[i] = document.createElement("IMG");
            self.imgs[i].style.display = "none";
            self.imgs[i].src = objs[i][0];
            self.imgs[i].xOpacity = 0;
            $$(self.clientid + "_AdA").appendChild(self.imgs[i]);
        }


        if (self.random) {
            var index = objs.length * Math.random();
            index = Math.ceil(index);
            if (index >= objs.length) index = 0;
            self.current = index;
        }

        if (self.remember) {
            var index = SimpleGetCookie(self.cookieKey);
            if (index) {
                try {
                    index = parseInt(index);
                    index++;

                    if (index < 0) index = 0;
                    if (index >= objs.length) index = 0;
                    self.current = index;
                    if (isNaN(self.current)) self.current = 0;
                } catch (e) { }
            }

            SimpleSetCookie(this.cookieKey, self.current);
        }

        self.display(true, self.inc);

        if (self.Navigation) {
            var nav = "<div class='adNavLeft'><span id='" + self.clientid + "_leftNav'>" + self.textPrevious + "</span></div>" +
			"<div class='adNavRight'><span id='" + self.clientid + "_rightNav'>" + self.textNext + "</span></div>";
            var navObj = document.createElement("DIV");
            navObj.innerHTML = nav;
            navObj.inc = self.clientid + "_nav";
            navObj.className = "adNav";

            $$(self.clientid + "_AdA").onmouseover = function () { navObj.style.display = "inline-block"; };
            $$(self.clientid + "_AdA").onmouseout = function () { navObj.style.display = "none"; };

            $$(self.clientid + "_AdA").className = "adNavContainer";
            $$(self.clientid + "_AdA").appendChild(navObj);
            $$(self.clientid + "_leftNav").onclick = function () { self.navigate("previous"); return false; };
            $$(self.clientid + "_rightNav").onclick = function () { self.navigate("next"); return false; };
        }

        if (self.showDots) {
            var nav = "<div class='adDots'>";
            for (var i = 0; i < self.objs.length; i++) {
                nav += "<span><img src='/img/addot-nel.png' id='" + self.clientid + "_dot" + i + "' /></span>";
            }
            nav += "</div>";
            var navObj = document.createElement("DIV");
            navObj.innerHTML = nav;
            navObj.className = "adNavDots";
            $$(self.clientid + "_AdA").className = "adNavContainer";
            $$(self.clientid + "_AdA").appendChild(navObj);

            var ada = $$(self.clientid + "_AdA")
            for (var i = 0; i < self.objs.length; i++) {
                var node = $$(self.clientid + "_dot" + i);
                eval("node.onclick = function () { self.navigate(" + i + "); return false; };");
                node.onmouseover = function () { ada.ahref = ada.href + ""; ada.href = "javascript:"; }
                node.onmouseout = function () { ada.href = ada.ahref; }
            }
            self.selectDot();
        }





    }

}

