//Globals 
var browserIe;
  var      media = new Array('docToRead', 'pdfToPrint', 'imageToSee', 'videoToWatch' );
    var    parts = new Array('Href', 'Hint', 'Display');
		  var whatDo = new Array('Read&nbsp;this', 'Print&nbsp;this', 'More&nbsp;to&nbsp;see', 'Watch&nbsp; this' );  
		    var display;
				var montageList = null;
			 
function showTOCInfo()
{
 
  showHere = document.getElementById("showInfoHere");
	
	whichElement = browserIe ? window.event.srcElement : window.event.target.srcElement;

	if  (whichElement.tagName.toLowerCase() == 'a') 
	 {
	 

	    showHere.innerText =  browserIe ? window.event.srcElement.title :             window.event.target.srcElement.getAttribute("title");
   
	 srcLinkUrl = browserIe ? window.event.srcElement.href :     window.event.target.srcElement.getAttribute("href");

	
	if ( montageList == null )
	{  buildMontageList();}
	
 showList = '';
	 foundLink = false;
	 for (count in montageList)
		  { 
			   montageValue =  montageList[count].getAttribute('docToReadHref');
			   montageNumeric = 0 + montageValue.length; 
				if ( srcLinkUrl.indexOf(montageValue) > -1 )
				 { 
				if ((montageNumeric +1)  > 1)
				     { 
						   //alert(montageNumeric +1);
							 showImageInfo(montageList[count]);
				      //  montageList[count].scrollIntoView(true);
				      foundLink = true;
				 break;
				     }
				  } 
			
			 }	
			if (foundLink == false) 
			  {
				 document.getElementById("fullImage").innerHTML = '<div style=\"position:relative; top:80px\"><div style=\"text-align:center; font-weight:bold\">'+whichElement.outerHTML+ '</div>' + '<br /><br />'+whichElement.title + '</div>';
				 }	 
	  }// if  (whichElement.tagName.toLowerCase() == 'a') 
 }

/*	image="true" video="false" infoText origWidth="400" origHeight="300" imageToSeeHref imageToSeeHint imageToSeeDisplay videoToWatchHref videoToWatchHint videoToWatchDisplay extraText docToReadHref docToReadHint docToReadDisplay pdfToPrintHref pdfToPrintHint pdfToPrintDisplay
*/

function displayImageToString()
{
  
  var infoHtml = this.buildTextHTML() ;
	// alert('displayImageToString');	
  return infoHtml;
 }
 
 function makeTextReady()
 {

	// alert('makeTextReady');
	
		 buildText = '<br /><h3 class=\"imageTitle\">'+this.image.title+'</h3>'
		  buildText += '<img src=\"'
			           + this.image.src
								  + '\" alt=\"'
									 + this.image.alt
									  + '\" class=\"imgBelow\" onclick=\"showFullImage(this)\">';  
				
					//	image Text			
		
			            buildText += '<table>';
									
						buildText +=  '<tr><td>'
		                    +'<div class=\"infoBoxAreas\">'
										      + '<table>';		
										 												
	for (count in media)
     {  
		      if (this.image.getAttribute(media[count] + parts[0]) != null)
							 if (this.image.getAttribute(media[count] + parts[0]) != '') 
								{								  
									  buildText += '<tr><td width="50" align=\"right\">';
								 //   position = media[count].indexOf('To') ;
								      buildText += '<span class=\"mediaType\">'
                                  + whatDo[count]
																     //+ media[count].substr(0, position)
																		+':</span>&nbsp;';
																		
											 buildText += '</td><td>';					
											
											  buildText += ' <a class=\"infoBoxLink\" target=\"'
											             + this.image.getAttribute(media[count] + parts[1])
																    + '\" href=\"'+ this.image.getAttribute(media[count] + parts[0])
                                     + '\" title=\"'+ this.image.getAttribute(media[count] + parts[1]) ;
														buildText += '\">' +  this.image.getAttribute(media[count] + parts[2]); 
															buildText +=	'</a></td></tr>'    ; 							 
								 }							 
		  }
																	
					
			  buildText += '</table>';
				
			  buildText += '</div></td>';
			  buildText += '</tr>';
				buildText += '<tr>';
									 buildText +=  '<td>'
									            + '<div class=\"infoBoxAreas\">'
															 + this.image.getAttribute('infoText')
															  + '<br />'
																 + this.image.getAttribute('extraText')
																  + '</div></td></tr>'	;	
			buildText +=	'</table>';
		return buildText;	
 }
  
function displayImage(thisImage)
{
    this.image = thisImage;
    this.toString = displayImageToString;
		this.buildTextHTML = makeTextReady;
 }



function showImageInfo(what)
{// onmouseover in top menu images

	display = new displayImage(what);	
 document.getElementById("fullImage").innerHTML = display;
 } 
 
function showFullImage(what)
{
  newDoc = window.open('about:blank');
	newDoc.document.title = display.image.title;  
	
	newDoc.document.body.innerHTML = '<center>'+display +'</center>';  
	newDoc.focus();
	//newStyleSheet = newDoc.document.styleSheets[0];
	thisStyleSheet = document.styleSheets[0];
	newDoc.document.createStyleSheet(thisStyleSheet.href);
 anotherSheet = newDoc.document.createStyleSheet('');
	anotherSheet.addRule('.infoBoxAreas', 'margin-top:15px; height:100; width: 550px;' ,0)
	anotherSheet.addRule('.imageTitle', 'font-family: times new roman, roman, swiss, serif; font-size:20pt' ,0);
  anotherSheet.addRule('BODY','font-family: verdana, arial, helvetica, sans-serif; font-size: 10pt;',0);
	anotherSheet.addRule('A','color:blue; font-size: 9pt; ',0);
	anotherSheet.addRule('.mediaType', 'display:inline-block; margin-bottom: 1px',0);
	anotherSheet.addRule('IMG', 'width:460; height:345; cursor: vertical-text; ',0);
	//	newDoc.document.images[0].detachEvent('onclick',parent.showFullImage);
	//  attachEvent('onclick',parent.doNothing);
	newDoc.document.images[0].style.setAttribute('cursor','default',0);
newDoc.document.images[0].setAttribute('onclick','',0);
 }

 
 function doNothing()
 {
 //alert('v');
 }
		
function createXMLHttpRequest() 
{
 if (typeof XMLHttpRequest != "undefined") 
    {
	    return new XMLHttpRequest();
     } else if (typeof ActiveXObject != "undefined") 
		    {
	       return new ActiveXObject("Microsoft.XMLHTTP");
        } 
			 else {
	            throw new Error("XMLHttpRequest not supported");
             }
 }

function getContents(fileName, htmlFor) 
{
 
 var request = createXMLHttpRequest();
 request.open("GET", fileName, true);
 
 request.onreadystatechange = function() 
   {
   	if (request.readyState == 4) 
		    {
         //alert('>'+request.responseText.substr(0,6)+'<');
         
				 htmlFor.innerHTML = request.responseText
					
			      
	      }// if (request.readyState == 4)
     }// close function()
		 
 request.send(null);
}

function buildMontageList()
{ 
			    montageList = new Array();
					
			  montageArea = document.getElementById("pictureBracket");
	  			imgCollection = montageArea.children;
				  
			  for (i=0; i<imgCollection.length; i++) 
          {
				    thisIMG = imgCollection.item(i);
					   if (thisIMG.tagName.toLowerCase() == 'img')
					    {
							 montageList.push(thisIMG);
							 thisIMG.setAttribute( 'longDesc', thisIMG.href + '.txt' );
							 } 					 
			     }
 }


function init()
 {
  
  if (document.location.href.toLowerCase().indexOf('henry3') != -1)	
      {
			document.getElementById('baseHref').href = 'http://henry3/web_mirror/paulanorman_info/';
			alert('You Are not on the Web but On:  ' +document.getElementById('baseHref').href);
			 }
			 
	 getContents("index-support/build Info from images.html", document.getElementById("pictureBracket"));	

 
 browserIe = (document.all) ? true : false;
 

 
  }

