var rotator = '';

function setup_rotate(theid) {
	if (!theid) { theid = 'image_rotator'; }
	rotator = document.getElementById(theid);
	var images = 0;

	for (var i=0;i < rotator.childNodes.length; i++) {
		if (rotator.childNodes[i].tagName == 'DIV') {
			// in case non img tags are in it for some reason
			images++;
		}
	}
	// less one to cope with starting at 0
	images--;
//console.log(images);
	rotate(images, images);
}

function rotate(current, total) {
	if (current >= total) {
		var next = 0;
	} else {
		var next = current + 1;
	}

	//fade current show next
	var images = 0;
	for (var i=0;i < rotator.childNodes.length; i++) {
		if (rotator.childNodes[i].tagName == 'DIV') {
			if (images == current) {
				$("#" + rotator.childNodes[i].id).fadeOut(3000);
			}
			if (images == next) {
				$("#" + rotator.childNodes[i].id).fadeIn(3000);
			}
			images++;
		}
	}

	setTimeout("rotate(" + next + ", " + total + ")", 5000);
}

function single_rotate(theid) {
	rotator = document.getElementById(theid);
	for (var i=0;i < rotator.childNodes.length; i++) {
		if (rotator.childNodes[i].tagName == 'DIV') {
			$("#" + rotator.childNodes[i].id).fadeIn(3000);
		}
	}
}
