/**********************/
/* Javascript Add-ons */
/**********************/

// Function to allow one JavaScript file to be included by another.

function includeJavaScript(jsFile) {
	var endString = jsFile + '"</scr' + 'ipt>';
	document.write('<script type="text/javascript" src="'+ endString); 
}


/***************/
/* Date & Time */
/***************/

function printYear() {

	var DEBUG = false;
	var year = new Date().getFullYear();

	if (DEBUG) alert ('Called printYear(' + year +')');
	document.write (year);

} // end: printYear()


/*****************/
/* Image-related */ 
/*****************/

// changeImage: Changes the main image when thumbnail is rolled over.

function changeImage (imageDir, mainImage, newImage, index) {

	var DEBUG = false;
	var imagePath = imageDir + newImage;

	// Get the index of the current thumbnail image
	var currentIndex = document.images[mainImage].title;

	if (DEBUG) {
		var info = "imagePath="+ imagePath +", item=item"+ index +
			", currentIndex="+ currentIndex;
		alert (info);
		var color = document.images['item' + currentIndex].style.color;
		alert ("style.color="+ color);
	}

	// Use title property to store the new main image index.
	document.images[mainImage].title = index;

	// Change the old image thumbnail to black, new to red.
	document.images['item' + currentIndex].style.color = "black";
	document.images['item' + index].style.color = "red";

	// Switch main image to one selected by thumbnail rollover.
	document.images[mainImage].src = imagePath;

} // end: changeImage -->

// openNewWindow: Opens a new window to view large image.
function openNewWindow (
	imageFile, videoFile, name, width, height, back, forward) {

	// Debugging.
	var DEBUG = false;

	// Default in upper left corner.
	var xposition = 0;
	var yposition = 0;

	if (DEBUG) {
	   //if (imageFile.length != 0) alert ('imageFile=' + imageFile);
	   //if (videoFile.length != 0) alert ('videoFile=' + videoFile);
	   alert ('name=' + name + ', width=' + width + ', height=' + height);
	   alert ('back=' + back + ', forward=' + forward);
	}

	// If possible, make the window appear in the middle, etc.
	if (parseInt(navigator.appVersion) >= 4) {
	   xposition = (screen.width - width) / 2;
	   yposition = (screen.height - height) / 2;
	}

	// Put together the args to open a window, and open it.
	args = "width="+ width +",height="+ height +",location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0,hotkeys=0,screenx="+ xposition +",screeny="+ yposition +",left="+ xposition +",top="+ yposition;
	largeWindow = window.open(name, name, args);

	// Put together a page for the new window plus stylesheets.

	page = '<html>\n<head>\n<title>\n'+ name +'\n</title>\n';
	page += addStyleSheets(false);
	page += '</head><body>\n<div class="center">';
	if (imageFile.length != 0)
	    page += '<img src="'+ imageFile +'" alt="'+ name +'">';
    else if (videoFile.length != 0) {
	    page += '<object width="425" height="350">';
	    page += '<param name="movie" value="http://www.youtube.com/v/';
	    page += videoFile + '"></param>\n';
	    page += '<embed src="http://www.youtube.com/v/' + videoFile;
	    page += '" type="application/x-shockwave-flash" width="425" height="350"></embed>\n</object>\n';
    } else {
	    alert ('No Image or Video File!');
	    return;
    }

	// Finish off the image or video "paragraph".
	//
	// 28 Jul 2011 robv - Removed tables, using CSS positioning.

	// Add "previous", "forward" and "close window" links.
	if (back.length > 1)
		page += '<span class="small left"><a href="javascript: void(); onClick="">&lt;&lt; Previous</a></span>\n';

	// Add a button to close the window.
	page += '<div class="left">';
	page += '<img height="5" src="images/spacer.gif" alt="" /><br />\n';
	page += '<a href="javascript: window.close();">';
	page += '<img name="close_window" src="/icons/CloseWindowButton.gif" alt="Close Window" /></a></div>\n';

	if (forward.length > 2)
	   page += '<div class="small right"><a href="javascript: void(); onClick=""> Next &gt;&gt;</a></div\n';

	// Finish up the window and open it.
	page += '</div> <!-- end: center -->\n\n</body>\n</html>\n';
	largeWindow.document.write (page);
	return true;
} // end: openNewWindow


/************************/
/* General Web-Oriented */
/************************/

//
// redirectPage: Redirects current page to new one.
//

function redirectPage (newPage) {
	var DEBUG = true;
	var site = document.location.href;

	if (DEBUG)
		alert ('site=' + site + ', namePage=' + newPage);
	window.location.href = newPage;
	document.location.href = newPage;
} // end: redirectPage()

//
// addStyleSheets: Adds standard stylesheets to new windows.
//

function addStyleSheets(writeFlag) {

	var page = '\n<link rel="stylesheet" href="/styles/main.css" type="text/css" />\n';
	page += '<link rel="stylesheet" href="/styles/classes.css" type="text/css" />\n';
	//page += '<link rel="stylesheet" href="/styles/ids.css" type="text/css" />\n\n';
	if (writeFlag)
		document.write (page);
	return (page);
} // end addStyleSheets()

//
// updateMoreLinks - displays more or less text in span.
//

function updateMoreLinks (id) {

	var DEBUG = false;
	var element = document.getElementById(id);
	var moreElement = document.getElementById(id + '-more');
	var lessElement = document.getElementById(id + '-less');
	var show = element.style.display;

	if (DEBUG) {
		var more = moreElement.style.display;
		var less = lessElement.style.display;
		alert ('id=' + id + ', show=' + show);
		alert ('more=' + more + ', less=' + less);
	}

	if (show == 'none') {
		element.style.display = '';
		moreElement.style.display = 'none';
		lessElement.style.display = 'inline';
	} else {
		element.style.display = 'none';
		moreElement.style.display = 'inline';
		lessElement.style.display = 'none';
	}

} // end updateMoreLinks()

