﻿
function PageAd(cpAD,cpADlink,imgId,AdIndexPrefix,timeFunctionName) {

    this.cpAD = cpAD;
    this.cpADlink = cpADlink;
    this.imgId = imgId;
    this.adNum = 0;
    this.coll = 0;
    this.AdIndexPrefix = AdIndexPrefix;
    this.timeFunctionName = timeFunctionName;
    var theTimer;
    
    this.jump2url = function() {
        jumpUrl=this.cpADlink[this.adNum - 1]; 
        jumpTarget='_blank'; 
        if (jumpUrl != '')
        { 
	        window.open(jumpUrl,jumpTarget); 
	    }
    }    
    
    this.ChangeViewIndex = function(n)
    {
        this.SetViewIndexColor(this.adNum,1);
        this.adNum = n;
        
        window.clearInterval(this.theTimer);
        this.SetViewADPid();
    }
    
    this.SetViewIndexColor = function(ind,bl)
    {
        var ct = document.getElementById(this.AdIndexPrefix + ind);
      
        if (ct == null)
        {
            return false;
        }
        if (bl == 1)
        {
        ct.style.backgroundColor = "#000000";
        ct.style.color = "#ffffff";
        }else
        {
        ct.style.backgroundColor = "#ffffff";
        ct.style.color = "#000000";
        }
    }
    
    this.nextAd = function(){ 
        this.SetViewIndexColor(this.adNum,1);
        this.adNum++
        this.SetViewADPid();
    } 

    this.SetViewADPid = function()
    {
        if(this.adNum>this.cpAD.length)
            this.adNum=1; 
        this.SetViewIndexColor(this.adNum,0);

        this.setTransition(); 
        
        imgCtrl = document.getElementById(this.imgId);
        
        if (imgCtrl != null)
        {
            imgCtrl.src=this.cpAD[this.adNum - 1]; 
        }
        this.playTransition(); 
        this.theTimer=setTimeout(this.timeFunctionName, 4000); 
    }
    
    this.setTransition = function(){ 
        if (document.all){ 
            imgCtrl = document.getElementById(this.imgId);
        
            if (imgCtrl != null)
            {
                imgCtrl.filters.revealTrans.Transition=23; 
                imgCtrl.filters.revealTrans.apply(); 
            }
        } 
    } 
    
    this.playTransition = function(){ 
    if (document.all) 
        imgCtrl = document.getElementById(this.imgId);
        
        if (imgCtrl != null)
        {
            imgCtrl.filters.revealTrans.play() 
        }
    } 


    this.loadimage = function()
    {
        var preloadedimages = new Array();
        for(i=1;i<this.cpAD.length;i++){
            preloadedimages[i] = new Image();
            preloadedimages[i].src = this.cpAD[i];
        }
    }
    
}
