var imgRatio = 1200/1600;
var imgInverseRatio = 1600/1200;

window.onload = function() {
    setMainImageSize();
}

window.onresize = function() {
    setMainImageSize();
}

IE7_PNG_SUFFIX = "-trans.png";
var type = "";
if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";
if (document.all) type="IE";
if (document.layers) type="NN";
if (!document.all && document.getElementById) type="MO";

var MAX_height = 12000;

function setMainImageSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
		 myWidth = window.innerWidth;
		 myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
	}
	
	var new_image_width = myWidth;
	var new_image_height = new_image_width * imgRatio;
	
	if(new_image_height < myHeight) { 
			new_image_height = myHeight;
			new_image_width = new_image_height * imgInverseRatio;
	}
	
	var mainimage = document.getElementById('mainimage');
	var mainimageContainer = document.getElementById('imagecontainer');
		 
	mainimage.setAttribute("className", "dynamic");
	
	mainimage.style.height = new_image_height + "px";
	mainimage.style.width = new_image_width + "px";
	
	var filename = mainimage.getAttribute("alt") + ".jpg";
	
	if(new_image_width < 1000) {
			var generatedWidth = 1000;
	} else if(new_image_width < 1500) {
			var generatedWidth = 1500;
	} else if(new_image_width < 2000) {
			var generatedWidth = 2000;
	} else {
			var generatedWidth = 771;
	}

	var generatedHeight = generatedWidth * imgRatio;
	
	//alert(generatedWidth + " " + generatedHeight);
	
	mainimage.src = "/beta/assets/img/image.php?crop=1&h="+generatedHeight+"&w=" + generatedWidth + "&i=" + filename;

}
