/*----------------------------------------------------
||Banner Ad Rotater v2.01                            ||
||Script by:  Anarchos                               ||
||URL: http://anarchos.xs.mw/                        ||
||E-mail: anarchos3@hotmail.com                      ||
||ICQ: 12007422                                      ||
||                                                   ||
||E-mail or ICQ me if you have any questions or need ||
||help setting up your banner ad rotator. Check out  ||
||my webpage every once in a while for updates to    ||
||this script.                                       ||
-----------------------------------------------------*/

function Banner(objName,layerName, refreshTime, random, align){
	//Methods
		this.write = b_write //output banner
		this.getCode = b_getCode //return output code
		this.Ad = b_Ad //add an ad to the ads array
		this.newAd = b_newAd //display the next ad
		this.randomAd = b_randomAd //make a random ad
		this.nextAd = b_nextAd //queue the next ad
	//Properties
		if (!objName) this.objName = "myBanner"; else this.objName = objName
		if (!layerName) this.layerName = "bannerAd"; else this.layerName = layerName //init output layer name
		if (!refreshTime) this.refreshTime = 5000; else this.refreshTime = refreshTime*1000 //init refresh time
		if (!random) this.random = 1; else this.random = random //cycle randomly
		if (!align) this.align = "none"; else this.align = align //alignment of the sponsor text
		this.ads = new Array() //init ads array
		this.currentAd = 0 //init current ad
		this.mySize = 0 //init size
		this.myCode = '' //init myCode	
}

function b_Ad(src, href, target, width, height, sponsor, mouseover, alt) {
    var tempImage = new Image()
	tempImage.src = src
	this.mySize++;
	this.ads[this.mySize] = new Object()
	this.ads[this.mySize].src = src
	if (!target) this.ads[this.mySize].target = "_self"; else this.ads[this.mySize].target = target
	this.ads[this.mySize].href = href
	this.ads[this.mySize].width = width
	this.ads[this.mySize].height = height
	this.ads[this.mySize].sponsor = sponsor
	this.ads[this.mySize].mouseover = mouseover
	this.ads[this.mySize].altText = alt
}

function b_randomAd(){
	var n
	do { n = Math.floor(Math.random() * (this.mySize) + 1) } 
	while(n == this.currentAd)
	this.currentAd = n
	this.myCode = this.getCode(n)
	this.nextAd()
}

function b_getCode(adNumber){
    if (adNumber > this.mySize) { 
	   	alert("Error: adNumber("+adNumber+") out of bounds.\nMax: "+this.size) 
		} 
	else {
		var tempCode = ""
		if (this.align == "center" || this.align == "right") tempCode += '<table cellpadding=0 cellspacing=0 border=0><tr><td>'
		tempCode += '<a href="'+ this.ads[adNumber].href +'"'
		tempCode += ' onMouseOver="status=\''+ this.ads[adNumber].mouseover +'\'; return true"'
		tempCode += ' target="'+ this.ads[adNumber].target + '"'
		tempCode += ' onMouseOut="status=\'\';return true"> \n'
		tempCode += '<img src="' + this.ads[adNumber].src + '" width=' + this.ads[adNumber].width
		tempCode += ' name="'+this.objName+'IMG"'
		tempCode += '\n height=' + this.ads[adNumber].height + ' Alt="'+this.ads[adNumber].altText+'" border=0 >'
		if (this.ads[adNumber].sponsor != null){
	    	if (this.align == "center" || this.align == "right"){
			   tempCode += '</a>'
			   tempCode += '</td></tr><tr><td align="'+this.align+'">'
			   tempCode += '<a href="'+ this.ads[adNumber].href +'"'
			   tempCode += ' onMouseOver="status=\''+ this.ads[adNumber].mouseover +'\'; return true"'
			   tempCode += ' target="'+ this.ads[adNumber].target + '"'
			   tempCode += ' onMouseOut="status=\'\';return true"> \n'
			   }
			else tempCode += '<br>'
			tempCode += 'Sponsor: <b>' + this.ads[adNumber].sponsor + '</b>' 
		}
		tempCode += '</a>'
		if (this.align == "center" || this.align == "right") tempCode += '</td></tr></table>'
		return tempCode
		}
}

function b_newAd(){
    if (!this.random){	
		this.currentAd++;
		if (this.currentAd > this.mySize)
		   this.currentAd = 1;
    }
	else {
	     this.randomAd();
		 }
	this.write(this.getCode(this.currentAd));
}

function b_nextAd(){
		 setTimeout(this.objName+'.newAd()',this.refreshTime)
}

function b_write(text){
	
	if (document.layers) {
		temp = "document."+this.layerName+".document.write(text)"
		eval(temp)
		eval("document."+this.layerName+".document.close()")
		
		}
	else
		if (document.all){
			document.all[this.layerName].innerHTML = text
			eval("document."+this.objName+"IMG.src = this.ads[this.currentAd].src")
			}
	//}
	
}


