var imageIndex = 0 // allows image scrolling

// just pass the id of the div to replace the div id='contents'
function show(id) {
	var divElement = document.getElementById(id);
	
	var contentsElement = document.getElementById('contents');
	
	contentsElement.innerHTML = divElement.innerHTML;
}

// div id="currentImage" is where the images are shown
// div id="imageN" is the div (display=none) to replace 'currentImage'
//   -- all of these must be id='imageN' name='image'  
function showImage() {
	var divElement = document.getElementById('image'+imageIndex);

	var imageElement = document.getElementById('currentImage');

	imageElement.innerHTML = divElement.innerHTML;
}
function countImages() {
	var length = 0;
	var imageList = document.getElementsByName("image");

	if( imageList.length == 0 ) {
		length = document.getElementById("numImages").value;
	} else {
		length = imageList.length;
	}

	return length;
}
function showPrevImage() {
	if( imageIndex == 0 ) {
		imageIndex = countImages() - 1;
	} else {
		imageIndex--;
	}
	showImage();
}
function showNextImage() {
	if( imageIndex == countImages() - 1 ) {
		imageIndex = 0;
	} else {
		imageIndex++;
	}
	showImage();
}
function markAsNewUntil(selector, expiration) {
	var now = new Date();
	if( now < new Date(expiration) ) {
		$(selector).children("a").attr("title", "New Items Inside!");
		$(selector).append('<span class="new" title="New Items Inside!">*</span>');
		//$(selector).text("New! - " + $(selector).text());
		$("#navigation_key").show();
	}
}
function setActiveTab(tab_index) {
	$(".tabs span").each(function(index) {
		if( tab_index == index ) {
			$(this).fadeTo(1, 1);
			//$(this).css("border-bottom", "solid 1px transparent");
		} else {
			$(this).fadeTo(0.64, 0.64);
		}
	});
	
	$(".contents div").each(function(index) {
		if( tab_index == index ) {
			$(this).show();
		} else {
			$(this).hide();
		}
	});
}

