/* Original rollover effect on different image script-
By JavaScript Kit (http://javascriptkit.com)
Over 200+ free scripts here!
Major revisions and additions by David Peters
to support text overlay and insertion with styles
*/

// photoInfo object constructor

function photoInfo (elmntId,details1,details2,details3) {
	this.elmntId = elmntId;
	this.details1 = details1;
	this.details2 = details2;
	this.details3 = details3;
	return true;
}

// photoInfoList object constructor

function photoInfoList (elmntId,details1,details2,details3,details4,details5,details6,details7,details8,details9) {
	this.elmntId = elmntId;			// parent element container
	this.details1 = details1;		// child node 0 id
	this.details2 = details2;		// child node 0 contents
	this.details3 = details3;		// child node 0 style
	this.details4 = details4;		// child node 1 id
	this.details5 = details5;		// child node 1 contents
	this.details6 = details6;		// child node 1 style
	this.details7 = details7;		// child node 2 id
	this.details8 = details8;		// child node 2 contents
	this.details9 = details9;		// child node 2 style
	return true;
}

// elementStyleInfo object constructor

function elementStyleInfo (elmntId,properties) {
	this.elmntId = elmntId;
	this.properties = properties;
	return true;
}


function changeImage(towhat,url){
	if (document.images)
	{
		document.images.targetimage.src=towhat.src
	}
}

var lastElmntIdDisplayed = '';

function changeImageAndText(towhatimage,towhattext,url){
	if (document.images)	// this is unrelated to the other text stuff herein
	{
		if (lastElmntIdDisplayed != '')
		{
			dinfo = document.getElementById(lastElmntIdDisplayed);
			// turn off the visibility of the last element we showed
			if (dinfo) 
			{
				dinfo.style.display = "none";
				lastElmntIdDisplayed = '';
				// toss all the child nodes of the last element displayed
				// will build new childnodes (if any)
				//if (dinfo.hasChildNodes()) {alert("Old view had text childnodes!");}
				while(dinfo.hasChildNodes()) {dinfo.removeChild(dinfo.firstChild);}
			}
		}
		// change the image to the new one associated with the mouseover thumbnail
		// may want to decouple this from the text overlay code as they don't have to be in same if statement
		// unless we want textoverlay to go away before we see photo change
		document.images.targetimage.src=towhatimage.src;
		
		// if there is an element in the towhattext array entry, make it visible
		if (towhattext.elmntId != "")
		{
			//alert(towhattext.elmntId + towhattext.details1 + towhattext.elmntId + towhattext.details2);
			dinfo = document.getElementById(towhattext.elmntId);
			//alert(dinfo);
			if (dinfo)
			{
				dinfo.style.display = "block";
				lastElmntIdDisplayed = towhattext.elmntId;
			}
		}
		else
		{
			// turn off visibility of the element last turned on
		}
		
		if (towhattext.elmntId != "")
		{
			d1 = document.getElementById(towhattext.elmntId);
			if (d1)
			{
				if (d1.hasChildNodes()) 	// clear all child nodes and then render new elements
				{
					//alert("This has childnodes!");
					while(dinfo.hasChildNodes()) {dinfo.removeChild(dinfo.firstChild);}
					// clear old text
//					d1.childNodes[0].data = '';
			
					// change the style attibutes for new text
//					d1.style.cssText = '';
//					d1.style.cssText = towhattext.details3;
			
					// and insert new text
//					d1.childNodes[0].data = towhattext.details2;
					
					// create a new div and the text in it
//					var newElementTag;
//					var newTextNode;
//   				newElementTag=document.createElement('div');
//					newElementTag.id = towhattext.details4;
//   				newTextNode=document.createTextNode(towhattext.details5);

					// add the text node as a child (leaf) of the new element
//  				newElementTag.appendChild(newTextNode);

					// add the new link to the parent node
//   				d1.appendChild(newElementTag);
				}
//				else
				{ 
					//alert ("This element has no child nodes. About to create them!");
					// create first new div and the text in it if it exists
					if (towhattext.details1 != '')
					{
						var newElementTag;
						var newTextNode;
   					newElementTag=document.createElement('div');
						newElementTag.id = towhattext.details1;
						newElementTag.style.cssText = towhattext.details3;
   					newTextNode=document.createTextNode(towhattext.details2);
						// add the text node as a child (leaf) of the new element
  					newElementTag.appendChild(newTextNode);
						// add the new link to the parent node
   					d1.appendChild(newElementTag);
					}
					
					// add the second text element if it exists
					if (towhattext.details4 != '')
					{
	 					newElementTag=document.createElement('div');
						newElementTag.id = towhattext.details4;
						newElementTag.style.cssText = towhattext.details6;
   					newTextNode=document.createTextNode(towhattext.details5);
						// add the text node as a child (leaf) of the new element
  					newElementTag.appendChild(newTextNode);
						// add the new link to the parent node
   					d1.appendChild(newElementTag);
					}
					
					// add the third text element if it exists
					if (towhattext.details7 != '')
					{
	 					newElementTag=document.createElement('div');
						newElementTag.id = towhattext.details7;
						newElementTag.style.cssText = towhattext.details9;
   					newTextNode=document.createTextNode(towhattext.details8);
						// add the text node as a child (leaf) of the new element
  					newElementTag.appendChild(newTextNode);
						// add the new link to the parent node
   					d1.appendChild(newElementTag);
					}
				}
			}	// end if d1
		}	// endif we have text to add to an element
		
	}	// endif document has images
	return true;
}

function warp(){
	window.location=gotolink
}
function newpage(newurl) {
	parent.location=newurl
}

var myImages=new Array()
var myThumbImages=new Array()

function preloadimages(images, thumbs){
	for ( i=0; i < images.length; i++ )
	{
		myImages[i]=new Image()
		myImages[i].src= images[i]
	}
	for ( i=0; i < thumbs.length; i++ )
	{
		myThumbImages[i]=new Image()
		myThumbImages[i].src= thumbs[i]
	}
	return true;
}