//source: Michael Imstepf
//date: 06/01/2008
//purpose: scale images according to avaiable screen space
//dependencies: style.css, imageDataLookup.js, photoSwitcher.js


//document.getElementById("content").style.overflow = "hidden";

function optimisePhotoSize(fileName,placeholderImage,homeHeight,homeWidth,placeholderContent,setScrollbar){

//imageDataLookup function not necessary on page "home" as there is only one image displayed
if (homeHeight) {
//alert("homeHeight");
var imageHeight = homeHeight;
var imageWidth = homeWidth;


//not for setting height of #content
} else if (!placeholderContent) { 
//alert("placeholderContent");
//alert(fileName);
var imageHeight = imageDataLookup(fileName,"Height");
var imageWidth = imageDataLookup(fileName,"Width");
//alert(imageHeight);
//alert(imageWidth);
}

//get information
//var navigationHeight = document.getElementById('navigationOuterWrapper').offsetHeight;

var viewportHeight = $(window).height();
//alert(viewportHeight);
//var viewportHeight = DHTMLAPI.getInsideWindowHeight( );
var viewportWidth = $(window).width();
//alert(viewportWidth);
//var viewportWidth = DHTMLAPI.getInsideWindowWidth( );
	
var contentHeight = viewportHeight * 0.65; /* before update Sept 2010: 0.6 */

//set equal height for all pages
document.getElementById("content").style.height = (contentHeight - 1) + 'px';



//set height of #content for  and exit script
if (placeholderContent) {
//document.getElementById("content").style.height = contentHeight + 'px';

} else {

var contentWidth = viewportWidth * 0.8; /* before update Sept 2010: 0.7 */

var imageRatio = imageWidth / imageHeight;
					
//var navigationPrimaryWidth = document.getElementById('navigationPrimary').offsetWidth;

// correct contentWidth to prevent horizontal overflow in Safari (every browser tends to calculate imageHeight below slightly proportionally different
if ($.browser.safari) {
var contentWidth = contentWidth - 7;
}
if ($.browser.mozilla) {
var contentWidth = contentWidth + 1;
}
if ($.browser.msie) {
var contentWidth = contentWidth + 1;
}

//alert('content' + contentHeight);
//alert('height' + imageHeight);


//calculate ideal height
while ( ((imageHeight > 50) && (imageHeight >= contentHeight)) || ((imageHeight > 50) && ((imageHeight * imageRatio) >= contentWidth)))
{imageHeight--;}


//set height of image
document.images[placeholderImage].style.height = imageHeight + 'px';
//document.getElementById('photo').style.height = '300px';

//images in Firefox are displayed before size is calculated, therefore element must be hidden at first

//set in photoSwitcher.js at the end of the script but this script is not used in page "home" 
if(homeHeight) { document.getElementById(placeholderImage).style.display = "block"; }

if(!homeHeight) {

//only set arrows in #thumbnail if thumbnails overlap available space within #thumbnails
//var thumbnailsInnerWrapper0Width = document.getElementById('thumbnailsInnerWrapper0').offsetWidth;
//#thumbnails minus padding of arrows
//var thumbnailsWidth = document.getElementById('thumbnails').offsetWidth * 0.9;

//if(thumbnailsInnerWrapper0Width > thumbnailsWidth) {
//document.getElementById('lineup0').style.visibility = "visible";
//document.getElementById('linedown0').style.visibility = "visible";
//}		

//set size of photo navigation using the same total width as #thumbnails calculated above
//document.getElementById("swapImage").style.width = (imageHeight * imageRatio) + (0.3 * navigationPrimaryWidth) + 'px';
document.getElementById("swapImage").style.height = contentHeight + 'px';
document.getElementById("swapImage").style.marginTop = -imageHeight + 'px'; /* for vertical alignment independent of image height */
document.getElementById("previousImage").style.height = contentHeight + 'px';
document.getElementById("nextImage").style.height = contentHeight + 'px';
//document.getElementById("previousImageArrow").style.marginLeft = (contentWidth - (imageHeight * imageRatio)) / 2 - 20 + 'px';
//document.getElementById("nextImageArrow").style.marginRight = (contentWidth - (imageHeight * imageRatio)) / 2 - 20 + 'px';

}


//images in Firefox are displayed before size is calculated, therefore element must be hidden at first
//document.getElementById("swapImage").style.display = "block";
}

// set scrollbar in script (overrides hideBodyIfJSEnabled.css) to make it appear after contentHeight ist calculated
if (setScrollbar)
{ document.getElementById("content").style.overflow = "auto"; }


}
