// the script was written in part by Scott Horne
// at http://web-professor.net 
// the original version was found some where on an ASP forum someplace but I can't remember where.
// Changes I have made include the click to resize 
// 
// make sure you set maxWidth to be the max number of pixels you want an image to be wide
// use
// <body onload="resizeImages();" >
// to activate the script

function resizeImages() 
{ 
          if (document.images.length > 0)          //Has images, validate sizes 
          { 

// edit this variable to set the max width
// of images
		var maxWidth = 300;
               	var imgHeight; 
               	var imgWidth; 
               	for (var loop = 0; loop < document.images.length; loop++) 
               { 
			if( maxWidth < document.images[loop].width && document.images[loop].className != 'noresize' )
			{ 
                         imgWidth = document.images[loop].width; 
                         imgHeight = document.images[loop].height; 

				image = new Image();
                              	image = document.images[loop]; 

				newImage = image.cloneNode( true )	;

				// store the origninal height and width 
                              	newImage.origHeight = image.height;
                            	newImage.origWidth = image.width


                             	newImage.width = maxWidth ; 
				
                              //Proportionalize Height 
				
                              	imgHeight = imgHeight / (imgWidth/ maxWidth ); 
                              	newImage.height = imgHeight; 
				
				newImage.style.cursor = 'pointer';


				if( image.outerHTML )
				{ 
                	              	newImage.onclick = "var altHeight; var altWidth;	altHeight = this.height ; altWidth = this.width; this.width = this.origWidth; 	this.height = this.origHeight; this.origWidth = altWidth; this.origHeight = altHeight; 	"; 
				} else {
                	              	newImage.onclick = function () { 
						var altHeight;
						var altWidth;
						
						// store the alt height and width in temp vars
						altHeight = this.height ;
						altWidth = this.width;

	
						// make it the alternate deminsions
						this.width = this.origWidth; 
						this.height = this.origHeight; 

						// store 
						this.origWidth = altWidth; 
						this.origHeight = altHeight; 
					}; 
				}


				// get parent node
				// insert this in a table witha message to click to resize
				if( parentNode = image.parentNode )
				{
					textMessage = document.createTextNode('Click image to resize');

					elem = document.createElement("td");
					elem.setAttribute( "align", "center");
					elem.style.backgroundColor = 'black';
					elem.style.color = 'white';
					elem.style.fontWeight = '900';
					elem.style.fontSize = '8pt';

					elem.appendChild( textMessage );
					elem.appendChild( document.createElement("br"));
					elem.appendChild( newImage );
						
					
					tableRow = document.createElement("tr");
					tableRow.appendChild(elem);
					
					TableElem = document.createElement("table");
					TableElem.setAttribute( "border", "1");
					TableElem.appendChild( tableRow );

					frag = document.createElement("div");
					frag.appendChild( TableElem );

					if( image.outerHTML )
					{
						image.outerHTML = frag.innerHTML;
					} else {
						parentNode.replaceChild( TableElem, image );
					}
				}
			}

               } 
          } 
     } 


