home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 80 / IOPROG_80.ISO / bannerad3.js < prev    next >
Encoding:
JavaScript  |  2004-03-29  |  3.4 KB  |  94 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='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="468" height="60">';
  61.             tempCode+='<param name=movie value="'+this.ads[this.currentAd].src+'">';
  62.             tempCode+='<param name=quality value=high>';
  63.             tempCode+='<embed src="'+this.ads[this.currentAd].src+'" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">';
  64.             tempCode += '</embed></object>';
  65.             //tempCode = '<a href="javascript:'+this.objName+'.link();"';
  66.             //tempCode += ' onMouseOver="' + this.objName + '.showStatus(); return true"';
  67.             //tempCode += ' onMouseOut="status=\'\';return true">';
  68.             //tempCode += '<img src="' + this.ads[this.currentAd].src + '" width="' + this.width;
  69.             //tempCode += '" name="' + this.objName + 'Img" height="' + this.height + '" ';
  70.             //if (this.altText) tempCode += 'alt="'+this.altText + '" ';
  71.             //tempCode += 'border="0" /></a>';
  72.             document.write(tempCode);
  73.             this.nextAd();
  74.         } else document.write("Error: two banners must be defined for the script to work.");
  75.     }
  76.  
  77.     this.newAd = function(){
  78.         if (!this.random){    
  79.             this.currentAd++;
  80.             if (this.currentAd >= this.mySize)
  81.                this.currentAd = 0;
  82.         }
  83.         else {
  84.             this.randomAd();
  85.         }
  86.         this.nextAd();
  87.     }
  88.  
  89.     this.nextAd = function(){
  90.         document.embeds[this.objName+'Img'].src = this.ads[this.currentAd].src;
  91.         setTimeout(this.objName+'.newAd()',10000)
  92.     }
  93. }
  94. Banner.count = 0;