function scaleImage(pagetype) {

	//alert ("test");

	// determine browser height and width
	//var varBrowserWidth = 0;
	//var varBrowserHeight = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {	
		//Non-IE 		
		varBrowserWidth = window.innerWidth;
		varBrowserHeight = window.innerHeight; 
	
	} else if( document.documentElement &&	
	( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
		//IE 6+ in 'standards compliant mode' 
		varBrowserWidth = document.documentElement.clientWidth; 
		varBrowserHeight = document.documentElement.clientHeight; 
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
		//IE 4 compatible 
		varBrowserWidth = document.body.clientWidth; 
		varBrowserHeight = document.body.clientHeight; 
	} 

	// determine variables for loaded image
	//alert (document.getElementById('largeImage').width);
    var varImageWidth = document.getElementById('largeImage').width;
	var varImageHeight = document.getElementById('largeImage').height;
	
	//alert (varImageWidth + " - " + varImageHeight);
	/*if (varImageWidth == 0) {
		varImageWidth = 1200;
		varImageHeight = 800	
	}*/
	
	// check if image shoule be scaled in width or height
	varScalingPercentageWidth = (Math.round( (varBrowserWidth/varImageWidth) * 100 ))/100;
	varScaledHeight = varImageHeight * varScalingPercentageWidth;
	
	if (varScaledHeight < varBrowserHeight)  {
		
		// use fixed sizes for iphone and ipad
		if (/iPhone/.test(navigator.userAgent) || /iPod/.test(navigator.userAgent)) {
			/*if (window.innerWidth > window.innerHeight) {
				var varNewImagewidth = 550;
			} else {*/
				var varNewImagewidth = 800;	
			//}
		} else if (/iPad/.test(navigator.userAgent)) {
			var varNewImagewidth = 700;
		} else {
			var varNewImagewidth = (varBrowserWidth - 277);	
		}
		
		
		
		document.getElementById('largeImage').style.width = varNewImagewidth + "px";
		
		//alert (varNewImagewidth);
		//alert(document.getElementById('largeImage').style.width + " - " + window.innerWidth);
		
		var varNewImageHeight = Math.round((varNewImagewidth/varImageWidth) * varImageHeight);
		document.getElementById('largeImage').style.height = varNewImageHeight + "px";
		
		//alert ("test1: " + document.getElementById('largeImage').style.width);
		
		if (pagetype == "portfolio") {
			// position info
			document.getElementById('info_pic').style.width = (varBrowserWidth - 277 - 40) + "px";
			document.getElementById('info_pic').style.bottom = (varBrowserHeight - varNewImageHeight ) + "px";
			
			// position thumbs
			document.getElementById('thumb_holder').style.bottom = "53px"; //varBrowserHeight - Math.ceil( ((((varBrowserWidth - 275)/3 ) * 2) + 10) ) + "px";
			document.getElementById('nextprev').style.bottom = "26px"; //(varBrowserHeight - Math.ceil( ((((varBrowserWidth - 275)/3 ) * 2) + 10) )  - 10) + "px";
		}
		
		
	} else {
		
		// use fixed sizes for iphone
		if (/iPhone/.test(navigator.userAgent) || /iPod/.test(navigator.userAgent)) {
			//if (window.innerWidth > window.innerHeight) {
				if (varImageWidth > varImageHeight) {
					var varNewImagewidth = 550;
				} else {
					document.getElementById('largeImage').style.height = (varBrowserHeight - 65) + "px";
					document.getElementById('largeImage').style.width = Math.round((document.getElementById('largeImage').height/varImageHeight) * varImageWidth) + "px";
				}
			//} 
			document.getElementById('largeImage').style.width = varNewImagewidth + "px";
			var varNewImageHeight = Math.round((varNewImagewidth/varImageWidth) * varImageHeight);
			document.getElementById('largeImage').style.height = varNewImageHeight + "px";
			
		} else {
		
			document.getElementById('largeImage').style.height = (varBrowserHeight - 65) + "px";
			document.getElementById('largeImage').style.width = Math.round(((varBrowserHeight - 65)/varImageHeight) * varImageWidth) + "px";
			//alert ("test2: " + varImageWidth + " - " + varImageHeight);
			
		}
		
		//alert (varNewImagewidth);
		
		if (pagetype == "portfolio") {
			// position info
			document.getElementById('info_pic').style.width = (Math.round((document.getElementById('largeImage').height/varImageHeight) * varImageWidth) - 40) + "px";
			document.getElementById('info_pic').style.bottom = "65px";
			
			// position thumbs
			document.getElementById('thumb_holder').style.bottom = "53px";
			document.getElementById('nextprev').style.bottom = "26px";
		}
		
		
		// check if width is larger than width allowed => rescale
		if ( Math.round((document.getElementById('largeImage').height/varImageHeight) * varImageWidth) > (varBrowserWidth - 277) ) {
			// same code as above
			var varNewImagewidth = (varBrowserWidth - 277);
			document.getElementById('largeImage').style.width = varNewImagewidth + "px";
		
			var varNewImageHeight = Math.round((varNewImagewidth/varImageWidth) * varImageHeight);
			document.getElementById('largeImage').style.height = varNewImageHeight + "px";
			
			//alert ("test3: " + varImageWidth);
			
			if (pagetype == "portfolio") {
				// position info
				document.getElementById('info_pic').style.width = (varBrowserWidth - 277 - 40) + "px";
				document.getElementById('info_pic').style.bottom = (varBrowserHeight - varNewImageHeight ) + "px";

				// position thumbs
				document.getElementById('thumb_holder').style.bottom = "53px";
				document.getElementById('nextprev').style.bottom = "26px";
			}
		}
		
	}
	
		
	// final things in script
	if (pagetype == "portfolio") {
	
		// check if image is real wide (on widescreen), in that case thumbnails will go to low, so determine minimum size
		if ( (varBrowserHeight - Math.ceil( ((((varBrowserWidth - 275)/3 ) * 2) + 10) )) < 53) {
			document.getElementById('thumb_holder').style.bottom = "53px";
			document.getElementById('nextprev').style.bottom = "26px";
		}
		// show thumbs and navigation
		if (/iPhone/.test(navigator.userAgent) || /iPod/.test(navigator.userAgent)) {
			document.getElementById('thumb_holder').style.visibility = "hidden";
			document.getElementById('nextprev').style.visibility = "hidden";
		} else {
			document.getElementById('thumb_holder').style.visibility = "visible";
			document.getElementById('nextprev').style.visibility = "visible";
		}
	}
	
	
	if (pagetype == "contact") {
		//alert (varBrowserWidth - (Math.round(((varBrowserHeight - 65)/varImageHeight) * varImageWidth)) - 285);
		var contentWidth = varBrowserWidth - (Math.round(((varBrowserHeight - 65)/varImageHeight) * varImageWidth)) - 285;
		if (contentWidth > 500) {
			contentWidth = 500;	
		}
		
		document.getElementById('content_holder').style.width = contentWidth + "px";
		document.getElementById('content_holder').style.visibility = "visible";
	}
	// hide loading 
	document.getElementById('loading').style.visibility = "hidden";
	
	// show image
	document.getElementById('image_holder').style.visibility = "visible";

}

// load large visual by pressing thumbnail
//function loadImage(varImageName,pagetype,prevUrl) {
	//var toggle = 0;
	/*document.getElementById('image_holder').style.visibility = "hidden";*/
	/*if (pagetype == "portfolio") {
		document.getElementById('image_holder').innerHTML = "<a href=\"" + prevUrl + "\"><img src=\"" + varImageName + "\" id=\"largeImage\" /></a>";
	} else {
		document.getElementById('image_holder').innerHTML = "<img src=\"" + varImageName + "\" id=\"largeImage\" />";
	}*/
	
	// set interval to see if image is loaded by checking the width (if not loaded it's 0)
	/*var checkImageLoaded = setInterval(function() {
		 var imageWidth = document.getElementById('largeImage').width;
		 if(imageWidth != 0) {
			clearInterval(checkImageLoaded);
			scaleImage(pagetype);
		 }
	}, 100);*/
	//$('img').load(function() {
	/*$('#largeImage').load(function() {
		//if (toggle == 0) {
			//alert ("image loaded" + toggle);

			scaleImage(pagetype);
			//toggle = 1;
		//}
	});*/
//}

/*$(window).resize(function() {
	scaleImage();
});*/

