// Resize the usable object dimesions according to window size.

var maxWidth;
var maxHeight;
var caption;
var captionHeight = 0;
function objectResize (){
	if (!document.getElementsByTagName){
		return;
	}
	objects = document.getElementsByTagName("object")
	if (!objects.length){
		return;
	}
	var object = objects[0];
	caption = document.getElementById("caption");
		
	var captionHeight = caption.clientHeight;
	
	if (maxWidth == undefined){
		//Set initial values
		var b = document.getElementsByTagName("body")[0]
		b.style.margin = "0px"
		b.style.padding = "0px"
		b.style.width = "100%"
		b.style.height = "100%"		
		
		maxWidth = object.width;
		maxHeight = object.height;
	}	
	//alert (window.innerWidth + " " + document.body.offsetWidth)
	if (window.innerWidth){
		//Firefox  etc.	
		object.width = Math.min (maxWidth, window.innerWidth);
		object.height = Math.min (maxHeight, window.innerHeight-captionHeight);
		object.style.top =  String(window.innerHeight/2 - object.height/2-captionHeight/2) + "px";
		var ratio =  maxHeight / object.height;
		caption.style.width = Math.min(window.innerWidth, maxWidth/ratio)  + "px";
		
	} else if (document.body.clientWidth){
		//Windows
		object.width = Math.min (maxWidth, document.body.clientWidth);
		object.height = Math.min (maxHeight, document.body.clientHeight-captionHeight);
		object.style.top =  document.body.clientHeight/2 - object.height/2-captionHeight/2;
		var ratio =  maxHeight / object.height;
		caption.style.width = Math.min(document.body.clientWidth, maxWidth/ratio)  + "px";
	}	
}

var objectResizeTempFunc = window.onload;
window.onload = function(){
	if (typeof (objectResizeTempFunc) == "function"){
		try{
			objectResizeTempFunc();
		} catch(e){}
	}
	objectResize();
}
window.onresize = function(){
	objectResize();
}
	