// ----------------------------------------------------------------
// Webvertiser main banner-object is defined here in JavaScript.
// To use this on published pages, set up with reference
// to the page-specific files. 
// For instance the homepage contains a reference to
// definition_0.js in this directory...
// 2003(c). BrainCrew, Oz.

// ----------------------------------------------------------------
function webvertiser_setup(img_array, url_array){
	var i_img = img_array.length
	var i_url = url_array.length
	
	if(i_img != i_url){
		//Err checksum:
		// amount of array-data doesn't match!
		Alert ("Webvertisement Error: image amount should be equal to url amount..")
		  
	}else{
		//Add to this object an images and urls array:
		for(var i=0; i<i_img;++i) this.images[i]=img_array[i]
		for(var j=0; j<i_url;++j) this.urls[j]=url_array[j]
	}
}

function webvertiser_writepage(doc){
	// setup HTML for webvertisment:
	// -----------------------------
	// setup Anchor-tag for webvertisment:
	name = this.name	
	//doc.write("<A HREF='javascript:"+ name +".click()'")
	// doc.write(" target='_blank'")
	//doc.write(">")		
		// setup IMG-tag for webvertisment:
	doc.write("<IMG name='"+ this.name +"'" )
	doc.write(" SRC='" + this.images[this.current] + "'" )
	doc.write(" width=" + this.width )
	doc.write(" height=" + this.height )
	doc.write(" alt='" + this.alt_text +"'")
	doc.write(" border=" + this.border )
	doc.write(" hspace='" + this.hspace +"' vspace='" + this.vspace +"'>")
		// ending Anchor-tag:
	//doc.write("</A>")
	// -----------------------------
}

function webvertiser_clicked(){
	current = this.current
	// development only:
	//alert("url to open:"+this.urls[current])
	// activation code: 
	// self.location.href = this.urls[current]
}

function webvertiser_cycle(){
	i=0

	if(document.images) {

		current = this.current
		current++

		if (current == (this.amount)) {
			current = 0		
		}
		this.current = current
		//show banner:
		image_amount = document.images.length
		for(var i=0; i<image_amount;++i){ 
			if(document.images[i].name == this.name){
				document.images[i].src = this.images[current]
			}
		}
		
		//setting time-out next cycle 
		name = this.name
		i_time = this.cycletime *1000
		setTimeout(name +".shownext()", i_time)
	}
}

function webvertiser(str_image_name, i_quantity){

	this.name = str_image_name // Identifier for banner images
	this.current = 0 // current webvertisement (0 = default, first one)

	this.amount = i_quantity // amount of banners
	this.images = new Array(i_quantity) // array of locations for banner images
	this.urls = new Array(i_quantity) // array of url-addresses for clicked banners

	this.set = webvertiser_setup // image-array and url-array setup
	
	this.height = 120 // Height of image in pixels (120 = default)
	this.width = 240 // Width of image in pixels (240 = default)
		
	this.border = 0 // in pixels (0 = default, no border)
	this.cycletime = 5 // duration of banner in seconds 
	this.alt_text = "" // Alternative text for <IMG> HTML-tag
	
	this.writepage = webvertiser_writepage // generates html for viewing
	this.shownext =  webvertiser_cycle // swap banner images
	this.click = webvertiser_clicked // open banner url
	this.vspace = 0 // in pixels
	this.hspace = 0 // in pixels
}