home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 81 / IOPROG_81.ISO / bannerad3.js < prev    next >
Encoding:
JavaScript  |  2003-05-02  |  2.8 KB  |  89 lines

  1. /****
  2. * Banner Ad Rotater v3.02
  3. * Anarchos > anarchos3@hotmail.com
  4. * http://anarchos.xs.mw/bannerad.phtml
  5. **/
  6.  
  7. function Banner(refreshTime, width, height, altText, start, random){
  8.     this.objName = "bannerAd" + (Banner.count++);
  9.     eval(this.objName + "=this");
  10.     if (!refreshTime) this.refreshTime = 2000; else this.refreshTime = refreshTime*1000;
  11.     if (!width) this.width = 460; else this.width = width;
  12.     if (!height) this.height = 68; else this.height = height;
  13.     if (random == null) this.random = 1; else this.random = random;
  14.     this.altText = altText;
  15.     this.ads = [];
  16.     if (start) this.currentAd = start-1; else start = null;
  17.     this.mySize = 0;
  18.  
  19.     this.Ad = function(src, href, target, mouseover) {
  20.         var tempImage = new Image();
  21.         tempImage.src = src;
  22.         this.ads[this.mySize] = new Object();
  23.         var ad = this.ads[this.mySize];
  24.         ad.src = src;
  25.         if (typeof(target) == "undefined" || target == null) ad.target = "_blank"; else ad.target = target;
  26.         ad.href = href;
  27.         ad.mouseover = mouseover;
  28.         this.mySize++;
  29.     }
  30.  
  31.     this.link = function(){
  32.         var    ad = this.ads[this.currentAd];
  33.         if (ad.target == "_self"){
  34.             location.href = ad.href;
  35.         }
  36.         else if (ad.target == "_blank" || ad.target == "_new"){
  37.             open(ad.href,this.objName + "Win");
  38.         }
  39.         else top.frames[ad.target].location.href = ad.href;
  40.     }
  41.  
  42.     this.showStatus = function(){
  43.         var ad = this.ads[this.currentAd];
  44.         if (ad.mouseover) status = ad.mouseover;
  45.         else status = ad.href;
  46.     }
  47.  
  48.     this.randomAd = function(){
  49.         var n;
  50.         do { n = Math.floor(Math.random() * (this.mySize)); } 
  51.         while(n == this.currentAd);
  52.         this.currentAd = n;
  53.     }
  54.  
  55.     this.output = function(){
  56.         var tempCode = "";
  57.         if (this.mySize > 1){
  58.             if (this.currentAd == null) this.randomAd();
  59.             if (this.currentAd >= this.mySize) this.currentAd = this.mySize - 1;
  60.             tempCode = '<a href="javascript:'+this.objName+'.link();"';
  61.             tempCode += ' onMouseOver="' + this.objName + '.showStatus(); return true"';
  62.             tempCode += ' onMouseOut="status=\'\';return true">';
  63.             tempCode += '<img src="' + this.ads[this.currentAd].src + '" width="' + this.width;
  64.             tempCode += '" name="' + this.objName + 'Img" height="' + this.height + '" ';
  65.             if (this.altText) tempCode += 'alt="'+this.altText + '" ';
  66.             tempCode += 'border="0" /></a>';
  67.             document.write(tempCode);
  68.             this.nextAd();
  69.         } else document.write("Error: two banners must be defined for the script to work.");
  70.     }
  71.  
  72.     this.newAd = function(){
  73.         if (!this.random){    
  74.             this.currentAd++;
  75.             if (this.currentAd >= this.mySize)
  76.                this.currentAd = 0;
  77.         }
  78.         else {
  79.             this.randomAd();
  80.         }
  81.         this.nextAd();
  82.     }
  83.  
  84.     this.nextAd = function(){
  85.         document.images[this.objName+ 'Img'].src = this.ads[this.currentAd].src;
  86.         setTimeout(this.objName+'.newAd()',10000)
  87.     }
  88. }
  89. Banner.count = 0;