var onLoadAgencyAdvert = function() {
	agencyAdvertLoad();
}

registerOnLoad(onLoadAgencyAdvert);

function agencyAdvertLoad()
{
	if (!isdefined("agentLogos")) {
		return;
	}
	// Start up routine
	for (var n = 0; n < 8; n++) {
		var box = new getObj('agentad_' + n);
		if (box.ready && agentLogos.length) {
			var id = Math.floor(Math.random() * agentLogos.length);
			var opacity = Math.floor(Math.random() * 101);
			var direction = Math.floor(Math.random() * 2);
			if (agentLogos[id][0]) {
				box.obj.innerHTML = '<span></span><a href="index.php?page=results&s=directorysearch&type=agency&id=' +
									agentLogos[id][0] +
									'" title="View all Properties By ' +
									agentLogos[id][1] +
									'">' +
									'<img src="' + agentLogos[id][2] + '" alt="' + agentLogos[id][1] + '" />' +
									'</a>';
			}
			else {
				box.obj.innerHTML = '<span></span><img src="' + agentLogos[id][2] + '" alt="' + agentLogos[id][1] + '" />';
			}
			box.style.opacity = opacity / 100;
			if (navigator.appName.indexOf("Netscape") != -1 && parseInt(navigator.appVersion) >= 5) {
				box.style.MozOpacity = opacity / 100;
			}
			else if (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion) >= 4) {
				box.obj.filters.alpha.opacity = opacity;
			}
			window.setTimeout("agencyAdvertUpdate(" + n + "," + opacity + "," + direction + ")",100);
		}
	}
}

function agencyAdvertUpdate(n, opacity, direction)
{
	var box = new getObj('agentad_' + n);
	if (box.ready) {	
		if (direction) {
			opacity ++;
		}
		else {
			opacity --;
		}
		if (opacity >= 100) {
			opacity = 100;
			direction = 0;
		}
		if (opacity <= 0) {
			opacity = 0;
			direction = 1;
			var id = Math.floor(Math.random() * agentLogos.length);
			if (agentLogos[id][0]) {
				box.obj.innerHTML = '<span></span><a href="index.php?page=results&s=directorysearch&type=agency&id=' +
									agentLogos[id][0] +
									'" title="View all Properties By ' +
									agentLogos[id][1] +
									'">' +
									'<img src="' + agentLogos[id][2] + '" alt="' + agentLogos[id][1] + '" />' +
									'</a>';
			}
			else {
				box.obj.innerHTML = '<span></span><img src="' + agentLogos[id][2] + '" alt="' + agentLogos[id][1] + '" />';
			}
		}
		box.style.opacity = opacity / 100;
		if (navigator.appName.indexOf("Netscape") != -1 && parseInt(navigator.appVersion) >= 5) {
			box.style.MozOpacity = opacity / 100;
		}
		else if (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion) >= 4) {
			box.obj.filters.alpha.opacity = opacity;
		}
		window.setTimeout("agencyAdvertUpdate(" + n + "," + opacity + "," + direction + ")",100);
	}
}