	
	// bind initialization handler to window load
	window.onload = init;
	window.onunload = finish;

	// initialization handler
	function init() {
		initAd();
	}

	// finish handler
	function finish() {
		finishAd();
	}

	
	var adPeriod = 10; // seconds - period between animation steps
	var adRunTime = 0; // seconds - stop the animation after this time (0 = never)
	var adSpacing = 136; // pixels - ads are offset vertically by this distance
	var ad = Array(); // ad links are kept here
	var adStep = 0; // current step in the animation (wraps)
	var adEnable = true; // ad animation is enabled

	
	// initialize ad animation
	function initAd() {
		// check browser support...
		if ( !document.getElementById )  return;
		// check page has the needed parts...
		if ( !document.getElementById('adArea') )  return;
		if ( !document.getElementById('adArea').getElementsByTagName('a') )  return;
		// ok...
		// put the ad links into an array
		ad = document.getElementById('adArea').getElementsByTagName('a');
		// take control of css positioning
		for (i=0; i<ad.length; i++) {
			ad[i].style.position = 'absolute';
			ad[i].style.top = i * adSpacing + 'px';
		}
		// get previous adStep from cookie, if available...
		var posA = document.cookie.indexOf("adStep=")
		if (posA != -1) {
			var startA = posA + 7;
			var endA = document.cookie.indexOf(";", startA);
			if (endA == -1) endA = document.cookie.length;
			adStep = unescape(document.cookie.substring(startA,endA));
		}
		// stop the animation at a given time in the future...
		if ( adRunTime > 0 ) {
			window.setTimeout( 'adEnable=false;' , adRunTime*1000);
		}
		// begin animation
		adShift();
	}

	// finish ad animation
	function finishAd() {
		// store the current ad step, so we can pick up were we left off on the next page
		document.cookie = 'adStep=' + adStep;
	}

	// shift the ads up one step
	function adShift () {
		if (!adEnable) return; // stop animating
		adStep++;
		adStep = adStep % ad.length;
		for (i=0; i<ad.length; i++) {
			if ( i >= adStep ) {
				ad[i].style.top = (i-adStep) * adSpacing + 'px';
			} else {
				ad[i].style.top = (i - adStep + ad.length) * adSpacing + 'px';
			}
		}
		window.setTimeout( 'adShift(adStep);' , adPeriod*1000);
	}
