var numimg  = 50;
var buttons = new Array;

myURL = window.location.href;
myURLType = myURL.substring(0,4);  /* this will tell me if i'm developing (file) or at the R&eacute;R website (http) */

function pic(baseURL, src, width, height, bgColor, background, credit, lowSrc, title, code, codeHTML, codeHTMLBase, soundBaseURL, soundSrc, soundTitle)	{	
	this.baseURL 		= baseURL; 				// site base location, as in baseURL='/rer/';
	this.src 			= src; 					// relative location from calling location
	this.width 			= width;				// image width
	this.height 		= height;				// image height
	this.lowSrc 		= lowSrc;				// relative location of a lowsrc copy of the image (thumbnail or greyscale, etc)

	this.title 			= title;				// title or description of the image
	this.credit 		= credit;				// credit or reference for original image

	this.bgColor 		= bgColor;				// background color for display window or frame
	this.background 	= background;			// relative location of a background image for display window or frame
	this.code 			= code;					// code to use when searching for related info, etc (eg rerhc1)
	this.codeHTML 		= codeHTML;				// true or false
	this.codeHTMLBase 	= codeHTMLBase;			// location within bas

	this.soundBaseURL 	= soundBaseURL;			// URL of sound files to be included
	this.soundSrc 		= soundSrc;				// name of the sound file
	this.soundSrc		= new Array;
	this.soundTitle 	= soundTitle;			// name of the sound file
	this.soundTitle		= new Array;
}

function urlButton(onSource, offSource, text, turnedOn) {  // image rollover with url on click
        this.onSource       = onSource;
        this.offSource      = offSource; 
        this.text           = text;
        this.turnedOn       = turnedOn;
}

var pics = new Array();	/* this array will hold all records */   


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function displayPicWindow(picIn) {  // picIn is a pic object (above)
	with (picIn) {
		if (src != null) {
	            nh = Math.round(height+(height*1.2)); 	if (nh==0) nh=350;
	            nw = Math.round(width+(width*.35)); 	if (nw==0) nw=325;
	     }
	    
		if (myURLType=="file") { 
			displayURL=baseURL;
		}
		else displayURL=baseURL;
		
		var windowParms="toolbar=yes,location=yes,directories=no,status=yes,"+"menubar=yes,scrollbars=yes,resizable=yes,width="+nw+",height="+nh;
		picWindow = window.open("", code, windowParms);
		
		if (picIn.src != null) {
			d=picWindow.document;
			d.writeln("<HTML><HEAD>");
			d.writeln("<TITLE>"+title+"</TITLE>");
			d.writeln("<script>");
			d.writeln("<!--");
			d.writeln("function soundWindow(soundBaseURL,soundSrc,winName,soundTitle) { ");
			d.writeln("	aWindow=window.open(soundBaseURL+soundSrc,winName+'Sound','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=250,height=250'); ");
			d.writeln("	aWindow.status=\""+soundTitle+"\";");
			d.writeln("return false;}");
			d.writeln("//-->");
			d.writeln("</script>");
			d.writeln("</HEAD><BODY BGCOLOR='white' TEXT='black'><CENTER>");
			d.writeln('<font size=+1>'+title+'</font><br><hr>');

		   if (src != null) {
				d.writeln("<IMG SRC='"+displayURL+src+"' width="+width+" height="+height+"'><BR CLEAR=ALL>");
				d.writeln("<br><center><font color='green' size=-1>artistic credit: "+credit+"</font></center><br>");
				if (codeHTML) {
					d.writeln('<br><a href="'+displayURL+codeHTMLBase+code+'.html" target="blank">For more information -- description and notes</a><br><br>');
				}
		  }
		   else if (codeHTML) {
				d.writeln('<a href="'+displayURL+codeHTMLBase+code+'.shtml" target="blank">For more information -- description and notes</a><br>');
		  }
		   
		  d.writeln("</form></center>");
		  if (soundBaseURL!=null) {
			d.writeln('<center>Sound Samples from the <a href="http://www.megacorp.u-net.com/" target="blank">ReR Megacorp Website, http://www.megacorp.u-net.com/ </a><br><br><form>');
			for (i=1;i<soundSrc.length;i++) {
				winName=code+i;
		  	 	d.writeln('<input type=button value="'+soundTitle[i]+'"onClick=\"javascript:soundWindow(\''+soundBaseURL+'\',\''+soundSrc[i]+'\',\''+winName+'\',\''+soundTitle[i]+'\')\"><br><br>');
//		  	 	d.writeln('<a href=\"javascript:window.open(\''+soundBaseURL+soundSrc[i]+'\','+code+')\">'+soundTitle[i]+'</a><br>');
		  	 }

			d.writeln("<br><br><font size='+1' color='red'>Help with Sound Files</font></center>");
			d.writeln("<p>All sounds files are mp3 files.  If you\'ve configured your browser to play mp3 files directly then clicking on a button above should open a new window with a sound controller in it.  If the window is blank then hopefully you\'ve been prompted to download the sound file.  If nothing has happened then download and install the latest <a href=\'http://www.apple.com/quicktime/\' target=\'blank\'>Apple Quicktime</a> (or the media player of your choice) and configure your browser to play mp3 files directly, or to open mp3 files with the Quicktime plugin.</p>");
		  }
		   
		   d.writeln("</body></html>");
		   d.close();
	   }
	   else {						// no image, check to see if there's a description
			if (codeHTML) {
				picWindow.location=displayURL+codeHTMLBase+code+'.shtml';		// changes the picWindow's location to the onesheet
			}
		}
	} // with picIn
}


function showpic(picIndex,thetgtFrame) {
  	parent.tgtFrame.document.writeln('<html><head></head><body bgcolor="'+pic[picIndex].bgColor+'" text="#000000" link="#CCCC33" alink="#663333" vlink="#00FF66">');
	parent.tgtFrame.document.writeln('<center><br><br>');
	if (pic[picIndex].bgColor == 'white') {
		parent.tgtFrame.document.writeln('<font color="black" size=+1>');
	}
	else {
		parent.tgtFrame.document.writeln('<font color="white" size=+1>');
	}
	parent.tgtFrame.document.writeln(pic[picIndex].title+'</font><br><br>');
	parent.tgtFrame.document.writeln('<img src="'+pic[picIndex].src+'" height='+pic[picIndex].height+' width='+pic[picIndex].width+'>');
	parent.tgtFrame.document.writeln('</center></body></html>\n');
	parent.tgtFrame.document.close();
	document.bgColor = pic[picIndex].bgColor;
}

    


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



function flip_image(buttonName) {

	with (buttons[buttonName]) {
		if (turnedOn) {
			document[buttonName].src = offSource.src;
			self.status= "";
		}
		else {
			document[buttonName].src = onSource.src;
			self.status = text;
		}
		turnedOn = !turnedOn;
		
	} 	// with (buttons[buttonName])
	
}  // function flip_image(buttonName)

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


function showMe() {
//	alert('made it '+imageWinName);

	imageRequested="http://www.squidco.com/"; // default url in case something goes wrong
	
	for (f=0;f<=imageForm.imageList.options.length;f++) {
		if (imageForm.imageList.options[f].selected) {
			imageRequested=imageForm.imageList.options[f].value;
			break;
		}
	}
		

	b=imageRequested.indexOf('|');
	imageSrc=imageRequested.substring(0,b);
	widthAndHeight=imageRequested.substring(b+1,imageRequested.length);
	b=widthAndHeight.indexOf('|');
	width=widthAndHeight.substring(0,b);
	height=widthAndHeight.substring(b+1,widthAndHeight.length);

	scaleFactor=document.imageForm.scaleFactor.options[document.imageForm.scaleFactor.selectedIndex].value;

	scaledWidth=Math.floor(width*scaleFactor);
	scaledHeight=Math.floor(height*scaleFactor);
	winWidth=scaledWidth+30;
	winHeight=scaledHeight+30;

    adate = new Date();
    bdate = Date.parse(adate);
    imageWinName = 'picWin'+bdate;

    myWindow=window.open('',imageWinName,'toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width='+winWidth+',height='+winHeight);
    
    myWindow.document.writeln('<html><head><title>'+imageSrc+'</title></head><body bgcolor="white">');
	myWindow.document.writeln("<center><img src='"+imageSrc+"' width="+scaledWidth+"heigth="+scaledHeight+"></center>");
 
    myWindow.document.writeln('</body></html>'); 
}


function makeImageWindow() {
    adate = new Date();
    bdate = Date.parse(adate);
    
    imageWinName = 'imgwin'+bdate;

	winIndex = allWindows[getSelectedWindowName()];
	if (!allWindows[getSelectedWindowName()]) {
		alert('naughty boy, you closed the window!');
		remakeWindow(getSelectedWindowName());
		winIndex = allWindows[getSelectedWindowName()];
	}


	pageURL=winIndex.location;

    myWindow=window.open('',imageWinName,'toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=400');
    
    myWindow.document.writeln('<html><head><title>'+pageURL+'</title>');
	myWindow.document.writeln('<script src="imageStuph.js"></script>');
    myWindow.document.writeln('</head><body bgcolor="white"><center>');
    myWindow.document.writeln('<br><br>'); 


	myWindow.document.writeln('Number of Frames: '+winIndex.frames.length+'<br>');
	if (winIndex.frames.length>0) {
	    for(var i = 0; i < winIndex.frames.length; i++) {
	    	myWindow.document.writeln('Frame '+i+' has '+winIndex.frames[i].document.images.length+' images'); 
		}
	}
	else {
    	myWindow.document.writeln('Window 0 has '+document.images.length+' images'); 
    }
    myWindow.document.writeln('<br><br>'); 

    myWindow.document.writeln('<form name="imageForm"><select NAME="imageList" size=12>'); 

	if (winIndex.frames.length>0) {
		numFrames=winIndex.frames.length;
	    for(var i = 0; i < winIndex.frames.length; i++) {
		    for(var j = 0; j < winIndex.frames[i].document.images.length; j++) {
		    	if (i==0) {
			    	myWindow.document.writeln('<option selected=true value="'+winIndex.frames[i].document.images[j].src+'|'+winIndex.frames[i].document.images[j].width+'|'+winIndex.frames[i].document.images[j].height+'">'+winIndex.frames[i].document.images[j].src);
			    }
			    else {
			   		myWindow.document.writeln('<option value="'+winIndex.frames[i].document.images[j].src+'|'+winIndex.frames[i].document.images[j].width+'|'+winIndex.frames[i].document.images[j].height+'">'+winIndex.frames[i].document.images[j].src);
			   	}
			}
		}
		myWindow.document.writeln('</select>');

	}
	else {
	    for(var i = 0; i < document.images.length; i++) {
	    	if (i==0) {
		    	myWindow.document.writeln('<option selected=true value="'+winIndex.document.images[i].src+'|'+winIndex.document.images[i].width+'|'+winIndex.document.images[i].height+'">'+winIndex.document.images[i].src);
		    }
		    else {
		   		myWindow.document.writeln('<option value="'+winIndex.document.images[i].src+'|'+winIndex.document.images[i].width+'|'+winIndex.document.images[i].height+'">'+winIndex.document.images[i].src);
		   	}
		}
		myWindow.document.writeln('</select>');
	}

	myWindow.document.writeln('<Br><br>enter scaling factor (1=100%) ==> <select NAME="scaleFactor" size=1><option value=".25">.25<Br>');
	myWindow.document.writeln('<option value=".50">.50<option value=".75">.75<option value="1">1.0<option value="1.50" selected="true">1.5<option value="1.75">1.75');
	myWindow.document.writeln('<option value="2.0">2.0<option value="2.50">2.5<option value="3.0">3.0<option value="3.5">3.5<option value="4.0">4.0<option value="4.5">4.5<option value="5.0">5.0</select>');
	
	myWindow.document.writeln('<Br><Br><a href="javascript:showMe()"><font size="+1">show selected image</font></a>');

    myWindow.document.writeln('</form></center></body></html>'); 
}


