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";
        var lobj = iobj;

        if (iobj) {
            {
                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);
                    iobj.style.display = "block";
                    iobj.style.zIndex = 1001;


                    if (doUpdate || nOpacity >= 0.99) {
                        for (var ni = 0; ni < self.imgs.length; ni++) {
                            switch (objs[i][7]) {
                                default:
                                case "image":
                                    {
                                        self.imgs[ni].style.display = "none";
                                    } break;
                                case "page":
                                    {
                                        self.imgs[ni].style.zIndex = 100;
                                        if (ni != i) self.imgs[ni].style.display = "none";
                                    } break;
                            }
                        }


                        lobj = iobj;

                        self.increment();
                        self.increment();
                        iobj = self.imgs[self.current];
                        self.current = i;


                        iobj.xOpacity = 0;
                        self.setOpacity(iobj);


                        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";
                    iobj.style.zIndex = 100;
                    self.increment(true);

                    iobj = self.imgs[self.current];
                    iobj.style.display = "block";
                    iobj.style.zIndex = 1000;
                    iobj.xOpacity = 0.99;
                    self.setOpacity(iobj);
                    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");
            var cobj = $$(self.clientid + "_AdHtml");
            i = self.current;
            switch (objs[i][7]) {
                default:
                case "image":
                    {
                        aobj.style.display = "inline-block";
                        cobj.style.display = "none";
                        iobj.style.display = "block";
                        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";
                    } break;
                case "page":
                    {
                        cobj.style.display = "block";
                        aobj.style.display = "none";
                        lobj.style.zIndex = 1000;
                        lobj.xOpacity = 0.99;
                        self.setOpacity(lobj);

                        if ($) {
                            var jso = $(".execJS", $(lobj));
                            if (jso.length > 0) eval(jso[0].innerHTML);
                        }

                    } break;
            }

            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;

        $$(self.clientid + "_AdHtml").style.display = "none";

        for (var i = 0; i < objs.length; i++) {
            var mode = objs[i][7];
            switch (mode) {
                default:
                case "image":
                    {
                        self.imgs[i] = document.createElement("IMG");
                        self.imgs[i].src = objs[i][0];
                        self.imgs[i].style.display = "none";
                        self.imgs[i].xOpacity = 0;
                        $$(self.clientid + "_AdA").appendChild(self.imgs[i]);
                    } break;
                case "page":
                    {
                        self.imgs[i] = document.getElementById(self.clientid + "_adContent_" + i);
                        self.imgs[i].style.display = "block";
                        self.imgs[i].xOpacity = 0;
                        self.imgs[i].style.position = "absolute";
                        self.imgs[i].style.backgroundColor = "#fff";
                        self.imgs[i].style.zIndex = 100;
                        $$(self.clientid + "_AdHtml").appendChild(self.imgs[i]);
                    } break;
            }
            self.imgs[i].className = "adContent";
        }


        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 + "_pnlAds").onmouseover = function () { navObj.style.display = "inline-block"; };
            $$(self.clientid + "_pnlAds").onmouseout = function () { navObj.style.display = "none"; };

            $$(self.clientid + "_pnlAds").className = "adNavContainer";
            $$(self.clientid + "_pnlAds").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 + "_pnlAds").className = "adNavContainer";
            $$(self.clientid + "_pnlAds").appendChild(navObj);

            var ada = $$(self.clientid + "_pnlAds")
            for (var i = 0; i < self.objs.length; i++) {
                var node = $$(self.clientid + "_dot" + i);
                node.style.zIndex = 2000;
                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();
        }





    }

}


