// -----------------------------------------------------------------------------
// Functions for Fruit Salad Faces Web Site
// -----------------------------------------------------------------------------




// -----------------------------------------------------------------------------
// Header & footer functions to display the FSF rainbow border
// -----------------------------------------------------------------------------

function write_header()
{
	// <!-- HEADER START -->
	// <table border="0" cellpadding="0" cellspacing="0" width="750">
	// <tr>
	// <td rowspan="2" colspan="1" width="167" height="75">
	// 	<a href="index.htm"
	// 		onmouseover="if(document.images) document.fsf_logo.src='Images/fsfborder_1x1_mouseover.gif';"
	// 		onmouseout="if(document.images) document.fsf_logo.src='Images/fsfborder_1x1.gif';">
	// 	<img name="fsf_logo" src="Images/fsfborder_1x1.gif" width="167" height="75" border="0" alt="Go to Fruit Salad Faces home page"></a></td>
	// <td rowspan="1" colspan="1" width="508" height="12">
	// 	<img src="Images/fsfborder_1x2.gif" width="508" height="12" border="0"></td>
	// <td rowspan="2" colspan="2" width="75" height="75">
	// 	<img src="Images/fsfborder_1x3.gif" width="75" height="75" border="0"></td>
	// </tr>
	// <tr>
	// <td rowspan="1" colspan="1" width="508" height="63">
	// 	<img src="Images/fsfborder_2x1.gif" width="508" height="63" border="0"></td>
	// </tr>
	// </table>
	// <table border="0" cellpadding="0" cellspacing="0" width="750">
	// <tr>
	// <td width="12" style="background-image: url(Images/fsfborder_3x1_repeat.gif); background-repeat: repeat-y;"></td>
	// <td width="726" bgcolor="#ffffff">
	// <!-- HEADER END -->


	// alert("In write_header()");
	var str= "";
	str += "<!-- HEADER START -->";
	str += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"750\">";
	str += "<tr>";
	str += "<td rowspan=\"2\" colspan=\"1\" width=\"167\" height=\"75\">";
	str += " <a href=\"index.htm\"";
	str += "  onmouseover=\"if(document.images) document.fsf_logo.src='Images/fsfborder_1x1_mouseover.gif';\"";
	str += "  onmouseout=\"if(document.images) document.fsf_logo.src='Images/fsfborder_1x1.gif';\">";
	str += " <img name=\"fsf_logo\" src=\"Images/fsfborder_1x1.gif\" width=\"167\" height=\"75\" border=\"0\" alt=\"Go to Fruit Salad Faces home page\"></a></td>";
	str += "<td rowspan=\"1\" colspan=\"1\" width=\"508\" height=\"12\">";
	str += " <img src=\"Images/fsfborder_1x2.gif\" width=\"508\" height=\"12\" border=\"0\"></td>";
	str += "<td rowspan=\"2\" colspan=\"2\" width=\"75\" height=\"75\">";
	str += " <img src=\"Images/fsfborder_1x3.gif\" width=\"75\" height=\"75\" border=\"0\"></td>";
	str += "</tr>";
	str += "<tr>";
	str += "<td rowspan=\"1\" colspan=\"1\" width=\"508\" height=\"63\">";
	str += " <img src=\"Images/fsfborder_2x1.gif\" width=\"508\" height=\"63\" border=\"0\"></td>";
	str += "</tr>";
	str += "</table>";
	str += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"750\">";
	str += "<tr>";
	str += "<td width=\"12\" style=\"background-image: url(Images/fsfborder_3x1_repeat.gif); background-repeat: repeat-y;\"></td>";
	str += "<td width=\"726\" bgcolor=\"#ffffff\">";
	str += "<!-- HEADER END -->";
	document.write(str);
}


function write_footer()
{
	// <!-- FOOTER START -->
	// </td>
	// <td width="12" style="background-image: url(Images/fsfborder_3x5_repeat.gif); background-repeat: repeat-y;"></td>
	// </tr>
	// </table>
	// <table border="0" cellpadding="0" cellspacing="0" width="750">
	// <tr>
	// <td rowspan="1" colspan="3" width="750" height="16">
	// 	<img src="Images/fsfborder_4x1.gif" width="750" height="16" border="0"></td>
	// </tr>
	//
	// <tr>
	// <td rowspan="2" colspan="1" width="75" height="59">
	// 	<img src="Images/fsfborder_5x1.gif" width="75" height="59" border="0"></td>
	//
	// <td rowspan="1" colspan="1" width="600" height="47" bgcolor="#ffffff">
	// <!-- FOOTER PAUSE -->
	//
	// <!-- #################### FOOTER AREA START #################### -->
	//
	// <div class="footertext">
	// Content, design and layout is Copyright © 2003 Fruit Salad Faces. All rights reserved.
	// Reproduction in whole or in part in any form or medium without the express written
	// permission of Fruit Salad Faces is prohibited.
	// </div>
	//
	// <!-- #################### FOOTER AREA END #################### -->
	//
	// <!-- FOOTER CONTINUE -->
	// </td>
	// <td rowspan="2" colspan="1" width="75" height="59">
	// 	<img src="Images/fsfborder_5x3.gif" width="75" height="59" border="0"></td>
	// </tr>
	// <tr>
	// <td rowspan="1" colspan="1" width="600" height="12">
	// 	<img src="Images/fsfborder_6x1.gif" width="600" height="12" border="0"></td>
	// </tr>
	// </table>
	// <!-- FOOTER END -->

	// alert("In write_footer()");
	var str= "";
	str += "<!-- FOOTER START -->";
	str += "</td>";
	str += "<td width=\"12\" style=\"background-image: url(Images/fsfborder_3x5_repeat.gif); background-repeat: repeat-y;\"></td>";
	str += "</tr>";
	str += "</table>";
	str += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"750\">";
	str += "<tr>";
	str += "<td rowspan=\"1\" colspan=\"3\" width=\"750\" height=\"16\">";
	str += " <img src=\"Images/fsfborder_4x1.gif\" width=\"750\" height=\"16\" border=\"0\"></td>";
	str += "</tr>";
	str += "";
	str += "<tr>";
	str += "<td rowspan=\"2\" colspan=\"1\" width=\"75\" height=\"59\">";
	str += " <img src=\"Images/fsfborder_5x1.gif\" width=\"75\" height=\"59\" border=\"0\"></td>";
	str += "";
	str += "<td rowspan=\"1\" colspan=\"1\" width=\"600\" height=\"47\" bgcolor=\"#ffffff\">";
	str += "<!-- FOOTER PAUSE -->";
	str += "";
	str += "<!-- #################### FOOTER AREA START #################### -->";
	str += "";
	str += "<div class=\"footertext\">";
	str += "Web design by <a href=\"http://www.gritac.com\"><img src=\"Images/gritacsmall.gif\" width=\"25\" height=\"14\" border=\"0\" align=\"absmiddle\" />Gritac</a><br>";
	str += "Content, design and layout is Copyright © 2003-2004 Fruit Salad Faces. All rights reserved. ";
	str += "Reproduction in whole or in part in any form or medium without the express written ";
	str += "permission of Fruit Salad Faces is prohibited.";
	str += "</div>";
	str += "";
	str += "<!-- #################### FOOTER AREA END #################### -->";
	str += "";
	str += "<!-- FOOTER CONTINUE -->";
	str += "</td>";
	str += "<td rowspan=\"2\" colspan=\"1\" width=\"75\" height=\"59\">";
	str += " <img src=\"Images/fsfborder_5x3.gif\" width=\"75\" height=\"59\" border=\"0\"></td>";
	str += "</tr>";
	str += "<tr>";
	str += "<td rowspan=\"1\" colspan=\"1\" width=\"600\" height=\"12\">";
	str += " <img src=\"Images/fsfborder_6x1.gif\" width=\"600\" height=\"12\" border=\"0\"></td>";
	str += "</tr>";
	str += "</table>";
	str += "<!-- FOOTER END -->";
	document.write(str);
	// calculate_filesize();
}




// -----------------------------------------------------------------------------
// Functions for the Image Cycler
// -----------------------------------------------------------------------------

function imageItem(image_location)
{
	this.image_item = new Image();
	this.image_item.src = image_location;
}

function get_ImageItemLocation(imageObj)
{
	// alert("get_ImageItemLocation("+imageObj+")");
	// index 0: The path to the image
	// index 1: Whether the image has been loaded or not (true/false)
	// index 2: The image object itself

	if (!imageObj[1]) {
		imageObj[1] = true;
		imageObj[2] = new imageItem(imageObj[0]);
	}
	return(imageObj[2].image_item.src);
}

function randNum(x, y)
{
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
}

function getNextImage()
{
	if (random_display) {
		ImageNum = randNum(0, number_of_image-1);
	}
	else {
		ImageNum = (ImageNum+1) % number_of_image;
	}
	var new_image = get_ImageItemLocation(imageArray[ImageNum]);
	return(new_image);
}

function getPrevImage()
{
	if (--ImageNum < 0) {
		ImageNum = number_of_image - 1;
	}
	var new_image = get_ImageItemLocation(imageArray[ImageNum]);
	return(new_image);
}

function prevImage(place)
{
	var new_image = getPrevImage();
	document[place].src = new_image;
}

function rotateImage(place)
{
	var new_image = getNextImage();
	document[place].src = new_image;
	var recur_call = "rotateImage('"+place+"')";
	timerID = setTimeout(recur_call, interval);
}

function doPlay()
{
	rotateImage('rImage');
}

function doPause()
{
	// alert("timerID:"+timerID);
	clearTimeout(timerID);
}

function doPrevious()
{
	// alert("timerID:"+timerID);
	prevImage('rImage');
	clearTimeout(timerID);
}

function doNext()
{
	// alert("timerID:"+timerID);
	rotateImage('rImage');
	clearTimeout(timerID);
}



// -----------------------------------------------------------------------------
// Miscellaneous functions
// -----------------------------------------------------------------------------

function calculate_filesize()
{
	// Calculates the size of the HTML document (including images)
	//

	if (!document.fileSize)
	{
		alert('This script does not work in your browser.');
		return;
	}
	var size = (document.fileSize)*1;
	var y = document.images;
	var imglength = 0;
	for (i=0;i<y.length;i++)
	{
		imglength += (y[i].fileSize)*1;
	}
	var total = size + imglength;
	var writestring = 'File size HTML: ' + size;
	writestring += '\nFile size images: ' + imglength;
	writestring += '\nTotal file size: ' + total;
	if (total > 40000) writestring += "\nFile too large!";
	alert(writestring);
}

function inspect_object()
{
	// Enter an object name and this function will display it's contents
	//

	ret = prompt ("Enter object", "document");
	obj = eval(ret);
	var temp = "";
	for (x in obj)
	temp += x + ": " + obj[x] + "\n";
	alert (temp);
}

function SwapImage( objImage, srcX, srcY )
{
	//

	newImage = new Image();
	if( objImage.src.indexOf(srcX) > -1 ) {
			newImage.src = srcY;
	}
	else {
			newImage.src = srcX;
	}
	objImage.src = newImage.src;
}

function SwapColor( obj, color )
{
	// Sets the background colour of an object (usually used on a <td> to do a MouseOver menu item)

	obj.style.cursor = "hand";
	obj.style.backgroundColor = color;
}
