function loadImageRollOver(img)
{
	if (!img) return;
	if (img.out) return;
	img.out = new Image();
	img.over = new Image();
	if ((img.src.indexOf("_out.gif") >= 0)  ||  (img.src.indexOf("_over.jpg") >= 0))
	{
		img.out.src = img.src;
		img.over.src = img.src.replace(/_out.gif$/, "_over.gif").replace(/_out.jpg$/, "_over.jpg");
	}
	else if ((img.src.indexOf("_over.gif") >= 0) || (img.src.indexOf("_over.jpg") >= 0))
	{
		img.over.src = img.src;
		img.out.src = img.src.replace(/_over.gif$/, "_out.gif").replace(/_over.jpg$/, "_out.jpg");
	}
	else
	{
		img.out.src = img.src;
		img.over.src = img.src;
	}
}
function imageRollOver(img)
{
	if (!img) return;
	if (!img.out) loadImageRollOver(img);
	img.src = img.over.src;
}
function imageRollOut(img)
{
	if (!img) return;
	if (!img.out) loadImageRollOver(img);
	img.src = img.out.src;
}
var content = null;
var content_next = 0;
var content_prev = 0;
var content_max = 0;
function clearContent()
{
	var divs = document.getElementsByTagName('DIV');
	for(var counter = 0; counter < divs.length; ++counter)
	{
		var div = divs[counter];
		if ((div.id.indexOf('content_text_') > -1) || (div.id.indexOf('content_image_') > -1))
		{
			div.style.display = 'none';
		}
	}
}
function setContent(current_num, max_num)
{
	content = document.getElementById('content_text_' + current_num);
	var image = document.getElementById('content_image_' + current_num);
	if (!content || !image) return;
	clearContent();
	content.style.display = 'block';
	content.style.left = '0px';
	content.style.top = '0px';
	content.maxBottom = 0;
	var clipper = document.getElementById('content_clipper');
	if (clipper)
	{
		content.maxBottom = clipper.offsetHeight;
	}
	if (window.contentInterval) window.clearInterval(window.contentInterval);
	window.contentInterval = null;
	image.style.display = 'block';
	content_next = current_num + 1;
	content_prev = current_num - 1;
	content_max = max_num;
	var nav_button = document.getElementById('page_next_button');
	if (nav_button)
	{
		if ((content_next < (max_num + 1)) && (max_num > 0))
		{
			nav_button.style.display = 'block';
		}
		else
		{
			imageRollOut(document.getElementById('page_next_image'));
			nav_button.style.display = 'none';
		}
	}
	nav_button = document.getElementById('page_prev_button');
	if (nav_button)
	{
		if ((content_prev > 0) && (max_num > 0))
		{
			nav_button.style.display = 'block';
		}
		else
		{
			imageRollOut(document.getElementById('page_prev_image'));
			nav_button.style.display = 'none';
		}
	}
}
function nextButton()
{
	setContent(content_next, content_max);
}
function previousButton()
{
	setContent(content_prev, content_max);
}
function setScrollImage(id, dir)
{
	var image = document.getElementById('scroll_' + id + '_image');
	if (!image) return;
	image.src = 'images/scroll_' + id + '_' + dir + '.gif';
}
function getScrollImage(id)
{
	var image = document.getElementById('scroll_' + id + '_image');
	if (!image) return('');
	return(image.src);
}
function scrollUpOver()
{
	setScrollImage('up', 'over');
}
function scrollUpOut()
{
	setScrollImage('up', 'out');
}
function scrollUpDown()
{
	if (!content);
	setScrollImage('up', 'push');
	if (!window.contentInterval)
	{
		window.contentInterval = window.setInterval(scrollingUp, 10);
	}
}
function scrollUpUp()
{
	setScrollImage('up', 'over');
	if (window.contentInterval) window.clearInterval(window.contentInterval);
	window.contentInterval = null;
}
function scrollingUp()
{
	content.style.top = (parseInt(content.style.top) + 3) + 'px';
	if (parseInt(content.style.top) >= 0)
	{
		content.style.top = '0px';
		window.clearInterval(window.contentInterval);
		window.contentInterval = null;
	}
}
function scrollDownOver()
{
	setScrollImage('down', 'over');
}
function scrollDownOut()
{
	setScrollImage('down', 'out');
}
function scrollDownDown()
{
	if (!content) return;
	setScrollImage('down', 'push');
	if ((content.offsetHeight > content.maxBottom) && (!window.contentInterval))
	{
		window.contentInterval = window.setInterval(scrollingDown, 10);
	}
}
function scrollDownUp(control)
{
	setScrollImage('down', 'over');
	if (window.contentInterval) window.clearInterval(window.contentInterval);
	window.contentInterval = null;
}
function scrollingDown()
{
	content.style.top = (parseInt(content.style.top) - 3) + 'px';
	if ((parseInt(content.style.top) + content.offsetHeight) <= content.maxBottom)
	{
		content.style.bottom = content.maxBottom;

		content.style.top =  (-(content.offsetHeight - content.maxBottom)) + 'px';
		window.clearInterval(window.contentInterval);
		window.contentInterval = null;
	}
}
function displayMenu(menu_id, closer_id, image)
{
	var menu = document.getElementById(menu_id);
	var closer = document.getElementById(closer_id);
	if (!menu) return;
	if (!closer) return;
	if (!image) return;
	var top = 0;
	var left = 0;
	var parent = image;
	while (parent != null)
	{
		top += parent.offsetTop;
		left += parent.offsetLeft;
		parent = parent.offsetParent;
	}
	menu.style.top = top + 11;
	closer.style.top = top + 11;
	menu.style.left = left;
	closer.style.left = left - 10;
        closer.style.width = parseInt(menu.style.width) + 20;
	menu.style.display = 'block';
	closer.style.display = 'block';
        closer.style.height = parseInt(menu.offsetHeight) + 20;
}
function hideMenu(menu_id, closer_id)
{
	var menu = document.getElementById(menu_id);
        var closer = document.getElementById(closer_id);
	if (!menu) return;
        if (!closer) return;
	menu.style.display = 'none';
	closer.style.display = 'none';
}
function loadNewsBreakout(source, target_id)
{
	if (!source) return;
	var target_node = document.getElementById(target_id);
	var source_node = source.document.getElementById(target_id);
	if (target_node && source_node)
	{
		if (!document.importNode)
		{
			target_node.innerHTML = source_node.innerHTML;
		}
		else
		{
			source_node = source_node.cloneNode(true);
			document.importNode(source_node, true);
			target_node.appendChild(source_node);
		}
	}
}
function initWindow()
{
	var image_buffer = new Array();
	for(var counter = 0; counter < document.images.length; ++counter)
	{
		if ((document.images[counter].src.indexOf("_out.") >= 0) ||
			(document.images[counter].src.indexOf("_over.") >= 0))
		{
			image_buffer.push(document.images[counter]);
		}
	}
	for(var counter = 0; counter < image_buffer.length; ++counter)
	{
		if (!image_buffer[counter].out || !image_buffer[counter].over)
		{
			loadImageRollOver(image_buffer[counter]);
		}
	}
}
var current_completed = 1;
var current_testimonial = 1;
var current_regex = new RegExp(/\?(.*)$/);
function nextCompleted()
{
	++current_completed;
	if (current_completed > 15) {
		current_completed = 1;
	}
	updateCompleted();
}
function nextTestimonial()
{
	++current_testimonial;
	if (current_testimonial > 13) {
		current_testimonial = 1;
	}
	updateTestimonial();
}
function prevCompleted()
{
	--current_completed;
	if (current_completed < 1) {
		current_completed = 15;
	}
	updateCompleted();
}
function prevTestimonial()
{
	--current_testimonial;
	if (current_testimonial < 1) {

	}
	updateTestimonial();
}
function initCompleted()
{
	var current_query = current_regex.exec(location);

	if (current_query)
	{
		if (parseInt(current_query[1])) current_completed = parseInt(current_query[1]);
	}
	updateCompleted();
}
function initTestimonial()
{
	var current_query = current_regex.exec(location);

	if (current_query)
	{
		if (parseInt(current_query[1])) current_testimonial = parseInt(current_query[1]);
	}
	updateTestimonial();
}
function updateCompleted()
{
	image1 = document.getElementById('completed_image_one');
	image2 = document.getElementById('completed_image_two');
	image3 = document.getElementById('completed_image_three');

	if (!image1 || !image2 || !image3) return;

	image1_number = current_completed;
	image2_number = image1_number + 1;
	if (image2_number == 16) image2_number = 1;
	if (image2_number == 17) image2_number = 2;
	image3_number = image2_number + 1;
	if (image3_number == 16) image3_number = 1;
	if (image3_number == 17) image3_number = 2;
	
	image1.src = 'images/completed' + image1_number + '_small.jpg';
	image2.src = 'images/completed' + image2_number + '_small.jpg';
	image3.src = 'images/completed' + image3_number + '_small.jpg';
}
function updateTestimonial()
{
	title = document.getElementById('content_title_' + current_testimonial);

	if (!title) return;

	content.style.top = (0 - parseInt(title.offsetTop)) + 'px';
	if ((parseInt(content.style.top) + content.offsetHeight) <= content.maxBottom)
	{
		content.style.bottom = content.maxBottom;

		content.style.top =  (-(content.offsetHeight - content.maxBottom)) + 'px';
		window.clearInterval(window.contentInterval);
		window.contentInterval = null;
	}
}
