// Copyright 2009 Innovative Illusions - Paul Rudyk
// the script can be modified but the copyright notice should be left unchanged.

var bannerArr = new Array

// EDIT THESE ITEMS
// set time between banner change (1000 ms = 1 second)
var speed = 5000

// banner ad information (image, URL)
bannerArr[0]=new item("banner01.gif","http://www.kayakforacure.ca")
bannerArr[1]=new item("banner02.gif","http://www.kayakutopia.com")
bannerArr[2]=new item("banner03.gif","http://www.kokatat.com")
bannerArr[3]=new item("banner04.gif","http://www.bajakayakadventures.com")
bannerArr[4]=new item("banner06.gif","http://www.bufferzoneresort.com")
bannerArr[5]=new item("banner08.gif","http://www.coastmountainexpeditions.com")
bannerArr[6]=new item("banner09.gif","http://www.advancedelements.com")
bannerArr[7]=new item("banner10.gif","http://www.cdkayak.com")
bannerArr[8]=new item("banner11.gif","http://www.ucluelet.travel/en/index.html")
bannerArr[9]=new item("banner12.gif","http://www.valleyseakayaks.com")
bannerArr[10]=new item("banner05.gif","http://www.peregrinekayaks.com")
bannerArr[11]=new item("banner07.gif","http://www.borealdesign.com")
bannerArr[12]=new item("banner13.gif","http://www.aldercreek.com")
bannerArr[13]=new item("banner14.gif","http://www.tahtsadivecharters.com")


// path to server directory containing banner images
var imgPath="/Images/RotatingAds/"

// NO EDITING REQUIRED BELOW THIS LINE

var qty=bannerArr.length
var pos
var imgArray=new Array()

for (pos=0;pos<qty;pos++){
imgArray[pos]=new Image()
imgArray[pos].src=imgPath+bannerArr[pos].name
}

function item(name,link){
	this.name=name
	this.link=link
}

function showBanners(){
	pos=Math.round(Math.random()*qty-1)
	if(pos<0) {pos=0}
	document.write('<table>')
	document.write('<tr><td><a ID=ad name=ad href='+bannerArr[pos].link+' onClick="openNewWindow(this.href);return false;"><img src='+imgArray[pos].src+' name=img ID=img border=0></a></td></tr>')
	document.write('</table>')
	pause = setInterval("ready()",1000)
}

function ready(){
var start = true
	for (pos=0;pos<qty;pos++){
		if (imgArray[pos].complete == false){
		start = false
		}
	}

	if (start == true){
		window.clearInterval(pause)
		interval = setInterval("show()",speed)			
	}
}

var lastNum=qty-1
var numArray=new Array()
for (pos=0;pos<qty;pos++) { numArray[pos] = pos }

function show(){
	var dispNum
	var tempNum
	dispNum=Math.round(Math.random()*(qty-2))

	if (document.all){
		eval('document.img').style.filter="blendTrans(duration=3)";
		eval('document.img').filters.blendTrans.Apply();
		eval('document.img').filters.blendTrans.Play();
	}

	eval('document.img').src = imgArray[lastNum].src
	eval("document.getElementById('ad')").href=bannerArr[lastNum].link
	tempNum=numArray[dispNum] 
	numArray[dispNum]=lastNum
	lastNum=tempNum
}

function openNewWindow(href){
	var newWindow
	newWindow = window.open(href,"","toolbar=yes,directories=yes,menubar=yes,resizable=yes,location=yes,status=yes,scrollbars=yes,copyhistory=yes")
} 
