//***********************************************
// Author        : Andrew Will - modified by Heidi Barry
// Modified      : 1/2/2004
// Functionailty : (1) Opening external picture
//                     windows
//		   (2) Write thumbnail window
//***********************************************


// calls writeVarThumb for pics 500x333 pix

function writeThumbLand(
			/* String */ myPath,
			/* String */ bgColor,
			/* String */ myImg,
			/* String */ imgTitle
 ) {

	writeVarThumb(500,333,150,100,myPath,bgColor,myImg,imgTitle);
}


// calls writeVarThumb for pics 333x500 pix

function writeThumbPort(
			/* String */ myPath,
			/* String */ bgColor,
			/* String */ myImg,
			/* String */ imgTitle
 ) {

	writeVarThumb(333,500,150,100,myPath,bgColor,myImg,imgTitle);
}


function writeVarThumb( 	/* int */    myWidth,
				/* int */    myHeight,
				/* int */    thumbWidth,
				/* int */    thumbHeight,
				/* String */ myPath,
				/* String */ bgColor,
				/* String */ myImg,
				/* String */ imgTitle ) {

	document.writeln("<span class=\"thumb\"><a href=\"javascript:openPicWin('', " + (parseInt(myWidth) + 80) + ", " + (parseInt(myHeight)+120) + ", '" + myPath + myImg + ".jpg', '" + imgTitle + "', '" + bgColor + "')\"><img alt=\"Click to Enlarge\" border=\"0\" width=\"" + thumbWidth + "\" height=\"" + thumbHeight + "\" src=\"" + myPath + "t" + myImg + ".jpg\"></a></span>");

}

// same as openBigPic but allows for bgcolor and caption

function openPicWin( /* String */ windowName,
                     /* int */    windowWidth,
                     /* int */    windowHeight,
                     /* String */ pathToPicture, 
                     /* String */ caption,
                     /* String */ bgColor ) {

	var winLeft = (screen.width - windowWidth) / 2;
	var winTop  = (screen.height - windowHeight) / 2 - 50;

	if (winLeft < 0) {
		winLeft = 0;
	}
	if (winTop < 0) {
		winTop = 0;
	}

	popUpWindow = window.open('','popUp'+parseInt(Math.random()*100),'toolbar=0,location=0,scrollbars=0,resizable=1,width='+ windowWidth +',height=' + windowHeight + ',top=' + winTop + ',left=' + winLeft);
	
	popUpWindow.document.writeln("<html><head><link rel=stylesheet type=\"text/css\" href=\"/revive/_css/revive.css\" >");
	popUpWindow.document.writeln("<body style=\"background-color:" + bgColor + "\">");

	popUpWindow.document.writeln("<center><br><div class=\"pic\" style=\"width: " + (windowWidth-80) + "; height: " + (windowHeight-120) + ";\"><img src=\"" + pathToPicture + "\"></div></center>");

	popUpWindow.document.writeln("<div class=\"caption\"> " + caption + "</div>");

	
	popUpWindow.document.writeln("</body>");
	popUpWindow.document.writeln("</html>");	
	
}


///////////////////////////////////////////////////////////////////////////////
//
// Picture Stuff
//

function openBigPic( /* String */ windowName,
                     /* int */    photoNum,
                     /* String */ key          ) {

	var windowWidth  = 10;
	var windowHeight = 10;

	var winLeft = (screen.width - windowWidth) / 2;
	var winTop  = (screen.height - windowHeight) / 2 - 50;

	if (winLeft < 0) {
		winLeft = 0;
	}
	if (winTop < 0) {
		winTop = 0;
	}

	popUpWindow = window.open("/revive/_util/display.jsp?key=" + key + "&num=" + photoNum,
														"popUp" + parseInt(Math.random()*100),
														"status=1,toolbar=0,location=0,scrollbars=0,resizable=1,width=" + windowWidth + ",height=" + windowHeight + ",top=" + winTop + ",left=" + winLeft);
}


///////////////////////////////////////////////////////////////////////////////
//
// Window Operations
//

var MAX_WINDOW_WIDTH  = 1024;
var MAX_WINDOW_HEIGHT =  750;


function resizeAndRecenter( /* int */     widthUnit,
														/* int */     heightUnit,
														/* boolean */ usePercent ) {
	if (usePercent) {
		_resizeAndRecenterPercent(widthUnit, heightUnit);
	}
	else {
		_resizeAndRecenter(widthUnit, heightUnit);
	}
}

/* private */
function _resizeAndRecenter( /* int */ newWidth,
														 /* int */ newHeight ) {

	/*
	if (screen.width > maxWidth) {
		var p = maxWidth / screen.width;

		newWidth  = maxWidth;
		newHeight = newHeight * p;
	}
	*/
	
	if (newWidth > MAX_WINDOW_WIDTH) {
		newWidth = MAX_WINDOW_WIDTH;
	}
	if (newHeight > MAX_WINDOW_HEIGHT) {
		newHeight = MAX_WINDOW_HEIGHT;
	}

	var winLeft = (screen.width - newWidth) / 2;
	var winTop  = (screen.height - newHeight) / 2 - (newHeight * .05);

	if (winLeft < 0) {
		winLeft = 0;
	}
	if (winTop < 0) {
		winTop = 0;
	}

	top.window.moveTo(winLeft, winTop);
	top.window.resizeTo(newWidth, newHeight);
}

/* private */
function _resizeAndRecenterPercent( /* int */ widthPercent,
																		/* int */ heightPercent ) {
	if (widthPercent >= 1) {
		widthPercent = widthPercent / 100;
	}
	if (heightPercent >= 1) {
		heightPercent = heightPercent / 100;
	}

	var newWidth  = widthPercent * screen.availWidth;
	var newHeight = heightPercent * screen.availHeight;

	_resizeAndRecenter(newWidth, newHeight, MAX_WINDOW_WIDTH);
}

// Opens window to specified percent of window space
function openWindowPercent( /* String */     url,
					        				  /* int,double */ percent,
					        					/* String */     parms  ) {

	if (percent > 1) {
		percent = percent/100;
	}

	// sample parms
	// "toolbar=0,location=0,scrollbars=0,resizable=1"

	var winLeft = (screen.width - percent*width) / 2;
	var winTop  = (screen.height - percent*height) / 2 - 50;

	if (winLeft < 0) {
		winLeft = 0;
	}
	if (winTop < 0) {
		winTop = 0;
	}

	popUpWindow = window.open( url,
							   "title" + parseInt(Math.random()*100),
							   parms + "," + "width="+ width +",height=" + height + ",top=" + winTop + ",left=" + winLeft );
}


