AdvRotator.objects = [];
function AdvRotator(advname, interval){
    var index = AdvRotator.objects.length;
    AdvRotator.objects[index] = this;
    this.advname = advname;
    this.link = document.getElementById(this.advname);    
    this.image = null;
    this.imgWidth = 0;
    this.imgHeight = 0;
    this.interval = interval * 1000;			
    this.nCount = 0;
    this.nCurrent = -1;
    this.arrImg = null;
    this.arrLink = null;
    this.arrText = null;
    this.arrSeq = null;
    this.popup = true;
    this.prefixImg = null;
    this.prefixUrl = null;
    this.name = "AdvRotator.objects[" + index + "]";			
    this.started = false;
    this.pageId = null;
    this.sectionId = null;
    this.itemNo = 0;
			
    this.setImageSize = function(width, height){
        this.imgWidth = width;
        this.imgHeight = height;
    }	
    this.setClickCountParam = function(page, section, item){
				this.pageId = page;
				this.sectionId= section;
				this.itemNo = item;
    }
    this.setImagePrefix = function(imgPrefix){
        this.prefixImg = imgPrefix;
    }
    this.setUrlPrefix = function(urlPrefix){
        this.prefixUrl = urlPrefix;
    }
    this.setPopup = function(pop){
        this.popup = pop;
    }
    this.add = function(imgSrc, link, text, isPopup, disableImgPrefix, disableUrlPrefix) {
        if (this.arrImg == null) this.arrImg = new Array();
        if (this.arrLink == null) this.arrLink = new Array();
        if (this.arrText == null) this.arrText = new Array();
        if (this.arrSeq == null) this.arrSeq = new Array();
        if (isPopup == null) isPopup = this.popup;
        if (disableImgPrefix == null) disableImgPrefix = false;
        if (disableUrlPrefix == null) disableUrlPrefix = false;
        if (this.prefixImg != null && disableImgPrefix != true) imgSrc = this.prefixImg + imgSrc;
        if (this.prefixUrl != null && disableUrlPrefix != true) link = this.prefixUrl + link;

        if (this.pageId != null && this.sectionId != null && this.itemNo > 0) {
            link = "javascript:GoTo(\"" + link + "\"," + isPopup + ",\"" + this.pageId + "\", \"" + this.sectionId + "\", " + this.itemNo + ");";
        } else {
            link = "javascript:GoTo(\"" + link + "\"," + isPopup + ");";
        }

        this.arrImg[this.nCount] = new Image();
        this.arrImg[this.nCount].src = imgSrc;
        this.arrLink[this.nCount] = link;
        this.arrText[this.nCount] = text;
        this.arrSeq[this.nCount] = this.nCount;
        this.nCount++;
    }
    this.start = function(act) {
        if (this.nCount == 0) return;
        this.link.innerHTML = "<img src='#' border='0'/>";
        this.image = this.link.getElementsByTagName("img")[0];
        this.started = true;
        if (this.nCount > 1 && act == 1) {
            var swap = this.nCount;            
            var indx1, indx2, temp;
            for (i = 0; i < swap; i++) {
                indx1 = Math.floor(Math.random() * this.nCount);
                indx2 = Math.floor(Math.random() * this.nCount);
                if (indx1 == indx2) {
                    continue;
                }

                temp = this.arrSeq[indx2];
                this.arrSeq[indx2] = this.arrSeq[indx1];
                this.arrSeq[indx1] = temp;
            }
        }

        this.rotate();
    }			
    this.stop = function(){
        this.started = false;
        if (this.timer != null){
            clearTimeout(this.timer); 
            this.timer = null;	
        }
    }
    this.rotate = function() {
        this.nCurrent++;
        this.nCurrent %= this.nCount;
        var indc = this.arrSeq[this.nCurrent];
        this.link.href = this.arrLink[indc];
        this.image.src = this.arrImg[indc].src;
        if (this.arrText[indc] != null) {
            this.image.alt = this.arrText[indc];
        }
        if (this.nCount > 1 && this.started) {
            clearTimeout(this.timer); this.timer = null;
            this.timer = setTimeout(this.name + ".rotate()", this.interval);
        }
    }
}


function GoTo(link, popup, pageId, sectionId, itemNo) {
    var url = "/jobseeker/rlinkz.aspx?page=" + pageId + "&section=" + sectionId + "&item=" + itemNo + "&url=" + escape(link);
    if (popup) {
        if (pageId != null && sectionId !=null) window.open(url);
        else window.open(link);
    } else {
        if (pageId != null && sectionId != null) window.location = url;
        else window.location = link;
    }
}