
//	var sDomain = "http://www.eskimo.com/~ambler/Dev/" ;
	var sDomain = "http://www.eskimo.com/~ambler/" ;
//	var sPgApp = sDomain + "AMDevDispPg.php" ;
	var sPgApp = sDomain + "AMDispPg.php" ;
//	var sVuApp = sDomain + "AMDevDispPic.php" ;
	var sVuApp = sDomain + "AMDispPic.php" ;
//	var sPicApp = sDomain + "AMDevLoadPic.php" ;
	var sPicApp = sDomain + "AMLoadPic.php" ;

// vars are set in the script section of the html returned by the php function
	var fImgWidth ;
	var fAdjustedImgWidth ;
	var fImgHeight ;
	var fAdjustedImgHeight ;

	var sPicMenu ;

	var sOrigCmdHTML = " <A class=topmenu HREF=\"javascript:OriginalImgSize()\" " ;
		sOrigCmdHTML += "onmouseover=\"window.status='original image size'; return true\"  " ;
		sOrigCmdHTML +=  "onmouseout=\"window.status=''\"> " ;
		sOrigCmdHTML +=  "Original size </a> | \n " ;

	var sToFitCmdHTML = " <A class=topmenu HREF=\"javascript:SizeImgToFit()\" "
		sToFitCmdHTML +=  "onmouseover=\"window.status='size image to fit'; return true\"  "
		sToFitCmdHTML += "onmouseout=\"window.status=''\"> "
		sToFitCmdHTML += "Size to fit </a> | \n " ;

	var sImgBlock = "<IMG id='dispimg' class='main' > \n" ;


//-----------------------------------------------------------------------------------------

	function DispPg( sMenuCmd, sTopic, sTemplate )
	{
		document.theForm.browser.value = navigator.appName ;
		document.theForm.menuItem.value = sMenuCmd ;
		document.theForm.topic.value = sTopic ;
		document.theForm.template.value = sTemplate ;
		document.theForm.target = '' ;
		document.theForm.action = sPgApp ;
		document.theForm.submit() ;

	}

//*-----------------------------------------------------------------------------------------
// creates httprequest object

    function MakeRequest()
    {
        var httpRequest;

        if (window.XMLHttpRequest) // Mozilla, Safari, ...
        {
            httpRequest = new XMLHttpRequest() ;
            if (httpRequest.overrideMimeType)
            {
                httpRequest.overrideMimeType( 'text/xml' ) ;
            }
        }
        else if ( window.ActiveXObject ) // IE
        {
            try
            {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }
			catch (e)
			{
				try
				{
					httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert( "unable to make ActiveXObject httpRequest!" ) ;
				}
			}
		}

        if ( !httpRequest )
        {
            alert('in MakeRequest; Giving up :( Cannot create an XMLHTTP instance');
            return null ;
        }

        return httpRequest ;

    }

//-----------------------------------------------------------------------------------------
// get img default height

	function GetImgHeight( disparea )
	{
		var fHeight ;

		if ( window.innerHeight )  // browser uses DOM w/ innerHeight element
		{
			fHeight = window.innerHeight - disparea.offsetTop ;
//alert( "GetImgHeight; innerHeight: " + window.innerHeight ) ;
		}
		else if ( document.documentElement.clientHeight > 0 )	//  IE strict
		{
			fHeight = document.documentElement.clientHeight - disparea.offsetTop ;
//alert( "GetImgHeight; documentElement.clientHeight: " + document.documentElement.clientHeight ) ;
		}
		else
		{
			fHeight = document.body.clientHeight - disparea.offsetTop ;
//alert( "GetImgHeight; body.clientHeight: " + document.body.clientHeight ) ;
		}

		return ( ( fHeight < 0 ) ? 0 : ( fHeight - ( fHeight * .1 ) ) ) ;
	}

//-----------------------------------------------------------------------------------------
// get img default width

	function GetImgWidth( disparea )
	{
		var fWidth ;

		if ( window.innerWidth )  // browser uses DOM w/ innerWidth element
		{
			fWidth = window.innerWidth - disparea.offsetLeft  ;
//alert( "GetImgWidth; innerWidth: " + window.innerWidth ) ;
		}
		else if ( document.documentElement.clientWidth > 0 )	//  IE strict
		{
			fWidth = document.documentElement.clientWidth - disparea.offsetLeft  ;
//alert( "GetImgWidth; documentElement.clientWidth: " + document.documentElement.clientWidth ) ;
		}
		else
		{
			fWidth = document.body.clientWidth - disparea.offsetLeft ;
//alert( "GetImgWidth; body.clientWidth: " + document.body.clientWidth ) ;
		}

		return ( ( fWidth < 0 ) ? 0 : ( fWidth - ( fWidth * .1 ) ) ) ;
	}

//-----------------------------------------------------------------------------------------
// sets up call to xmlhttprequest to get the img info

	function GetPic( iImgId, sDispAreaId )
	{
//alert( "in GetPic; ") ;

		var httpRequest = MakeRequest() ;
		if ( httpRequest == null )	// unable to generate request object
		{
//alert( "in GetPic; MakeRequest failed") ;
			return false ;
		}

		// set the image size as a proportion of the total display area
		var disparea = document.getElementById( sDispAreaId ) ;

		// blank the image
		var dispImg = document.getElementById( 'dispimg' ) ;
		SetBorders( dispImg.getAttribute( "value" ), "black" ) ;  // unhighlight left bar img icon
		var imgdisparea = document.getElementById( 'imgdisparea' ) ;
		imgdisparea.innerHTML = "" ;
//		var fWidth = disparea.clientWidth * .76;
//		var fHeight = disparea.clientHeight * .79 ;
/*
		var fWidth = window.innerWidth - disparea.offsetLeft  ;
		fWidth -= ( fWidth * .1 ) ;
		var fHeight = window.innerHeight - disparea.offsetTop ;
		fHeight -= ( fHeight * .1 ) ;
*/
		var fWidth = GetImgWidth( disparea ) ;
		var fHeight = GetImgHeight( disparea ) ;

//alert( "GetPic; innerHeight: " + window.innerHeight + "; innerWidth: " + window.innerWidth ) ;
//alert( "GetPic; disparea.offsetLeft: " + disparea.offsetLeft + "; disparea.offsetTop: " + disparea.offsetTop ) ;
//alert( "GetPic: fWidth: " + fWidth + "; fHeight: " + fHeight ) ;

		var imgElmt = document.getElementById( iImgId ) ;
		var sImgLoc = imgElmt.getAttribute( "value" ) ;

		sSendArg = 'imgloc=' + sImgLoc ;
//		sSendArg += '&imgid=' + iImgId + '&width=' + fWidth + '&height=' + fHeight ;
		sSendArg += '&imgid=' + iImgId + '&width=' + fWidth + '&height=' + fHeight ;

		SetTitle( "<SPAN class='msg'> Retrieving image </span>" ) ;

		// enable passing of parameters
        httpRequest.onreadystatechange = function() { DispPic( httpRequest ); };

        httpRequest.open('POST', sPicApp, true);
		httpRequest.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
		httpRequest.setRequestHeader("Content-length",sSendArg.length);
		httpRequest.setRequestHeader("Connection","close");
        httpRequest.send( sSendArg );

	}


//*-----------------------------------------------------------------------------------------
// build the HTML to add the "previous" and "next" cmds to the menu element.
// the incoming arguments are used to set the arguments to the calls to "GetPic"

	function SetMenuCmds( iPrev, iNext )
	{
		var sTmpMenu  = "| <A class=topmenu HREF=\"javascript:GetPic('" + iPrev + "', 'imgdisparea' )\" " ;
		sTmpMenu += "onmouseover=\"window.status='previous image'; return true\"  " ;
		sTmpMenu += "onmouseout=\"window.status=''\"> " ;
		sTmpMenu += "Prev </a> \n" ;

		sTmpMenu += "| <A class=topmenu HREF=\"javascript:GetPic('" + iNext + "', 'imgdisparea' )\" " ;
		sTmpMenu += "onmouseover=\"window.status='next image'; return true\"  " ;
		sTmpMenu += "onmouseout=\"window.status=''\"> " ;
		sTmpMenu += "Next </a> \n" ;
		sTmpMenu += "| \n" ;

		var picMenu = document.getElementById( 'picmenu' ) ;
		picMenu.innerHTML = sTmpMenu ;
	}

//*-----------------------------------------------------------------------------------------
// trim leading & trailing blanks
// return: the trimmed string

	function trim( sText )
	{
		return sText.replace(/^\s+|\s+$/g, '') ;
	}

//*-----------------------------------------------------------------------------------------
// call-back function which displays the requested img

	function DispPic( httpRequest )
	{
//alert( "in DispPic; ") ;
		if ( httpRequest.readyState != 4 )  //not complete
		{
			return ;
		}

		if ( httpRequest.status != 200 ) // ok
		{
			alert( "DispPic; unable to obtain img from server" ) ;
			return ;
		}

		// get and extract XML data returned by server
		var sXML = httpRequest.responseXML ;
		var iImgId = parseInt( trim( sXML.getElementsByTagName( 'IMGID' )[ 0 ].firstChild.data ) ) ;
		fImgWidth = parseFloat( trim( sXML.getElementsByTagName( 'WIDTH' )[ 0 ].firstChild.data ) ) ;
		fAdjustedImgWidth = parseFloat( trim( sXML.getElementsByTagName( 'ADJWIDTH' )[ 0 ].firstChild.data ) ) ;
		fImgHeight = parseFloat( trim( sXML.getElementsByTagName( 'HEIGHT' )[ 0 ].firstChild.data ) ) ;
		fAdjustedImgHeight = parseFloat( trim( sXML.getElementsByTagName( 'ADJHEIGHT' )[ 0 ].firstChild.data ) ) ;
		var imgElmt = document.getElementById( iImgId ) ;  // get DOM element containing info
		var sImgLoc = imgElmt.getAttribute( "value" ) ;		// get the image file location (usually on server)

//alert( "DispPic: fAdjustedImgWidth: " + fAdjustedImgWidth + "; fAdjustedImgHeight: " + fAdjustedImgHeight ) ;
		var imgdisparea = document.getElementById( 'imgdisparea' ) ;
		imgdisparea.innerHTML = sImgBlock ;
		var dispImg = document.getElementById( 'dispimg' ) ;
		dispImg.setAttribute( "src", sImgLoc ) ;
		dispImg.setAttribute( "width", fAdjustedImgWidth  ) ;
		dispImg.setAttribute( "height", fAdjustedImgHeight ) ;
		dispImg.setAttribute( "value", iImgId  ) ;
//		dispImg.setAttribute( "style", "visibility: visible" ) ;


		SetMenuCmds( iImgId - 1, iImgId + 1 ) ;

		AdjustImgDisp( iImgId, true ) ;

	}

//*-----------------------------------------------------------------------------------------
// Display the gallery window/tab with the initial image requested

	function DispGallery( sImgFilter, iImgId, sTopicDesc, sDispAreaId )
	{
		var disparea = document.getElementById( sDispAreaId ) ;
//		var fWidth = disparea.clientWidth * .76;
//		var fHeight = disparea.clientHeight * .79 ;
		var fWidth = GetImgWidth( disparea ) ;
		var fHeight = GetImgHeight( disparea ) ;


//alert( "DispGallery; disparea.offsetLeft: " + disparea.offsetLeft + "; disparea.offsetTop: " + disparea.offsetTop ) ;
//alert( "DispGallery: fWidth: " + fWidth + "; fHeight: " + fHeight ) ;

		document.theForm.browser.value = navigator.appName ;
		document.theForm.filter.value = sImgFilter ;
		document.theForm.topic.value = sTopicDesc ;
		document.theForm.imgid.value = iImgId ;
		document.theForm.width.value = fWidth ;
		document.theForm.height.value = fHeight ;
		document.theForm.target = 'photowndo' ;
		document.theForm.action = sVuApp ; //sDomain + "AMDevDispPic.php" ;
		document.theForm.submit() ;
	}

//*-----------------------------------------------------------------------------------------
// toggle the borders around the icons corresponding to the current image and previous image
// current image has red borders
// the icon image id uses the id of the anchor element with the prefix "thumb"

	function SetBorders( currIconId, sColor )
	{
		// get the leftbar thumbnail
		var imgElmt = document.getElementById( "thumb" + currIconId ) ;
		if ( imgElmt != null )
		{
			imgElmt.style.borderColor = sColor ;
		}

	}

//-----------------------------------------------------------------------------------------
// return either the image title or its file name
// title is stored in the attribute "Title"
// file name is stored in attribute "Value"

	function GetTitle( imgElmt )
	{
		var sTitle = imgElmt.getAttribute( "Title" ) ;
		if ( sTitle == "" )		// no title, use the file name
		{
			sTitle = imgElmt.getAttribute( "value" ) ;
			var i = sTitle.lastIndexOf( "." ) ;		// start of the file extension
			if ( i < 0 )  // no extension
			{
				i = sTitle.length ;
			}

			// strip off the path & extension
			sTitle = sTitle.substring( sTitle.lastIndexOf( "/" ) + 1, i ) ;
		}

		return sTitle ;
	}

//-----------------------------------------------------------------------------------------
// write the background color for the content display area
// set the width and height attributes of the content display area used to display the image
//   to be slightly larger than the width and height of the image

	function SetImgBkground( fImgHeight, fImgWidth )
	{
		var dispArea = document.getElementById( 'imgdisparea' ) ;

		fDispWidth = fImgWidth + ( fImgWidth * .1 ) ;
		fDispHeight = fImgHeight + ( fImgHeight * .1 ) ;
		dispArea.style.width = fDispWidth ;
		dispArea.style.height = fDispHeight ;
	}

//-----------------------------------------------------------------------------------------
// display the image in its original size
// set the width and height attributes of the the IMG element used to display the image
// rewrite the HTML for the menu element to replace the "original size" cmd with the
//    "size to fit" cmd

	function OriginalImgSize()
	{
		var dispImg = document.getElementById( 'dispimg' ) ;
		dispImg.setAttribute( "width", fImgWidth  ) ;
		dispImg.setAttribute( "height", fImgHeight ) ;
		SetImgBkground( fImgHeight, fImgWidth )

		var picMenu = document.getElementById( 'picmenu' ) ;
		picMenu.innerHTML = sPicMenu + sToFitCmdHTML ;
	}

//-----------------------------------------------------------------------------------------
// display the image sized to fit the display area
// set the width and height attributes of the the IMG element used to display the image
// rewrite the HTML for the menu element to replace the "size to fit" cmd with the
//    "original size" cmd

	function SizeImgToFit()
	{
//alert( "SizeImgToFit; fAdjustedImgWidth: " + fAdjustedImgWidth + "; fAdjustedImgHeight: " + fAdjustedImgHeight ) ;
		var dispImg = document.getElementById( 'dispimg' ) ;
		dispImg.setAttribute( "width", fAdjustedImgWidth  ) ;
		dispImg.setAttribute( "height", fAdjustedImgHeight ) ;
		SetImgBkground( fAdjustedImgHeight, fAdjustedImgWidth )

		var picMenu = document.getElementById( 'picmenu' ) ;
		picMenu.innerHTML = sPicMenu + sOrigCmdHTML ;
	}

//*-----------------------------------------------------------------------------------------
// called onload by DispPic.php
// sets the borders of the leftbar img corresponding to the display image
// writes the title if necessary
// adds the resizing command if necessary
// scroll the left bar to display the selected icon at the top

	function AdjustImgDisp( id, boolAlignTop )
	{
//alert( "AdjustImgDisp; fAdjustedImgWidth: " + fAdjustedImgWidth + "; fImgWidth: " + fImgWidth + "; fAdjustedImgHeight: " + fAdjustedImgHeight + "; fImgHeight: " + fImgHeight ) ;

		var imgElmt = document.getElementById( id ) ;
		SetBorders(  id, "red" ) ;	// highlight left bar img icon

		SetTitle( GetTitle( imgElmt ) ) ;

		if( fAdjustedImgWidth < fImgWidth )
		{
			var picMenu = document.getElementById( 'picmenu' ) ;
			sPicMenu = picMenu.innerHTML ;				// store for future use
			picMenu.innerHTML = sPicMenu + sOrigCmdHTML ;
		}

		SetImgBkground( fAdjustedImgHeight, fAdjustedImgWidth )

		imgElmt.scrollIntoView( boolAlignTop ) ;
//		var picTopBox = document.getElementById( 'pictopbox' ) ;
		var picTopBox = document.getElementById( 'picbody' ) ;
		picTopBox.scrollIntoView( boolAlignTop ) ;
	}

//*-----------------------------------------------------------------------------------------*/

	function SetTitle( sTitle )
	{
		var titleElmt = document.getElementById( 'pictitle' ) ;
		titleElmt.innerHTML = sTitle ;
	}


//*-----------------------------------------------------------------------------------------*/

	function DispMailForm()
	{
		sLoc = sDomain + "AMDispMailForm.php" ;
		mailWndo = window.open( sLoc, 'contactwndo', 'scrollbars=yes,resizable=yes,width=650,height=500' ) ;
	}

//-----------------------------------------------------------------------------------------

	function OpenNew( sLoc )
	{
		window.open( sLoc, '_blank', 'scrollbars=yes,toolbar=yes,resizable=yes,status=yes,width=700,height=450' ) ;
	}

//-----------------------------------------------------------------------------------------

	function SendMail()
	{
		document.emailForm.action = sDomain + "AMemail.php" ;
		document.emailForm.submit() ;
		return true ;
	}

//-----------------------------------------------------------------------------------------

	function CloseMailForm()
	{
		window.close() ;
	}

//-----------------------------------------------------------------------------------------*/
