var image;
var offset = 100;

function highlight(field) {
		field.focus();
		field.select();
}
		
function scaleImage() {
	if (!fitsInWindow())
		if(parseInt(image.style.width) != imageWidth)
			showActualImage();
		else
			showCuttedImage();
	else
		image.style.cursor = "default";
}

function resizeImage() {
	if (!fitsInWindow())
		showCuttedImage();
	else{
		showActualImage();	
		image.style.cursor = "default";
	}
}

function showActualImage(){
	image.style.width = imageWidth;
	image.style.height = imageHeight;
	showMessage(false);	
}

function showCuttedImage(){
	image.style.width = getAvailableWidth();
	image.style.height = (imageHeight/imageWidth) * parseInt(image.style.width);
	image.style.cursor = "pointer";	
	showMessage(true);	
}

function fitsInWindow() {
	return (imageWidth < getAvailableWidth());
}

function getAvailableWidth() {	
	var width = (navigator.appName=="Netscape")?
		window.innerWidth:
		document.body.offsetWidth;
	return width - offset;
}

function showMessage(t) {
	getEl('message').style.display = (t)? "block": "none";
}

function getEl(id){
	return document.getElementById(id);
}

window.onresize = resizeImage;

