// 0 - Box in			12 - Random dissolve
// 1 - Box out			13 - Split vertical in
// 2 - Circle in		14 - Split vertical out
// 3 - Circle out		15 - Split horizontal in
// 4 - Wipe up			16 - Split horizontal out
// 5 - Wipe down		17 - Strips left down
// 6 - Wipe right		18 - Strips left up
// 7 - Wipe left		19 - Strips right down
// 8 - Vertical blinds		20 - Strips right up
// 9 - Horizontal blinds	21 - Random bars horizontal
// 10 - Checkerboard across	22 - Random bars vertical
// 11 - Checkerboard down	23 - Random
var BBBlock = null;
var BBImage = null;
var BBIndex = 0;
var BBContainer = null;
var BBTimeout = 7000;
var BBEffect = 2;
var BBHref;
var BBSrc;
var BBAlt;
var BBTransition;

function Billboard(href,src,alt,trans,width,height,animate) {
	if (BBBlock) {
		return;
	}
	BBHref = href;
	BBSrc = src;
	BBAlt = alt;
	BBTransition = trans;
	// For browsers that don't support filters
	var cycle = Math.floor(Math.random() * href.length);
	// Nested DIVs
	BBIndex = cycle;
	var nextImage = (BBIndex + 1) % src.length;
	document.writeln("<div id=\"container\" style=\"width:" + width +"px;height:"+ height +"px;\">");
	for (i = 0; i < src.length; i++) {
		// Placeholder
		document.write("<div id=\"Billboard" + i + "\" style=\"display:none\">");
		if (i == nextImage) {
			// Prefetch first image
			document.write(BillboardPicker(i));
		}
		document.write("</div>");
	}
	document.writeln("</div>");
	// Pull images out
	BBBlock = new Array(src.length);
	BBImage = new Array(src.length);
	for (i = 0; i < src.length; i++) {
		BBBlock[i] = document.getElementById("Billboard" + i);
		if (i == nextImage) {
			BBImage[i] = document.getElementById("BBImage" + i);
		} else {
			BBImage[i] = null;
		}
	}
	BBContainer = document.getElementById("container");
	BillboardEffects();
}

function BillboardEffects() {
	var nextImage = (BBIndex + 1) % BBImage.length;
	if (readIEVer() >= 4.0 && BBEffect > 0) {
		if (BBEffect == 1) {
			BBContainer.style.filter = "blendTrans(duration=0.6)";
			BBContainer.filters(0).apply();
 			BillboardSelect( nextImage );
			BBContainer.filters(0).play();
		} else {
			BBContainer.style.filter = "blendTrans(duration=1.5) revealTrans(duration=1.0,transition=" + trn[BBIndex] + ")";
			BBContainer.filters(0).apply();
			BBContainer.filters(1).apply();
 			BillboardSelect(nextImage);
			BBContainer.filters(0).play();
			BBContainer.filters(1).play();
		}
	} else {
		BillboardSelect(nextImage);
	}
	setTimeout("BillboardPrep()", BBTimeout - 1500);
	setTimeout("BillboardSwap()", BBTimeout);
}

function BillboardSelect(nextImage) {
	BBBlock[BBIndex].style.display = "none";
	BBIndex = nextImage;
	BBBlock[BBIndex].style.display = "block";
}		

function BillboardPrep() {
	// Prefetch next image
	var nextImage = (BBIndex + 1) % BBImage.length;
	if (!BBImage[nextImage]) {
		BBBlock[nextImage].innerHTML = BillboardPicker(nextImage);
		BBImage[nextImage] = document.getElementById("BBImage" + nextImage);
	}
}

function BillboardSwap() {
	if (BBImage[BBIndex].complete) {
		BillboardEffects();
	} else {
		setTimeout("BillboardSwap()", 3000);
	}
}

function BillboardPicker(cycle) {
	var divHtml;
	if (BBHref[cycle] != null) {
		divHtml = "<A href=\"" + BBHref[cycle] + "\"><IMG src=\"" + BBSrc[cycle] + "\" alt=\"" + BBAlt[cycle] + "\" BORDER=\"0\" ID=\"BBImage" + cycle + "\"></a>";
	} else {
		divHtml = "<IMG src=\"" + BBSrc[cycle] + "\" ID=\"BBImage" + cycle + "\">";
	}
	return divHtml;
}

function readIEVer() {
	var agent = navigator.userAgent;
	var offset = agent.indexOf("MSIE");
	if (offset < 0) {
		return 0;
	}
	return parseFloat(agent.substring(offset + 5,agent.indexOf(";",offset)));
}

function addBookMark() {
	if (window.external) {
		window.external.AddFavorite( document.location.href,document.title );
	} else {
		alert("Sorry, your browser doesn't support bookmarking this page...\n\nPlease try pressing Control + D instead");
	}
}
